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

Side by Side Diff: ui/gl/yuv_to_rgb_converter.cc

Issue 2629633003: Refactor GL bindings so there is no global GLApi or DriverGL. (Closed)
Patch Set: rebase Created 3 years, 10 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
« no previous file with comments | « ui/gl/test/gl_surface_test_support.cc ('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 "ui/gl/yuv_to_rgb_converter.h" 5 #include "ui/gl/yuv_to_rgb_converter.h"
6 6
7 #include "base/strings/stringize_macros.h" 7 #include "base/strings/stringize_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "ui/gl/gl_helper.h" 9 #include "ui/gl/gl_helper.h"
10 #include "ui/gl/gl_version_info.h" 10 #include "ui/gl/gl_version_info.h"
11 #include "ui/gl/scoped_api.h"
12 #include "ui/gl/scoped_binders.h" 11 #include "ui/gl/scoped_binders.h"
13 12
14 namespace gl { 13 namespace gl {
15 namespace { 14 namespace {
16 15
17 const char kVertexHeaderCompatiblityProfile[] = 16 const char kVertexHeaderCompatiblityProfile[] =
18 "#version 110\n" 17 "#version 110\n"
19 "#define ATTRIBUTE attribute\n" 18 "#define ATTRIBUTE attribute\n"
20 "#define VARYING varying\n"; 19 "#define VARYING varying\n";
21 20
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 TEX(a_uv_texture, v_texCoord * 0.5).rg); 64 TEX(a_uv_texture, v_texCoord * 0.5).rg);
66 FRAGCOLOR = vec4(yuv_matrix * (yuv + yuv_adj), 1.0); 65 FRAGCOLOR = vec4(yuv_matrix * (yuv + yuv_adj), 1.0);
67 } 66 }
68 ); 67 );
69 // clang-format on 68 // clang-format on
70 69
71 } // namespace 70 } // namespace
72 71
73 YUVToRGBConverter::YUVToRGBConverter(const GLVersionInfo& gl_version_info) { 72 YUVToRGBConverter::YUVToRGBConverter(const GLVersionInfo& gl_version_info) {
74 bool use_core_profile = gl_version_info.is_desktop_core_profile; 73 bool use_core_profile = gl_version_info.is_desktop_core_profile;
75 ScopedSetGLToRealGLApi scoped_set_gl_api;
76 glGenFramebuffersEXT(1, &framebuffer_); 74 glGenFramebuffersEXT(1, &framebuffer_);
77 vertex_buffer_ = GLHelper::SetupQuadVertexBuffer(); 75 vertex_buffer_ = GLHelper::SetupQuadVertexBuffer();
78 vertex_shader_ = GLHelper::LoadShader( 76 vertex_shader_ = GLHelper::LoadShader(
79 GL_VERTEX_SHADER, 77 GL_VERTEX_SHADER,
80 base::StringPrintf("%s\n%s", 78 base::StringPrintf("%s\n%s",
81 use_core_profile ? kVertexHeaderCoreProfile 79 use_core_profile ? kVertexHeaderCoreProfile
82 : kVertexHeaderCompatiblityProfile, 80 : kVertexHeaderCompatiblityProfile,
83 kVertexShader) 81 kVertexShader)
84 .c_str()); 82 .c_str());
85 fragment_shader_ = GLHelper::LoadShader( 83 fragment_shader_ = GLHelper::LoadShader(
(...skipping 14 matching lines...) Expand all
100 DCHECK_NE(-1, uv_sampler_location); 98 DCHECK_NE(-1, uv_sampler_location);
101 99
102 glGenTextures(1, &y_texture_); 100 glGenTextures(1, &y_texture_);
103 glGenTextures(1, &uv_texture_); 101 glGenTextures(1, &uv_texture_);
104 102
105 glUniform1i(y_sampler_location, 0); 103 glUniform1i(y_sampler_location, 0);
106 glUniform1i(uv_sampler_location, 1); 104 glUniform1i(uv_sampler_location, 1);
107 } 105 }
108 106
109 YUVToRGBConverter::~YUVToRGBConverter() { 107 YUVToRGBConverter::~YUVToRGBConverter() {
110 ScopedSetGLToRealGLApi scoped_set_gl_api;
111 glDeleteTextures(1, &y_texture_); 108 glDeleteTextures(1, &y_texture_);
112 glDeleteTextures(1, &uv_texture_); 109 glDeleteTextures(1, &uv_texture_);
113 glDeleteProgram(program_); 110 glDeleteProgram(program_);
114 glDeleteShader(vertex_shader_); 111 glDeleteShader(vertex_shader_);
115 glDeleteShader(fragment_shader_); 112 glDeleteShader(fragment_shader_);
116 glDeleteBuffersARB(1, &vertex_buffer_); 113 glDeleteBuffersARB(1, &vertex_buffer_);
117 glDeleteFramebuffersEXT(1, &framebuffer_); 114 glDeleteFramebuffersEXT(1, &framebuffer_);
118 } 115 }
119 116
120 void YUVToRGBConverter::CopyYUV420ToRGB(unsigned target, 117 void YUVToRGBConverter::CopyYUV420ToRGB(unsigned target,
121 const gfx::Size& size, 118 const gfx::Size& size,
122 unsigned rgb_texture) { 119 unsigned rgb_texture) {
123 ScopedSetGLToRealGLApi scoped_set_gl_api;
124
125 // Note that state restoration is done explicitly instead of scoped binders to 120 // Note that state restoration is done explicitly instead of scoped binders to
126 // avoid https://crbug.com/601729. 121 // avoid https://crbug.com/601729.
127 GLint old_active_texture = -1; 122 GLint old_active_texture = -1;
128 glGetIntegerv(GL_ACTIVE_TEXTURE, &old_active_texture); 123 glGetIntegerv(GL_ACTIVE_TEXTURE, &old_active_texture);
129 GLint old_texture0_binding = -1; 124 GLint old_texture0_binding = -1;
130 glActiveTexture(GL_TEXTURE0); 125 glActiveTexture(GL_TEXTURE0);
131 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_texture0_binding); 126 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_texture0_binding);
132 GLint old_texture1_binding = -1; 127 GLint old_texture1_binding = -1;
133 glActiveTexture(GL_TEXTURE1); 128 glActiveTexture(GL_TEXTURE1);
134 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_texture1_binding); 129 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_texture1_binding);
(...skipping 22 matching lines...) Expand all
157 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 152 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
158 target, 0, 0); 153 target, 0, 0);
159 glActiveTexture(GL_TEXTURE0); 154 glActiveTexture(GL_TEXTURE0);
160 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, old_texture0_binding); 155 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, old_texture0_binding);
161 glActiveTexture(GL_TEXTURE1); 156 glActiveTexture(GL_TEXTURE1);
162 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, old_texture1_binding); 157 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, old_texture1_binding);
163 glActiveTexture(old_active_texture); 158 glActiveTexture(old_active_texture);
164 } 159 }
165 160
166 } // namespace gl 161 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/test/gl_surface_test_support.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698