OLD | NEW |
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_copy_texture_chromium.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
10 #include "ui/gl/gl_context.h" | 11 #include "ui/gl/gl_context.h" |
11 #include "ui/gl/gl_gl_api_implementation.h" | 12 #include "ui/gl/gl_gl_api_implementation.h" |
12 #include "ui/gl/gl_version_info.h" | 13 #include "ui/gl/gl_version_info.h" |
13 | 14 |
14 #define SHADER(Src) #Src | 15 #define SHADER(Src) #Src |
15 | 16 |
16 namespace gpu { | 17 namespace gpu { |
17 namespace gles2 { | 18 namespace gles2 { |
18 | 19 |
19 ApplyFramebufferAttachmentCMAAINTELResourceManager:: | 20 ApplyFramebufferAttachmentCMAAINTELResourceManager:: |
20 ApplyFramebufferAttachmentCMAAINTELResourceManager() | 21 ApplyFramebufferAttachmentCMAAINTELResourceManager() |
21 : initialized_(false), | 22 : initialized_(false), |
22 textures_initialized_(false), | 23 textures_initialized_(false), |
23 is_in_gamma_correct_mode_(false), | 24 is_in_gamma_correct_mode_(false), |
24 supports_usampler_(true), | 25 supports_usampler_(true), |
25 supports_r8_image_(true), | 26 supports_r8_image_(true), |
26 supports_r8_read_format_(true), | 27 supports_r8_read_format_(true), |
27 is_gles31_compatible_(false), | 28 is_gles31_compatible_(false), |
28 frame_id_(0), | 29 frame_id_(0), |
29 width_(0), | 30 width_(0), |
30 height_(0), | 31 height_(0), |
31 copy_to_framebuffer_shader_(0), | |
32 edges0_shader_(0), | 32 edges0_shader_(0), |
33 edges1_shader_(0), | 33 edges1_shader_(0), |
34 edges_combine_shader_(0), | 34 edges_combine_shader_(0), |
35 process_and_apply_shader_(0), | 35 process_and_apply_shader_(0), |
36 debug_display_edges_shader_(0), | 36 debug_display_edges_shader_(0), |
37 cmaa_framebuffer_(0), | 37 cmaa_framebuffer_(0), |
38 copy_framebuffer_(0), | |
39 rgba8_texture_(0), | 38 rgba8_texture_(0), |
40 working_color_texture_(0), | 39 working_color_texture_(0), |
41 edges0_texture_(0), | 40 edges0_texture_(0), |
42 edges1_texture_(0), | 41 edges1_texture_(0), |
43 mini4_edge_texture_(0), | 42 mini4_edge_texture_(0), |
44 mini4_edge_depth_texture_(0), | 43 mini4_edge_depth_texture_(0), |
45 edges0_shader_result_rgba_texture_slot1_(0), | 44 edges0_shader_result_rgba_texture_slot1_(0), |
46 edges0_shader_target_texture_slot2_(0), | 45 edges0_shader_target_texture_slot2_(0), |
47 edges1_shader_result_edge_texture_(0), | 46 edges1_shader_result_edge_texture_(0), |
48 process_and_apply_shader_result_rgba_texture_slot1_(0), | 47 process_and_apply_shader_result_rgba_texture_slot1_(0), |
49 edges_combine_shader_result_edge_texture_(0) {} | 48 edges_combine_shader_result_edge_texture_(0) {} |
50 | 49 |
51 ApplyFramebufferAttachmentCMAAINTELResourceManager:: | 50 ApplyFramebufferAttachmentCMAAINTELResourceManager:: |
52 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { | 51 ~ApplyFramebufferAttachmentCMAAINTELResourceManager() { |
53 Destroy(); | 52 Destroy(); |
54 } | 53 } |
55 | 54 |
56 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( | 55 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Initialize( |
57 gles2::GLES2Decoder* decoder) { | 56 gles2::GLES2Decoder* decoder) { |
58 DCHECK(decoder); | 57 DCHECK(decoder); |
59 is_gles31_compatible_ = | 58 is_gles31_compatible_ = |
60 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); | 59 decoder->GetGLContext()->GetVersionInfo()->IsAtLeastGLES(3, 1); |
61 | 60 |
62 copy_to_framebuffer_shader_ = | |
63 CreateProgram("", vert_str_, copy_frag_str_); | |
64 | |
65 // Check if RGBA8UI is supported as an FBO colour target with depth. | 61 // Check if RGBA8UI is supported as an FBO colour target with depth. |
66 // If not supported, GLSL needs to convert the data to/from float so there is | 62 // If not supported, GLSL needs to convert the data to/from float so there is |
67 // a small extra cost. | 63 // a small extra cost. |
68 { | 64 { |
69 GLuint rgba8ui_texture = 0, depth_texture = 0; | 65 GLuint rgba8ui_texture = 0, depth_texture = 0; |
70 glGenTextures(1, &rgba8ui_texture); | 66 glGenTextures(1, &rgba8ui_texture); |
71 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); | 67 glBindTexture(GL_TEXTURE_2D, rgba8ui_texture); |
72 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); | 68 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8UI, 4, 4); |
73 | 69 |
74 glGenTextures(1, &depth_texture); | 70 glGenTextures(1, &depth_texture); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 186 |
191 initialized_ = true; | 187 initialized_ = true; |
192 } | 188 } |
193 | 189 |
194 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() { | 190 void ApplyFramebufferAttachmentCMAAINTELResourceManager::Destroy() { |
195 if (!initialized_) | 191 if (!initialized_) |
196 return; | 192 return; |
197 | 193 |
198 ReleaseTextures(); | 194 ReleaseTextures(); |
199 | 195 |
200 glDeleteProgram(copy_to_framebuffer_shader_); | |
201 glDeleteProgram(process_and_apply_shader_); | 196 glDeleteProgram(process_and_apply_shader_); |
202 glDeleteProgram(edges_combine_shader_); | 197 glDeleteProgram(edges_combine_shader_); |
203 glDeleteProgram(edges1_shader_); | 198 glDeleteProgram(edges1_shader_); |
204 glDeleteProgram(edges0_shader_); | 199 glDeleteProgram(edges0_shader_); |
205 glDeleteProgram(debug_display_edges_shader_); | 200 glDeleteProgram(debug_display_edges_shader_); |
206 | 201 |
207 initialized_ = false; | 202 initialized_ = false; |
208 } | 203 } |
209 | 204 |
210 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the | 205 // Apply CMAA(Conservative Morphological Anti-Aliasing) algorithm to the |
211 // color attachments of currently bound draw framebuffer. | 206 // color attachments of currently bound draw framebuffer. |
212 // Reference GL_INTEL_framebuffer_CMAA for details. | 207 // Reference GL_INTEL_framebuffer_CMAA for details. |
213 void ApplyFramebufferAttachmentCMAAINTELResourceManager:: | 208 void ApplyFramebufferAttachmentCMAAINTELResourceManager:: |
214 ApplyFramebufferAttachmentCMAAINTEL(gles2::GLES2Decoder* decoder, | 209 ApplyFramebufferAttachmentCMAAINTEL( |
215 gles2::Framebuffer* framebuffer) { | 210 gles2::GLES2Decoder* decoder, |
| 211 gles2::Framebuffer* framebuffer, |
| 212 gles2::CopyTextureCHROMIUMResourceManager* copier) { |
216 DCHECK(decoder); | 213 DCHECK(decoder); |
217 DCHECK(initialized_); | 214 DCHECK(initialized_); |
218 if (!framebuffer) | 215 if (!framebuffer) |
219 return; | 216 return; |
220 | 217 |
221 glDisable(GL_SCISSOR_TEST); | 218 glDisable(GL_SCISSOR_TEST); |
222 glDisable(GL_STENCIL_TEST); | 219 glDisable(GL_STENCIL_TEST); |
223 glDisable(GL_CULL_FACE); | 220 glDisable(GL_CULL_FACE); |
224 glDisable(GL_BLEND); | 221 glDisable(GL_BLEND); |
225 | 222 |
(...skipping 16 matching lines...) Expand all Loading... |
242 // Resize internal structures - only if needed. | 239 // Resize internal structures - only if needed. |
243 OnSize(width, height); | 240 OnSize(width, height); |
244 | 241 |
245 // CMAA internally expects GL_RGBA8 textures. | 242 // CMAA internally expects GL_RGBA8 textures. |
246 // Process using a GL_RGBA8 copy if this is not the case. | 243 // Process using a GL_RGBA8 copy if this is not the case. |
247 bool do_copy = internal_format != GL_RGBA8; | 244 bool do_copy = internal_format != GL_RGBA8; |
248 | 245 |
249 // CMAA Effect | 246 // CMAA Effect |
250 if (do_copy) { | 247 if (do_copy) { |
251 ApplyCMAAEffectTexture(source_texture, rgba8_texture_, do_copy); | 248 ApplyCMAAEffectTexture(source_texture, rgba8_texture_, do_copy); |
252 CopyTexture(rgba8_texture_, source_texture); | 249 |
| 250 copier->DoCopySubTexture( |
| 251 decoder, GL_TEXTURE_2D, rgba8_texture_, GL_RGBA8, GL_TEXTURE_2D, |
| 252 source_texture, internal_format, 0, 0, 0, 0, width_, height_, |
| 253 width_, height_, width_, height_, false, false, false); |
253 } else { | 254 } else { |
254 ApplyCMAAEffectTexture(source_texture, source_texture, do_copy); | 255 ApplyCMAAEffectTexture(source_texture, source_texture, do_copy); |
255 } | 256 } |
256 | 257 |
257 decoder->RestoreTextureState(source_texture); | 258 decoder->RestoreTextureState(source_texture); |
258 } | 259 } |
259 } | 260 } |
260 | 261 |
261 // Restore state | 262 // Restore state |
262 decoder->RestoreAllAttributes(); | 263 decoder->RestoreAllAttributes(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 void ApplyFramebufferAttachmentCMAAINTELResourceManager::OnSize(GLint width, | 467 void ApplyFramebufferAttachmentCMAAINTELResourceManager::OnSize(GLint width, |
467 GLint height) { | 468 GLint height) { |
468 if (height_ == height && width_ == width) | 469 if (height_ == height && width_ == width) |
469 return; | 470 return; |
470 | 471 |
471 ReleaseTextures(); | 472 ReleaseTextures(); |
472 | 473 |
473 height_ = height; | 474 height_ = height; |
474 width_ = width; | 475 width_ = width; |
475 | 476 |
476 glGenFramebuffersEXT(1, ©_framebuffer_); | |
477 glGenTextures(1, &rgba8_texture_); | 477 glGenTextures(1, &rgba8_texture_); |
478 glBindTexture(GL_TEXTURE_2D, rgba8_texture_); | 478 glBindTexture(GL_TEXTURE_2D, rgba8_texture_); |
479 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); | 479 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); |
480 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_); | |
481 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | |
482 rgba8_texture_, 0); | |
483 | 480 |
484 // Edges texture - R8 | 481 // Edges texture - R8 |
485 // OpenGLES has no single component 8/16-bit image support, so needs to be R32 | 482 // OpenGLES has no single component 8/16-bit image support, so needs to be R32 |
486 // Although CHT does support R8. | 483 // Although CHT does support R8. |
487 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; | 484 GLenum edge_format = supports_r8_image_ ? GL_R8 : GL_R32F; |
488 glGenTextures(1, &edges0_texture_); | 485 glGenTextures(1, &edges0_texture_); |
489 glBindTexture(GL_TEXTURE_2D, edges0_texture_); | 486 glBindTexture(GL_TEXTURE_2D, edges0_texture_); |
490 glTexStorage2DEXT(GL_TEXTURE_2D, 1, edge_format, width, height); | 487 glTexStorage2DEXT(GL_TEXTURE_2D, 1, edge_format, width, height); |
491 | 488 |
492 glGenTextures(1, &edges1_texture_); | 489 glGenTextures(1, &edges1_texture_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 527 |
531 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 528 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
532 edges1_texture_, 0); | 529 edges1_texture_, 0); |
533 glClear(GL_COLOR_BUFFER_BIT); | 530 glClear(GL_COLOR_BUFFER_BIT); |
534 | 531 |
535 textures_initialized_ = true; | 532 textures_initialized_ = true; |
536 } | 533 } |
537 | 534 |
538 void ApplyFramebufferAttachmentCMAAINTELResourceManager::ReleaseTextures() { | 535 void ApplyFramebufferAttachmentCMAAINTELResourceManager::ReleaseTextures() { |
539 if (textures_initialized_) { | 536 if (textures_initialized_) { |
540 glDeleteFramebuffersEXT(1, ©_framebuffer_); | |
541 glDeleteFramebuffersEXT(1, &cmaa_framebuffer_); | 537 glDeleteFramebuffersEXT(1, &cmaa_framebuffer_); |
542 glDeleteTextures(1, &rgba8_texture_); | 538 glDeleteTextures(1, &rgba8_texture_); |
543 glDeleteTextures(1, &edges0_texture_); | 539 glDeleteTextures(1, &edges0_texture_); |
544 glDeleteTextures(1, &edges1_texture_); | 540 glDeleteTextures(1, &edges1_texture_); |
545 glDeleteTextures(1, &mini4_edge_texture_); | 541 glDeleteTextures(1, &mini4_edge_texture_); |
546 glDeleteTextures(1, &mini4_edge_depth_texture_); | 542 glDeleteTextures(1, &mini4_edge_depth_texture_); |
547 glDeleteTextures(1, &working_color_texture_); | 543 glDeleteTextures(1, &working_color_texture_); |
548 } | 544 } |
549 textures_initialized_ = false; | 545 textures_initialized_ = false; |
550 } | 546 } |
551 | 547 |
552 // TODO(dshwang): reuse CopyTextureCHROMIUMResourceManager. crbug.com/535198 | |
553 void ApplyFramebufferAttachmentCMAAINTELResourceManager::CopyTexture( | |
554 GLint source, | |
555 GLint dest) { | |
556 glBindFramebufferEXT(GL_FRAMEBUFFER, copy_framebuffer_); | |
557 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
558 GL_TEXTURE_2D, dest, 0); | |
559 glViewport(0, 0, width_, height_); | |
560 | |
561 glActiveTexture(GL_TEXTURE0); | |
562 glBindTexture(GL_TEXTURE_2D, source); | |
563 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
564 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
565 | |
566 glUseProgram(copy_to_framebuffer_shader_); | |
567 | |
568 glDrawArrays(GL_TRIANGLES, 0, 3); | |
569 glUseProgram(0); | |
570 glBindTexture(GL_TEXTURE_2D, 0); | |
571 } | |
572 | |
573 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram( | 548 GLuint ApplyFramebufferAttachmentCMAAINTELResourceManager::CreateProgram( |
574 const char* defines, | 549 const char* defines, |
575 const char* vs_source, | 550 const char* vs_source, |
576 const char* fs_source) { | 551 const char* fs_source) { |
577 GLuint program = glCreateProgram(); | 552 GLuint program = glCreateProgram(); |
578 | 553 |
579 GLuint vs = CreateShader(GL_VERTEX_SHADER, defines, vs_source); | 554 GLuint vs = CreateShader(GL_VERTEX_SHADER, defines, vs_source); |
580 GLuint fs = CreateShader(GL_FRAGMENT_SHADER, defines, fs_source); | 555 GLuint fs = CreateShader(GL_FRAGMENT_SHADER, defines, fs_source); |
581 | 556 |
582 glAttachShader(program, vs); | 557 glAttachShader(program, vs); |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 CombineEdges(); | 1837 CombineEdges(); |
1863 \n#endif\n | 1838 \n#endif\n |
1864 \n#if defined BLUR_EDGES\n | 1839 \n#if defined BLUR_EDGES\n |
1865 BlurEdges(); | 1840 BlurEdges(); |
1866 \n#endif\n | 1841 \n#endif\n |
1867 \n#if defined DISPLAY_EDGES\n | 1842 \n#if defined DISPLAY_EDGES\n |
1868 DisplayEdges(); | 1843 DisplayEdges(); |
1869 \n#endif\n | 1844 \n#endif\n |
1870 } | 1845 } |
1871 ); | 1846 ); |
1872 | |
1873 const char | |
1874 ApplyFramebufferAttachmentCMAAINTELResourceManager::copy_frag_str_[] = | |
1875 SHADER( | |
1876 precision highp float; | |
1877 layout(binding = 0) uniform highp sampler2D inTexture; | |
1878 layout(location = 0) out vec4 outColor; | |
1879 | |
1880 void main() { | |
1881 ivec2 screenPosI = ivec2( gl_FragCoord.xy ); | |
1882 vec4 pixel = texelFetch(inTexture, screenPosI, 0); | |
1883 outColor = pixel; | |
1884 } | |
1885 ); | |
1886 /* clang-format on */ | 1847 /* clang-format on */ |
1887 | 1848 |
1888 } // namespace gles2 | 1849 } // namespace gles2 |
1889 } // namespace gpu | 1850 } // namespace gpu |
OLD | NEW |