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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 375303002: cc: Refactor ResourceProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing typing error in build.gn Created 6 years, 5 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 | « cc/cc.gyp ('k') | cc/resources/gpu_raster_worker_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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 "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Smallest unit that impact anti-aliasing output. We use this to 174 // Smallest unit that impact anti-aliasing output. We use this to
175 // determine when anti-aliasing is unnecessary. 175 // determine when anti-aliasing is unnecessary.
176 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; 176 const float kAntiAliasingEpsilon = 1.0f / 1024.0f;
177 177
178 // Block or crash if the number of pending sync queries reach this high as 178 // Block or crash if the number of pending sync queries reach this high as
179 // something is seriously wrong on the service side if this happens. 179 // something is seriously wrong on the service side if this happens.
180 const size_t kMaxPendingSyncQueries = 16; 180 const size_t kMaxPendingSyncQueries = 16;
181 181
182 } // anonymous namespace 182 } // anonymous namespace
183 183
184 static GLint GetActiveTextureUnit(GLES2Interface* gl) {
185 GLint active_unit = 0;
186 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
187 return active_unit;
188 }
189
184 class GLRenderer::ScopedUseGrContext { 190 class GLRenderer::ScopedUseGrContext {
185 public: 191 public:
186 static scoped_ptr<ScopedUseGrContext> Create(GLRenderer* renderer, 192 static scoped_ptr<ScopedUseGrContext> Create(GLRenderer* renderer,
187 DrawingFrame* frame) { 193 DrawingFrame* frame) {
188 if (!renderer->output_surface_->context_provider()->GrContext()) 194 if (!renderer->output_surface_->context_provider()->GrContext())
189 return scoped_ptr<ScopedUseGrContext>(); 195 return scoped_ptr<ScopedUseGrContext>();
190 return make_scoped_ptr(new ScopedUseGrContext(renderer, frame)); 196 return make_scoped_ptr(new ScopedUseGrContext(renderer, frame));
191 } 197 }
192 198
193 ~ScopedUseGrContext() { PassControlToGLRenderer(); } 199 ~ScopedUseGrContext() { PassControlToGLRenderer(); }
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 mask_texture_id = mask_resource_lock->texture_id(); 1065 mask_texture_id = mask_resource_lock->texture_id();
1060 } 1066 }
1061 1067
1062 // TODO(danakj): use the background_texture and blend the background in with 1068 // TODO(danakj): use the background_texture and blend the background in with
1063 // this draw instead of having a separate copy of the background texture. 1069 // this draw instead of having a separate copy of the background texture.
1064 1070
1065 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; 1071 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock;
1066 if (filter_bitmap.getTexture()) { 1072 if (filter_bitmap.getTexture()) {
1067 GrTexture* texture = 1073 GrTexture* texture =
1068 reinterpret_cast<GrTexture*>(filter_bitmap.getTexture()); 1074 reinterpret_cast<GrTexture*>(filter_bitmap.getTexture());
1069 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 1075 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
1070 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); 1076 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
1071 } else { 1077 } else {
1072 contents_resource_lock = 1078 contents_resource_lock =
1073 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( 1079 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL(
1074 resource_provider_, contents_texture->id(), GL_LINEAR)); 1080 resource_provider_, contents_texture->id(), GL_LINEAR));
1075 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1081 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1076 contents_resource_lock->target()); 1082 contents_resource_lock->target());
1077 } 1083 }
1078 1084
1079 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1085 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 GetVideoStreamTextureProgram(tex_coord_precision); 1853 GetVideoStreamTextureProgram(tex_coord_precision);
1848 SetUseProgram(program->program()); 1854 SetUseProgram(program->program());
1849 1855
1850 ToGLMatrix(&gl_matrix[0], quad->matrix); 1856 ToGLMatrix(&gl_matrix[0], quad->matrix);
1851 GLC(gl_, 1857 GLC(gl_,
1852 gl_->UniformMatrix4fv( 1858 gl_->UniformMatrix4fv(
1853 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); 1859 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix));
1854 1860
1855 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 1861 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
1856 quad->resource_id); 1862 quad->resource_id);
1857 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 1863 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
1858 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); 1864 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()));
1859 1865
1860 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 1866 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
1861 1867
1862 SetShaderOpacity(quad->opacity(), 1868 SetShaderOpacity(quad->opacity(),
1863 program->fragment_shader().alpha_location()); 1869 program->fragment_shader().alpha_location());
1864 DrawQuadGeometry(frame, 1870 DrawQuadGeometry(frame,
1865 quad->quadTransform(), 1871 quad->quadTransform(),
1866 quad->rect, 1872 quad->rect,
1867 program->vertex_shader().matrix_location()); 1873 program->vertex_shader().matrix_location());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 1963
1958 // Bind the program to the GL state. 1964 // Bind the program to the GL state.
1959 SetUseProgram(draw_cache_.program_id); 1965 SetUseProgram(draw_cache_.program_id);
1960 1966
1961 // Bind the correct texture sampler location. 1967 // Bind the correct texture sampler location.
1962 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); 1968 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0));
1963 1969
1964 // Assume the current active textures is 0. 1970 // Assume the current active textures is 0.
1965 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_, 1971 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_,
1966 draw_cache_.resource_id); 1972 draw_cache_.resource_id);
1967 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 1973 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
1968 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id())); 1974 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id()));
1969 1975
1970 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), struct_is_densely_packed); 1976 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), struct_is_densely_packed);
1971 COMPILE_ASSERT(sizeof(Float16) == 16 * sizeof(float), 1977 COMPILE_ASSERT(sizeof(Float16) == 16 * sizeof(float),
1972 struct_is_densely_packed); 1978 struct_is_densely_packed);
1973 1979
1974 // Upload the tranforms for both points and uvs. 1980 // Upload the tranforms for both points and uvs.
1975 GLC(gl_, 1981 GLC(gl_,
1976 gl_->UniformMatrix4fv( 1982 gl_->UniformMatrix4fv(
1977 static_cast<int>(draw_cache_.matrix_location), 1983 static_cast<int>(draw_cache_.matrix_location),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 quad->io_surface_size.width(), 2112 quad->io_surface_size.width(),
2107 quad->io_surface_size.height())); 2113 quad->io_surface_size.height()));
2108 } 2114 }
2109 2115
2110 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), 2116 const float vertex_opacity[] = {quad->opacity(), quad->opacity(),
2111 quad->opacity(), quad->opacity()}; 2117 quad->opacity(), quad->opacity()};
2112 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); 2118 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity));
2113 2119
2114 ResourceProvider::ScopedReadLockGL lock(resource_provider_, 2120 ResourceProvider::ScopedReadLockGL lock(resource_provider_,
2115 quad->io_surface_resource_id); 2121 quad->io_surface_resource_id);
2116 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 2122 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2117 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); 2123 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id()));
2118 2124
2119 DrawQuadGeometry( 2125 DrawQuadGeometry(
2120 frame, quad->quadTransform(), quad->rect, binding.matrix_location); 2126 frame, quad->quadTransform(), quad->rect, binding.matrix_location);
2121 2127
2122 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); 2128 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0));
2123 } 2129 }
2124 2130
2125 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { 2131 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) {
2126 if (use_sync_query_) { 2132 if (use_sync_query_) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 } else { 2265 } else {
2260 GLC(gl_, 2266 GLC(gl_,
2261 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), 2267 gl_->Uniform4f(program->vertex_shader().tex_transform_location(),
2262 0.f, 2268 0.f,
2263 0.f, 2269 0.f,
2264 1.f, 2270 1.f,
2265 1.f)); 2271 1.f));
2266 } 2272 }
2267 2273
2268 SetShaderOpacity(1.f, program->fragment_shader().alpha_location()); 2274 SetShaderOpacity(1.f, program->fragment_shader().alpha_location());
2269 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 2275 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
2270 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); 2276 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id));
2271 DrawQuadGeometry( 2277 DrawQuadGeometry(
2272 frame, draw_matrix, rect, program->vertex_shader().matrix_location()); 2278 frame, draw_matrix, rect, program->vertex_shader().matrix_location());
2273 } 2279 }
2274 2280
2275 void GLRenderer::Finish() { 2281 void GLRenderer::Finish() {
2276 TRACE_EVENT0("cc", "GLRenderer::Finish"); 2282 TRACE_EVENT0("cc", "GLRenderer::Finish");
2277 GLC(gl_, gl_->Finish()); 2283 GLC(gl_, gl_->Finish());
2278 } 2284 }
2279 2285
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 context_support_->ScheduleOverlayPlane( 3171 context_support_->ScheduleOverlayPlane(
3166 overlay.plane_z_order, 3172 overlay.plane_z_order,
3167 overlay.transform, 3173 overlay.transform,
3168 pending_overlay_resources_.back()->texture_id(), 3174 pending_overlay_resources_.back()->texture_id(),
3169 overlay.display_rect, 3175 overlay.display_rect,
3170 overlay.uv_rect); 3176 overlay.uv_rect);
3171 } 3177 }
3172 } 3178 }
3173 3179
3174 } // namespace cc 3180 } // namespace cc
OLDNEW
« no previous file with comments | « cc/cc.gyp ('k') | cc/resources/gpu_raster_worker_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698