2017-01-10 22:57:08 -05:00
|
|
|
// Copyright 2017 The Servo Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Computes total coverage and writes into the output atlas.
|
|
|
|
//
|
|
|
|
// This proceeds top to bottom for better data locality. For details on the algorithm, see [1].
|
|
|
|
//
|
2017-01-23 18:33:12 -05:00
|
|
|
// [1]: https://medium.com/@raphlinus/inside-the-fastest-font-renderer-in-the-world-75ae5270c445
|
2017-01-10 22:57:08 -05:00
|
|
|
|
2017-01-23 18:33:12 -05:00
|
|
|
const sampler_t SAMPLER = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST;
|
2017-01-10 22:57:08 -05:00
|
|
|
|
2017-02-02 19:40:46 -05:00
|
|
|
__kernel void accum(__write_only image2d_t gImage,
|
2017-01-23 18:33:12 -05:00
|
|
|
__read_only image2d_t gCoverage,
|
2017-01-23 22:39:51 -05:00
|
|
|
uint4 kAtlasRect,
|
2017-01-10 22:57:08 -05:00
|
|
|
uint kAtlasShelfHeight) {
|
2017-01-23 18:33:12 -05:00
|
|
|
// Determine the boundaries of the column we'll be traversing.
|
2017-01-23 22:39:51 -05:00
|
|
|
uint atlasWidth = kAtlasRect.z - kAtlasRect.x;
|
|
|
|
uint column = get_global_id(0) % atlasWidth, shelfIndex = get_global_id(0) / atlasWidth;
|
2017-01-23 18:33:12 -05:00
|
|
|
uint firstRow = shelfIndex * kAtlasShelfHeight, lastRow = (shelfIndex + 1) * kAtlasShelfHeight;
|
2017-01-10 22:57:08 -05:00
|
|
|
|
|
|
|
// Sweep down the column, accumulating coverage as we go.
|
2017-01-23 18:33:12 -05:00
|
|
|
float coverage = 0.0f;
|
|
|
|
for (uint row = firstRow; row < lastRow; row++) {
|
|
|
|
int2 coord = (int2)((int)column, (int)row);
|
|
|
|
coverage += read_imagef(gCoverage, SAMPLER, coord).r;
|
2017-01-10 22:57:08 -05:00
|
|
|
|
2017-02-06 18:28:23 -05:00
|
|
|
uint gray = convert_uint(clamp(fabs(coverage), 0.0f, 1.0f) * 255.0f);
|
2017-02-02 19:40:46 -05:00
|
|
|
write_imageui(gImage, coord + (int2)kAtlasRect.xy, (uint4)(gray, 255, 255, 255));
|
2017-01-10 22:57:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|