tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

render_task.glsl (2878B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2  * License, v. 2.0. If a copy of the MPL was not distributed with this
      3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 
      6 #ifdef WR_VERTEX_SHADER
      7 #define VECS_PER_RENDER_TASK        2U
      8 
      9 uniform HIGHP_SAMPLER_FLOAT sampler2D sRenderTasks;
     10 
     11 struct RenderTaskData {
     12     RectWithEndpoint task_rect;
     13     vec4 user_data;
     14 };
     15 
     16 // See RenderTaskData in render_task.rs
     17 RenderTaskData fetch_render_task_data(int index) {
     18     ivec2 uv = get_fetch_uv(index, VECS_PER_RENDER_TASK);
     19 
     20     vec4 texel0 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));
     21     vec4 texel1 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(1, 0));
     22 
     23     RectWithEndpoint task_rect = RectWithEndpoint(
     24         texel0.xy,
     25         texel0.zw
     26     );
     27 
     28     RenderTaskData data = RenderTaskData(
     29         task_rect,
     30         texel1
     31     );
     32 
     33     return data;
     34 }
     35 
     36 RectWithEndpoint fetch_render_task_rect(int index) {
     37     ivec2 uv = get_fetch_uv(index, VECS_PER_RENDER_TASK);
     38 
     39     vec4 texel0 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));
     40     vec4 texel1 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(1, 0));
     41 
     42     RectWithEndpoint task_rect = RectWithEndpoint(
     43         texel0.xy,
     44         texel0.zw
     45     );
     46 
     47     return task_rect;
     48 }
     49 
     50 #define PIC_TYPE_IMAGE          1
     51 #define PIC_TYPE_TEXT_SHADOW    2
     52 
     53 /*
     54  The dynamic picture that this brush exists on. Right now, it
     55  contains minimal information. In the future, it will describe
     56  the transform mode of primitives on this picture, among other things.
     57  */
     58 struct PictureTask {
     59     RectWithEndpoint task_rect;
     60     float device_pixel_scale;
     61     vec2 content_origin;
     62 };
     63 
     64 PictureTask fetch_picture_task(int address) {
     65     RenderTaskData task_data = fetch_render_task_data(address);
     66 
     67     PictureTask task = PictureTask(
     68         task_data.task_rect,
     69         task_data.user_data.x,
     70         task_data.user_data.yz
     71     );
     72 
     73     return task;
     74 }
     75 
     76 #define CLIP_TASK_EMPTY 0x7FFFFFFF
     77 
     78 struct ClipArea {
     79     RectWithEndpoint task_rect;
     80     float device_pixel_scale;
     81     vec2 screen_origin;
     82 };
     83 
     84 ClipArea fetch_clip_area(int index) {
     85     RenderTaskData task_data;
     86     if (index >= CLIP_TASK_EMPTY) {
     87       // We deliberately create a dummy RenderTaskData here then convert to a
     88       // ClipArea after this if-else statement, rather than initialize the
     89       // ClipArea in separate branches, to avoid a miscompile in some Adreno
     90       // drivers. See bug 1884791. Unfortunately the specific details of the bug
     91       // are unknown, so please take extra care not to regress this when
     92       // refactoring.
     93       task_data = RenderTaskData(RectWithEndpoint(vec2(0.0), vec2(0.0)),
     94                                  vec4(0.0));
     95     } else {
     96       task_data = fetch_render_task_data(index);
     97     }
     98 
     99     return ClipArea(task_data.task_rect, task_data.user_data.x,
    100                     task_data.user_data.yz);
    101 }
    102 
    103 #endif //WR_VERTEX_SHADER