diff options
author | Eric Anholt <eric@anholt.net> | 2016-02-01 13:58:14 -0800 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2016-03-10 11:12:43 -0500 |
commit | 0b4c0c75d06f3dbe92be1a26a637e9f05529cb3d (patch) | |
tree | 64df0f3068a30650ca3cff0c12509aa40a22bdb1 /glamor/glamor_core.c | |
parent | b0cc04992ced5d96bb5c52fc1e5c868797cc0a17 (diff) |
glamor: Replace "finish access" shader with texture swizzling.
For pictures without alpha, and for most other formats for GLES2, we
would make a temporary FBO, make another temporary texture, upload our
GLAMOR_MEMORY pixmap to the texture, then run the "finish access" shader
across it to swizzle its values around into the temporary FBO (which we
would use for a single Render operation and then throw away).
We can simplify everything by using GL_ARB_texture_swizzle (or its
GLES3 counterpart). It's just not worth the complexity to try to
improve the performance of this already low-performance path (SHM
pixmaps + Render) on GLES2.
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'glamor/glamor_core.c')
-rw-r--r-- | glamor/glamor_core.c | 158 |
1 files changed, 0 insertions, 158 deletions
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c index a8768f4e8..7b2b39633 100644 --- a/glamor/glamor_core.c +++ b/glamor/glamor_core.c @@ -113,164 +113,6 @@ glamor_link_glsl_prog(ScreenPtr screen, GLint prog, const char *format, ...) } } -/* - * When downloading a unsupported color format to CPU memory, - we need to shuffle the color elements and then use a supported - color format to read it back to CPU memory. - - For an example, the picture's format is PICT_b8g8r8a8, - Then the expecting color layout is as below (little endian): - 0 1 2 3 : address - a r g b - - Now the in GLES2 the supported color format is GL_RGBA, type is - GL_UNSIGNED_TYPE, then we need to shuffle the fragment - color as : - frag_color = sample(texture).argb; - before we use glReadPixel to get it back. - - For the uploading process, the shuffle is a revert shuffle. - We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color - to a texture, then let's see - 0 1 2 3 : address - a r g b : correct colors - R G B A : GL_RGBA with GL_UNSIGNED_BYTE - - Now we need to shuffle again, the mapping rule is - r = G, g = B, b = A, a = R. Then the uploading shuffle is as - below: - frag_color = sample(texture).gbar; -*/ - -void -glamor_init_finish_access_shaders(ScreenPtr screen) -{ - glamor_screen_private *glamor_priv; - const char *vs_source = - "attribute vec4 v_position;\n" - "attribute vec4 v_texcoord0;\n" - "varying vec2 source_texture;\n" - "void main()\n" - "{\n" - " gl_Position = v_position;\n" - " source_texture = v_texcoord0.xy;\n" - "}\n"; - - const char *common_source = - GLAMOR_DEFAULT_PRECISION - "varying vec2 source_texture;\n" - "uniform sampler2D sampler;\n" - "uniform int revert;\n" - "uniform int swap_rb;\n" - "#define REVERT_NONE 0\n" - "#define REVERT_NORMAL 1\n" - "#define SWAP_UPLOADING 2\n" - "#define SWAP_NONE_UPLOADING 3\n"; - - const char *fs_source = - "void main()\n" - "{\n" - " vec4 color = texture2D(sampler, source_texture);\n" - " if (revert == REVERT_NONE) \n" - " { \n" - " if ((swap_rb != SWAP_NONE_UPLOADING)) \n" - " gl_FragColor = color.bgra;\n" - " else \n" - " gl_FragColor = color.rgba;\n" - " } \n" - " else \n" - " { \n" - " if (swap_rb == SWAP_UPLOADING)\n" - " gl_FragColor = color.gbar;\n" - " else if (swap_rb == SWAP_NONE_UPLOADING)\n" - " gl_FragColor = color.abgr;\n" - " } \n" - "}\n"; - - const char *set_alpha_source = - "void main()\n" - "{\n" - " vec4 color = texture2D(sampler, source_texture);\n" - " if (revert == REVERT_NONE) \n" - " { \n" - " if (swap_rb != SWAP_NONE_UPLOADING) \n" - " gl_FragColor = vec4(color.bgr, 1);\n" - " else \n" - " gl_FragColor = vec4(color.rgb, 1);\n" - " } \n" - " else \n" - " { \n" - " if (swap_rb == SWAP_UPLOADING)\n" - " gl_FragColor = vec4(color.gba, 1);\n" - " else if (swap_rb == SWAP_NONE_UPLOADING)\n" - " gl_FragColor = vec4(color.abg, 1);\n" - " } \n" - "}\n"; - GLint fs_prog, vs_prog, avs_prog, set_alpha_prog; - GLint sampler_uniform_location; - char *source; - - glamor_priv = glamor_get_screen_private(screen); - glamor_make_current(glamor_priv); - glamor_priv->finish_access_prog[0] = glCreateProgram(); - glamor_priv->finish_access_prog[1] = glCreateProgram(); - - vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source); - - XNFasprintf(&source, "%s%s", common_source, fs_source); - fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, source); - free(source); - - glAttachShader(glamor_priv->finish_access_prog[0], vs_prog); - glAttachShader(glamor_priv->finish_access_prog[0], fs_prog); - - avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source); - - XNFasprintf(&source, "%s%s", common_source, set_alpha_source); - set_alpha_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, - source); - free(source); - - glAttachShader(glamor_priv->finish_access_prog[1], avs_prog); - glAttachShader(glamor_priv->finish_access_prog[1], set_alpha_prog); - - glBindAttribLocation(glamor_priv->finish_access_prog[0], - GLAMOR_VERTEX_POS, "v_position"); - glBindAttribLocation(glamor_priv->finish_access_prog[0], - GLAMOR_VERTEX_SOURCE, "v_texcoord0"); - glamor_link_glsl_prog(screen, glamor_priv->finish_access_prog[0], - "finish access 0"); - - glBindAttribLocation(glamor_priv->finish_access_prog[1], - GLAMOR_VERTEX_POS, "v_position"); - glBindAttribLocation(glamor_priv->finish_access_prog[1], - GLAMOR_VERTEX_SOURCE, "v_texcoord0"); - glamor_link_glsl_prog(screen, glamor_priv->finish_access_prog[1], - "finish access 1"); - - glamor_priv->finish_access_revert[0] = - glGetUniformLocation(glamor_priv->finish_access_prog[0], "revert"); - - glamor_priv->finish_access_swap_rb[0] = - glGetUniformLocation(glamor_priv->finish_access_prog[0], "swap_rb"); - sampler_uniform_location = - glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler"); - glUseProgram(glamor_priv->finish_access_prog[0]); - glUniform1i(sampler_uniform_location, 0); - glUniform1i(glamor_priv->finish_access_revert[0], 0); - glUniform1i(glamor_priv->finish_access_swap_rb[0], 0); - - glamor_priv->finish_access_revert[1] = - glGetUniformLocation(glamor_priv->finish_access_prog[1], "revert"); - glamor_priv->finish_access_swap_rb[1] = - glGetUniformLocation(glamor_priv->finish_access_prog[1], "swap_rb"); - sampler_uniform_location = - glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler"); - glUseProgram(glamor_priv->finish_access_prog[1]); - glUniform1i(glamor_priv->finish_access_revert[1], 0); - glUniform1i(sampler_uniform_location, 0); - glUniform1i(glamor_priv->finish_access_swap_rb[1], 0); -} static GCOps glamor_gc_ops = { .FillSpans = glamor_fill_spans, |