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

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

Issue 2460973002: gpu, cmaa: reuse CopyTextureCHROMIUMResourceManager (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_apply_framebuffer_attachment_cmaa _intel.h" 5 #include "gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa _intel.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "gpu/command_buffer/service/framebuffer_manager.h" 8 #include "gpu/command_buffer/service/framebuffer_manager.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
10 #include "ui/gl/gl_context.h" 10 #include "ui/gl/gl_context.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 glGetUniformLocation(edges0_shader_, "g_resultRGBATextureSlot1"); 178 glGetUniformLocation(edges0_shader_, "g_resultRGBATextureSlot1");
179 edges0_shader_target_texture_slot2_ = 179 edges0_shader_target_texture_slot2_ =
180 glGetUniformLocation(edges0_shader_, "g_targetTextureSlot2"); 180 glGetUniformLocation(edges0_shader_, "g_targetTextureSlot2");
181 edges1_shader_result_edge_texture_ = 181 edges1_shader_result_edge_texture_ =
182 glGetUniformLocation(edges1_shader_, "g_resultEdgeTexture"); 182 glGetUniformLocation(edges1_shader_, "g_resultEdgeTexture");
183 edges_combine_shader_result_edge_texture_ = 183 edges_combine_shader_result_edge_texture_ =
184 glGetUniformLocation(edges_combine_shader_, "g_resultEdgeTexture"); 184 glGetUniformLocation(edges_combine_shader_, "g_resultEdgeTexture");
185 process_and_apply_shader_result_rgba_texture_slot1_ = glGetUniformLocation( 185 process_and_apply_shader_result_rgba_texture_slot1_ = glGetUniformLocation(
186 process_and_apply_shader_, "g_resultRGBATextureSlot1"); 186 process_and_apply_shader_, "g_resultRGBATextureSlot1");
187 187
188 copy_to_framebuffer_shader_ = CreateProgram("", vert_str_, copy_frag_str_);
189
188 initialized_ = true; 190 initialized_ = true;
189 } 191 }
190 192
191 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() { 193 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() {
192 if (!initialized_) 194 if (!initialized_)
193 return; 195 return;
194 196
195 ReleaseTextures(); 197 ReleaseTextures();
196 198
199 glDeleteProgram(copy_to_framebuffer_shader_);
197 glDeleteProgram(process_and_apply_shader_); 200 glDeleteProgram(process_and_apply_shader_);
198 glDeleteProgram(edges_combine_shader_); 201 glDeleteProgram(edges_combine_shader_);
199 glDeleteProgram(edges1_shader_); 202 glDeleteProgram(edges1_shader_);
200 glDeleteProgram(edges0_shader_); 203 glDeleteProgram(edges0_shader_);
201 glDeleteProgram(debug_display_edges_shader_); 204 glDeleteProgram(debug_display_edges_shader_);
202 205
203 initialized_ = false; 206 initialized_ = false;
204 } 207 }
205 208
206 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the 209 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Resize internal structures - only if needed. 241 // Resize internal structures - only if needed.
239 OnSize(width, height); 242 OnSize(width, height);
240 243
241 // CMAA internally expects GL_RGBA8 textures. 244 // CMAA internally expects GL_RGBA8 textures.
242 // Process using a GL_RGBA8 copy if this is not the case. 245 // Process using a GL_RGBA8 copy if this is not the case.
243 bool do_copy = internal_format != GL_RGBA8; 246 bool do_copy = internal_format != GL_RGBA8;
244 247
245 // CMAA Effect 248 // CMAA Effect
246 if (do_copy) { 249 if (do_copy) {
247 ApplyCMAAEffectTexture(source_texture, rgba8_texture_, do_copy); 250 ApplyCMAAEffectTexture(source_texture, rgba8_texture_, do_copy);
251 CopyTexture(rgba8_texture_, source_texture);
248 } else { 252 } else {
249 ApplyCMAAEffectTexture(source_texture, source_texture, do_copy); 253 ApplyCMAAEffectTexture(source_texture, source_texture, do_copy);
250 } 254 }
251 255
252 // Copy rgba8_texture_ to source_texture
253 if (do_copy) {
254 // copy_framebuffer_ always binds rgba8_texture_
255 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
256 CopyTexture(source_texture);
257 }
258 decoder->RestoreTextureState(source_texture); 256 decoder->RestoreTextureState(source_texture);
259 } 257 }
260 } 258 }
261 259
262 // Restore state 260 // Restore state
263 decoder->RestoreAllAttributes(); 261 decoder->RestoreAllAttributes();
264 decoder->RestoreTextureUnitBindings(0); 262 decoder->RestoreTextureUnitBindings(0);
265 decoder->RestoreTextureUnitBindings(1); 263 decoder->RestoreTextureUnitBindings(1);
266 decoder->RestoreActiveTexture(); 264 decoder->RestoreActiveTexture();
267 decoder->RestoreProgramBindings(); 265 decoder->RestoreProgramBindings();
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 glDeleteTextures(1, &rgba8_texture_); 541 glDeleteTextures(1, &rgba8_texture_);
544 glDeleteTextures(1, &edges0_texture_); 542 glDeleteTextures(1, &edges0_texture_);
545 glDeleteTextures(1, &edges1_texture_); 543 glDeleteTextures(1, &edges1_texture_);
546 glDeleteTextures(1, &mini4_edge_texture_); 544 glDeleteTextures(1, &mini4_edge_texture_);
547 glDeleteTextures(1, &mini4_edge_depth_texture_); 545 glDeleteTextures(1, &mini4_edge_depth_texture_);
548 glDeleteTextures(1, &working_color_texture_); 546 glDeleteTextures(1, &working_color_texture_);
549 } 547 }
550 textures_initialized_ = false; 548 textures_initialized_ = false;
551 } 549 }
552 550
553 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture( 551 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture(
piman 2016/10/28 21:51:12 We already have a facility to copy a texture using
552 GLint source,
554 GLint dest) { 553 GLint dest) {
555 glActiveTexture(GL_TEXTURE0); 554 // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver,
556 glBindTexture(GL_TEXTURE_2D, dest); 555 // although opposite in Android. Currently, only IA ChromeOS uses this code.
557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 556 const bool draw = true;
dshwang 2016/10/28 18:13:24 Mesa may will fix it or future Intel Chromebook ma
558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 557 if (draw) {
559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 558 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 559 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
560 GL_TEXTURE_2D, dest, 0);
561 glViewport(0, 0, width_, height_);
561 562
562 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width_, height_); 563 glActiveTexture(GL_TEXTURE0);
564 glBindTexture(GL_TEXTURE_2D, source);
565 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
568 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
569
570 glDisable(GL_DEPTH_TEST);
571 glDisable(GL_STENCIL_TEST);
572 glDisable(GL_CULL_FACE);
573 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
574 glDepthMask(GL_FALSE);
575 glDisable(GL_BLEND);
576 glUseProgram(copy_to_framebuffer_shader_);
577
578 glDrawArrays(GL_TRIANGLES, 0, 3);
579 glUseProgram(0);
580 glBindTexture(GL_TEXTURE_2D, 0);
581 } else {
582 // copy_framebuffer_ always binds rgba8_texture_
583 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_);
584 glActiveTexture(GL_TEXTURE0);
585 glBindTexture(GL_TEXTURE_2D, dest);
586 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width_, height_);
587 }
563 } 588 }
564 589
565 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram( 590 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram(
566 const char* defines, 591 const char* defines,
567 const char* vs_source, 592 const char* vs_source,
568 const char* fs_source) { 593 const char* fs_source) {
569 GLuint program = glCreateProgram(); 594 GLuint program = glCreateProgram();
570 595
571 GLuint vs = CreateShader(GL_VERTEX_SHADER, defines, vs_source); 596 GLuint vs = CreateShader(GL_VERTEX_SHADER, defines, vs_source);
572 GLuint fs = CreateShader(GL_FRAGMENT_SHADER, defines, fs_source); 597 GLuint fs = CreateShader(GL_FRAGMENT_SHADER, defines, fs_source);
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 CombineEdges(); 1879 CombineEdges();
1855 \n#endif\n 1880 \n#endif\n
1856 \n#if defined BLUR_EDGES\n 1881 \n#if defined BLUR_EDGES\n
1857 BlurEdges(); 1882 BlurEdges();
1858 \n#endif\n 1883 \n#endif\n
1859 \n#if defined DISPLAY_EDGES\n 1884 \n#if defined DISPLAY_EDGES\n
1860 DisplayEdges(); 1885 DisplayEdges();
1861 \n#endif\n 1886 \n#endif\n
1862 } 1887 }
1863 ); 1888 );
1889
1890 const char
1891 ApplyFramebufferAttachmentCMAAINTELResourceManager::copy_frag_str_[] =
1892 SHADER(
1893 precision highp float;
1894 layout(binding = 0) uniform highp sampler2D inTexture;
1895 layout(location = 0) out vec4 outColor;
1896 void main() {
1897 ivec2 screenPosI = ivec2( gl_FragCoord.xy );
1898 vec4 pixel = texelFetch(inTexture, screenPosI, 0);
1899 outColor = pixel;
1900 }
1901 );
1864 /* clang-format on */ 1902 /* clang-format on */
1865 1903
1866 } // namespace gles2 1904 } // namespace gles2
1867 } // namespace gpu 1905 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa_intel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698