Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc

Issue 10535174: Addition of unpremultiply setting to GL_CHROMIUM_copy_texture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressing review comments. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "gpu/command_buffer/common/types.h" 8 #include "gpu/command_buffer/common/types.h"
9 #include "gpu/command_buffer/service/gl_utils.h" 9 #include "gpu/command_buffer/service/gl_utils.h"
10 10
11 #define SHADER0(Src) \ 11 #define SHADER0(Src) \
12 "#ifdef GL_ES\n"\ 12 "#ifdef GL_ES\n"\
13 "precision mediump float;\n"\ 13 "precision mediump float;\n"\
14 "#endif\n"\ 14 "#endif\n"\
15 #Src 15 #Src
16 #define SHADER(Src) SHADER0(Src) 16 #define SHADER(Src) SHADER0(Src)
17 17
18 namespace { 18 namespace {
19 19
20 const GLfloat kQuadVertices[] = { -1.0f, -1.0f, 0.0f, 1.0f, 20 const GLfloat kQuadVertices[] = { -1.0f, -1.0f, 0.0f, 1.0f,
21 1.0f, -1.0f, 0.0f, 1.0f, 21 1.0f, -1.0f, 0.0f, 1.0f,
22 1.0f, 1.0f, 0.0f, 1.0f, 22 1.0f, 1.0f, 0.0f, 1.0f,
23 -1.0f, 1.0f, 0.0f, 1.0f }; 23 -1.0f, 1.0f, 0.0f, 1.0f };
24 24
25 const GLfloat kTextureCoords[] = { 0.0f, 0.0f, 25 const GLfloat kTextureCoords[] = { 0.0f, 0.0f,
26 1.0f, 0.0f, 26 1.0f, 0.0f,
27 1.0f, 1.0f, 27 1.0f, 1.0f,
28 0.0f, 1.0f }; 28 0.0f, 1.0f };
29 29
30 const int kNumShaders = 5; 30 const int kNumShaders = 7;
31 enum ShaderId { 31 enum ShaderId {
32 VERTEX_SHADER_POS_TEX, 32 VERTEX_SHADER_POS_TEX,
33 FRAGMENT_SHADER_TEX, 33 FRAGMENT_SHADER_TEX,
34 FRAGMENT_SHADER_TEX_FLIP_Y, 34 FRAGMENT_SHADER_TEX_FLIP_Y,
35 FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA, 35 FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA,
36 FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA_FLIP_Y 36 FRAGMENT_SHADER_TEX_UNPREMULTIPLY_ALPHA,
37 FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA_FLIP_Y,
38 FRAGMENT_SHADER_TEX_UNPREMULTIPLY_ALPHA_FLIP_Y
37 }; 39 };
38 40
39 enum ProgramId { 41 enum ProgramId {
40 PROGRAM_COPY_TEXTURE, 42 PROGRAM_COPY_TEXTURE,
41 PROGRAM_COPY_TEXTURE_FLIP_Y, 43 PROGRAM_COPY_TEXTURE_FLIP_Y,
42 PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA, 44 PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA,
43 PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA_FLIPY 45 PROGRAM_COPY_TEXTURE_UNPREMULTIPLY_ALPHA,
46 PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA_FLIPY,
47 PROGRAM_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_FLIPY
44 }; 48 };
45 49
46 // Returns the correct program to evaluate the copy operation for 50 // Returns the correct program to evaluate the copy operation for
47 // the CHROMIUM_flipy and premultiply alpha pixel store settings. 51 // the CHROMIUM_flipy and premultiply alpha pixel store settings.
48 ProgramId GetProgram(bool flip_y, bool premultiply_alpha) { 52 ProgramId GetProgram(bool flip_y, bool premultiply_alpha,
53 bool unpremultiply_alpha) {
54 // If both pre-multiply and unpremultiply are requested, then perform no
55 // alpha manipulation.
56 if (premultiply_alpha && unpremultiply_alpha) {
57 premultiply_alpha = false;
58 unpremultiply_alpha = false;
59 }
60
49 if (flip_y && premultiply_alpha) 61 if (flip_y && premultiply_alpha)
50 return PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA_FLIPY; 62 return PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA_FLIPY;
51 63
64 if (flip_y && unpremultiply_alpha)
65 return PROGRAM_COPY_TEXTURE_UNPREMULTIPLY_ALPHA_FLIPY;
66
52 if (flip_y) 67 if (flip_y)
53 return PROGRAM_COPY_TEXTURE_FLIP_Y; 68 return PROGRAM_COPY_TEXTURE_FLIP_Y;
54 69
55 if (premultiply_alpha) 70 if (premultiply_alpha)
56 return PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA; 71 return PROGRAM_COPY_TEXTURE_PREMULTIPLY_ALPHA;
57 72
73 if (unpremultiply_alpha)
74 return PROGRAM_COPY_TEXTURE_UNPREMULTIPLY_ALPHA;
75
58 return PROGRAM_COPY_TEXTURE; 76 return PROGRAM_COPY_TEXTURE;
59 } 77 }
60 78
61 const char* GetShaderSource(ShaderId shader) { 79 const char* GetShaderSource(ShaderId shader) {
62 switch (shader) { 80 switch (shader) {
63 case VERTEX_SHADER_POS_TEX: 81 case VERTEX_SHADER_POS_TEX:
64 return SHADER( 82 return SHADER(
65 attribute vec4 a_position; 83 attribute vec4 a_position;
66 attribute vec2 a_texCoord; 84 attribute vec2 a_texCoord;
67 varying vec2 v_uv; 85 varying vec2 v_uv;
(...skipping 16 matching lines...) Expand all
84 gl_FragColor = texture2D(u_texSampler, vec2(v_uv.s, 1.0 - v_uv.t)); 102 gl_FragColor = texture2D(u_texSampler, vec2(v_uv.s, 1.0 - v_uv.t));
85 }); 103 });
86 case FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA: 104 case FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA:
87 return SHADER( 105 return SHADER(
88 uniform sampler2D u_texSampler; 106 uniform sampler2D u_texSampler;
89 varying vec2 v_uv; 107 varying vec2 v_uv;
90 void main(void) { 108 void main(void) {
91 gl_FragColor = texture2D(u_texSampler, v_uv.st); 109 gl_FragColor = texture2D(u_texSampler, v_uv.st);
92 gl_FragColor.rgb *= gl_FragColor.a; 110 gl_FragColor.rgb *= gl_FragColor.a;
93 }); 111 });
112 case FRAGMENT_SHADER_TEX_UNPREMULTIPLY_ALPHA:
113 return SHADER(
114 uniform sampler2D u_texSampler;
115 varying vec2 v_uv;
116 void main(void) {
117 gl_FragColor = texture2D(u_texSampler, v_uv.st);
118 if (gl_FragColor.a > 0.0)
119 gl_FragColor.rgb /= gl_FragColor.a;
120 });
94 case FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA_FLIP_Y: 121 case FRAGMENT_SHADER_TEX_PREMULTIPLY_ALPHA_FLIP_Y:
95 return SHADER( 122 return SHADER(
96 uniform sampler2D u_texSampler; 123 uniform sampler2D u_texSampler;
97 varying vec2 v_uv; 124 varying vec2 v_uv;
98 void main(void) { 125 void main(void) {
99 gl_FragColor = texture2D(u_texSampler, vec2(v_uv.s, 1.0 - v_uv.t)); 126 gl_FragColor = texture2D(u_texSampler, vec2(v_uv.s, 1.0 - v_uv.t));
100 gl_FragColor.rgb *= gl_FragColor.a; 127 gl_FragColor.rgb *= gl_FragColor.a;
101 }); 128 });
129 case FRAGMENT_SHADER_TEX_UNPREMULTIPLY_ALPHA_FLIP_Y:
130 return SHADER(
131 uniform sampler2D u_texSampler;
132 varying vec2 v_uv;
133 void main(void) {
134 gl_FragColor = texture2D(u_texSampler, vec2(v_uv.s, 1.0 - v_uv.t));
135 if (gl_FragColor.a > 0.0)
136 gl_FragColor.rgb /= gl_FragColor.a;
137 });
102 default: 138 default:
103 return 0; 139 return 0;
104 } 140 }
105 } 141 }
106 142
107 } // namespace 143 } // namespace
108 144
109 void CopyTextureCHROMIUMResourceManager::Initialize() { 145 void CopyTextureCHROMIUMResourceManager::Initialize() {
110 COMPILE_ASSERT( 146 COMPILE_ASSERT(
111 kVertexPositionAttrib == 0u || kVertexTextureAttrib == 0u, 147 kVertexPositionAttrib == 0u || kVertexTextureAttrib == 0u,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 213
178 glDeleteBuffersARB(2, buffer_ids_); 214 glDeleteBuffersARB(2, buffer_ids_);
179 } 215 }
180 216
181 void CopyTextureCHROMIUMResourceManager::DoCopyTexture( 217 void CopyTextureCHROMIUMResourceManager::DoCopyTexture(
182 GLenum target, 218 GLenum target,
183 GLuint source_id, 219 GLuint source_id,
184 GLuint dest_id, 220 GLuint dest_id,
185 GLint level, 221 GLint level,
186 bool flip_y, 222 bool flip_y,
187 bool premultiply_alpha) { 223 bool premultiply_alpha,
224 bool unpremultiply_alpha) {
188 if (!initialized_) { 225 if (!initialized_) {
189 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; 226 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager.";
190 return; 227 return;
191 } 228 }
192 229
193 GLuint program = GetProgram(flip_y, premultiply_alpha); 230 GLuint program = GetProgram(flip_y, premultiply_alpha, unpremultiply_alpha);
194 glUseProgram(programs_[program]); 231 glUseProgram(programs_[program]);
195 232
196 #ifndef NDEBUG 233 #ifndef NDEBUG
197 glValidateProgram(programs_[program]); 234 glValidateProgram(programs_[program]);
198 GLint validation_status; 235 GLint validation_status;
199 glGetProgramiv(programs_[program], GL_VALIDATE_STATUS, &validation_status); 236 glGetProgramiv(programs_[program], GL_VALIDATE_STATUS, &validation_status);
200 if (GL_TRUE != validation_status) { 237 if (GL_TRUE != validation_status) {
201 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader."; 238 DLOG(ERROR) << "CopyTextureCHROMIUM: Invalid shader.";
202 return; 239 return;
203 } 240 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 glDisable(GL_SCISSOR_TEST); 276 glDisable(GL_SCISSOR_TEST);
240 glDisable(GL_STENCIL_TEST); 277 glDisable(GL_STENCIL_TEST);
241 glDisable(GL_CULL_FACE); 278 glDisable(GL_CULL_FACE);
242 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 279 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
243 glDepthMask(GL_FALSE); 280 glDepthMask(GL_FALSE);
244 glDisable(GL_BLEND); 281 glDisable(GL_BLEND);
245 282
246 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 283 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
247 } 284 }
248 285
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698