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

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

Issue 23961003: cc: Remove most methods from RendererClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rendererclient: rebase Created 7 years, 3 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 scoped_ptr<CopyOutputRequest> copy_request; 121 scoped_ptr<CopyOutputRequest> copy_request;
122 base::CancelableClosure finished_read_pixels_callback; 122 base::CancelableClosure finished_read_pixels_callback;
123 unsigned buffer; 123 unsigned buffer;
124 124
125 private: 125 private:
126 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); 126 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels);
127 }; 127 };
128 128
129 scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client, 129 scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client,
130 const LayerTreeSettings* settings,
130 OutputSurface* output_surface, 131 OutputSurface* output_surface,
131 ResourceProvider* resource_provider, 132 ResourceProvider* resource_provider,
132 int highp_threshold_min, 133 int highp_threshold_min,
133 bool use_skia_gpu_backend) { 134 bool use_skia_gpu_backend) {
134 scoped_ptr<GLRenderer> renderer(new GLRenderer( 135 scoped_ptr<GLRenderer> renderer(new GLRenderer(client,
135 client, output_surface, resource_provider, highp_threshold_min)); 136 settings,
137 output_surface,
138 resource_provider,
139 highp_threshold_min));
136 if (!renderer->Initialize()) 140 if (!renderer->Initialize())
137 return scoped_ptr<GLRenderer>(); 141 return scoped_ptr<GLRenderer>();
138 if (use_skia_gpu_backend) { 142 if (use_skia_gpu_backend) {
139 renderer->InitializeGrContext(); 143 renderer->InitializeGrContext();
140 DCHECK(renderer->CanUseSkiaGPUBackend()) 144 DCHECK(renderer->CanUseSkiaGPUBackend())
141 << "Requested Skia GPU backend, but can't use it."; 145 << "Requested Skia GPU backend, but can't use it.";
142 } 146 }
143 147
144 return renderer.Pass(); 148 return renderer.Pass();
145 } 149 }
146 150
147 GLRenderer::GLRenderer(RendererClient* client, 151 GLRenderer::GLRenderer(RendererClient* client,
152 const LayerTreeSettings* settings,
148 OutputSurface* output_surface, 153 OutputSurface* output_surface,
149 ResourceProvider* resource_provider, 154 ResourceProvider* resource_provider,
150 int highp_threshold_min) 155 int highp_threshold_min)
151 : DirectRenderer(client, output_surface, resource_provider), 156 : DirectRenderer(client, settings, output_surface, resource_provider),
152 offscreen_framebuffer_id_(0), 157 offscreen_framebuffer_id_(0),
153 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), 158 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)),
154 context_(output_surface->context_provider()->Context3d()), 159 context_(output_surface->context_provider()->Context3d()),
155 is_backbuffer_discarded_(false), 160 is_backbuffer_discarded_(false),
156 discard_backbuffer_when_not_visible_(false), 161 discard_backbuffer_when_not_visible_(false),
157 is_using_bind_uniform_(false), 162 is_using_bind_uniform_(false),
158 visible_(true), 163 visible_(true),
159 is_scissor_enabled_(false), 164 is_scissor_enabled_(false),
160 stencil_shadow_(false), 165 stencil_shadow_(false),
161 blend_shadow_(false), 166 blend_shadow_(false),
162 highp_threshold_min_(highp_threshold_min), 167 highp_threshold_min_(highp_threshold_min),
163 highp_threshold_cache_(0), 168 highp_threshold_cache_(0),
164 offscreen_context_labelled_(false), 169 offscreen_context_labelled_(false),
165 on_demand_tile_raster_resource_id_(0) { 170 on_demand_tile_raster_resource_id_(0) {
166 DCHECK(context_); 171 DCHECK(context_);
167 } 172 }
168 173
169 bool GLRenderer::Initialize() { 174 bool GLRenderer::Initialize() {
170 if (!context_->makeContextCurrent()) 175 if (!context_->makeContextCurrent())
171 return false; 176 return false;
172 177
173 std::string unique_context_name = base::StringPrintf( 178 std::string unique_context_name =
174 "%s-%p", 179 base::StringPrintf("%s-%p", settings_->compositor_name.c_str(), context_);
175 Settings().compositor_name.c_str(),
176 context_);
177 context_->pushGroupMarkerEXT(unique_context_name.c_str()); 180 context_->pushGroupMarkerEXT(unique_context_name.c_str());
178 181
179 ContextProvider::Capabilities context_caps = 182 ContextProvider::Capabilities context_caps =
180 output_surface_->context_provider()->ContextCapabilities(); 183 output_surface_->context_provider()->ContextCapabilities();
181 184
182 capabilities_.using_partial_swap = 185 capabilities_.using_partial_swap =
183 Settings().partial_swap_enabled && 186 settings_->partial_swap_enabled && context_caps.post_sub_buffer;
184 context_caps.post_sub_buffer;
185 187
186 capabilities_.using_set_visibility = context_caps.set_visibility; 188 capabilities_.using_set_visibility = context_caps.set_visibility;
187 189
188 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); 190 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle);
189 191
190 capabilities_.using_egl_image = context_caps.egl_image_external; 192 capabilities_.using_egl_image = context_caps.egl_image_external;
191 193
192 capabilities_.max_texture_size = resource_provider_->max_texture_size(); 194 capabilities_.max_texture_size = resource_provider_->max_texture_size();
193 capabilities_.best_texture_format = resource_provider_->best_texture_format(); 195 capabilities_.best_texture_format = resource_provider_->best_texture_format();
194 196
195 // The updater can access textures while the GLRenderer is using them. 197 // The updater can access textures while the GLRenderer is using them.
196 capabilities_.allow_partial_texture_updates = true; 198 capabilities_.allow_partial_texture_updates = true;
197 199
198 // Check for texture fast paths. Currently we always use MO8 textures, 200 // Check for texture fast paths. Currently we always use MO8 textures,
199 // so we only need to avoid POT textures if we have an NPOT fast-path. 201 // so we only need to avoid POT textures if we have an NPOT fast-path.
200 capabilities_.avoid_pow2_textures = context_caps.fast_npot_mo8_textures; 202 capabilities_.avoid_pow2_textures = context_caps.fast_npot_mo8_textures;
201 203
202 capabilities_.using_offscreen_context3d = true; 204 capabilities_.using_offscreen_context3d = true;
203 205
204 capabilities_.using_map_image = 206 capabilities_.using_map_image =
205 Settings().use_map_image && context_caps.map_image; 207 settings_->use_map_image && context_caps.map_image;
206 208
207 capabilities_.using_discard_framebuffer = 209 capabilities_.using_discard_framebuffer =
208 context_caps.discard_framebuffer; 210 context_caps.discard_framebuffer;
209 211
210 is_using_bind_uniform_ = context_caps.bind_uniform_location; 212 is_using_bind_uniform_ = context_caps.bind_uniform_location;
211 213
212 if (!InitializeSharedObjects()) 214 if (!InitializeSharedObjects())
213 return false; 215 return false;
214 216
215 // Make sure the viewport and context gets initialized, even if it is to zero. 217 // Make sure the viewport and context gets initialized, even if it is to zero.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 285
284 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } 286 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); }
285 287
286 void GLRenderer::ViewportChanged() { 288 void GLRenderer::ViewportChanged() {
287 ReinitializeGrCanvas(); 289 ReinitializeGrCanvas();
288 } 290 }
289 291
290 void GLRenderer::ClearFramebuffer(DrawingFrame* frame) { 292 void GLRenderer::ClearFramebuffer(DrawingFrame* frame) {
291 // It's unsafe to clear when we have a stencil test because glClear ignores 293 // It's unsafe to clear when we have a stencil test because glClear ignores
292 // stencil. 294 // stencil.
293 if (client_->ExternalStencilTestEnabled() && 295 if (output_surface_->HasExternalStencilTest() &&
294 frame->current_render_pass == frame->root_render_pass) { 296 frame->current_render_pass == frame->root_render_pass) {
295 DCHECK(!frame->current_render_pass->has_transparent_background); 297 DCHECK(!frame->current_render_pass->has_transparent_background);
296 return; 298 return;
297 } 299 }
298 300
299 if (capabilities_.using_discard_framebuffer) { 301 if (capabilities_.using_discard_framebuffer) {
300 GLenum attachments[] = { 302 GLenum attachments[] = {
301 GL_COLOR_EXT 303 GL_COLOR_EXT
302 }; 304 };
303 context_->discardFramebufferEXT( 305 context_->discardFramebufferEXT(
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 1244
1243 gfx::Transform device_transform = 1245 gfx::Transform device_transform =
1244 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); 1246 frame->window_matrix * frame->projection_matrix * quad->quadTransform();
1245 device_transform.FlattenTo2d(); 1247 device_transform.FlattenTo2d();
1246 if (!device_transform.IsInvertible()) 1248 if (!device_transform.IsInvertible())
1247 return; 1249 return;
1248 1250
1249 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); 1251 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect));
1250 float edge[24]; 1252 float edge[24];
1251 bool use_aa = 1253 bool use_aa =
1252 Settings().allow_antialiasing && !quad->force_anti_aliasing_off && 1254 settings_->allow_antialiasing && !quad->force_anti_aliasing_off &&
1253 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); 1255 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge);
1254 1256
1255 SolidColorProgramUniforms uniforms; 1257 SolidColorProgramUniforms uniforms;
1256 if (use_aa) 1258 if (use_aa)
1257 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); 1259 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms);
1258 else 1260 else
1259 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); 1261 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms);
1260 SetUseProgram(uniforms.program); 1262 SetUseProgram(uniforms.program);
1261 1263
1262 GLC(Context(), 1264 GLC(Context(),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height(); 1383 float fragment_tex_scale_y = clamp_tex_rect.height() / texture_size.height();
1382 1384
1383 gfx::Transform device_transform = 1385 gfx::Transform device_transform =
1384 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); 1386 frame->window_matrix * frame->projection_matrix * quad->quadTransform();
1385 device_transform.FlattenTo2d(); 1387 device_transform.FlattenTo2d();
1386 if (!device_transform.IsInvertible()) 1388 if (!device_transform.IsInvertible())
1387 return; 1389 return;
1388 1390
1389 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); 1391 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect));
1390 float edge[24]; 1392 float edge[24];
1391 bool use_aa = Settings().allow_antialiasing && SetupQuadForAntialiasing( 1393 bool use_aa = settings_->allow_antialiasing && SetupQuadForAntialiasing(
1392 device_transform, quad, &local_quad, edge); 1394 device_transform, quad, &local_quad, edge);
1393 1395
1394 TileProgramUniforms uniforms; 1396 TileProgramUniforms uniforms;
1395 if (use_aa) { 1397 if (use_aa) {
1396 if (quad->swizzle_contents) { 1398 if (quad->swizzle_contents) {
1397 TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision), 1399 TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision),
1398 &uniforms); 1400 &uniforms);
1399 } else { 1401 } else {
1400 TileUniformLocation(GetTileProgramAA(tex_coord_precision), &uniforms); 1402 TileUniformLocation(GetTileProgramAA(tex_coord_precision), &uniforms);
1401 } 1403 }
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 DCHECK(visible_); 2093 DCHECK(visible_);
2092 DCHECK(!is_backbuffer_discarded_); 2094 DCHECK(!is_backbuffer_discarded_);
2093 2095
2094 TRACE_EVENT0("cc", "GLRenderer::SwapBuffers"); 2096 TRACE_EVENT0("cc", "GLRenderer::SwapBuffers");
2095 // We're done! Time to swapbuffers! 2097 // We're done! Time to swapbuffers!
2096 2098
2097 CompositorFrame compositor_frame; 2099 CompositorFrame compositor_frame;
2098 compositor_frame.metadata = client_->MakeCompositorFrameMetadata(); 2100 compositor_frame.metadata = client_->MakeCompositorFrameMetadata();
2099 compositor_frame.gl_frame_data = make_scoped_ptr(new GLFrameData); 2101 compositor_frame.gl_frame_data = make_scoped_ptr(new GLFrameData);
2100 compositor_frame.gl_frame_data->size = output_surface_->SurfaceSize(); 2102 compositor_frame.gl_frame_data->size = output_surface_->SurfaceSize();
2101 if (capabilities_.using_partial_swap && client_->AllowPartialSwap()) { 2103 if (capabilities_.using_partial_swap) {
2102 // If supported, we can save significant bandwidth by only swapping the 2104 // If supported, we can save significant bandwidth by only swapping the
2103 // damaged/scissored region (clamped to the viewport) 2105 // damaged/scissored region (clamped to the viewport)
2104 swap_buffer_rect_.Intersect(client_->DeviceViewport()); 2106 swap_buffer_rect_.Intersect(client_->DeviceViewport());
2105 int flipped_y_pos_of_rect_bottom = 2107 int flipped_y_pos_of_rect_bottom =
2106 client_->DeviceViewport().height() - swap_buffer_rect_.y() - 2108 client_->DeviceViewport().height() - swap_buffer_rect_.y() -
2107 swap_buffer_rect_.height(); 2109 swap_buffer_rect_.height();
2108 compositor_frame.gl_frame_data->sub_buffer_rect = 2110 compositor_frame.gl_frame_data->sub_buffer_rect =
2109 gfx::Rect(swap_buffer_rect_.x(), 2111 gfx::Rect(swap_buffer_rect_.x(),
2110 flipped_y_pos_of_rect_bottom, 2112 flipped_y_pos_of_rect_bottom,
2111 swap_buffer_rect_.width(), 2113 swap_buffer_rect_.width(),
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2504 frame->current_render_pass = NULL; 2506 frame->current_render_pass = NULL;
2505 frame->current_texture = texture; 2507 frame->current_texture = texture;
2506 2508
2507 return BindFramebufferToTexture(frame, texture, viewport_rect); 2509 return BindFramebufferToTexture(frame, texture, viewport_rect);
2508 } 2510 }
2509 2511
2510 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { 2512 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) {
2511 current_framebuffer_lock_.reset(); 2513 current_framebuffer_lock_.reset();
2512 output_surface_->BindFramebuffer(); 2514 output_surface_->BindFramebuffer();
2513 2515
2514 if (client_->ExternalStencilTestEnabled()) { 2516 if (output_surface_->HasExternalStencilTest()) {
2515 SetStencilEnabled(true); 2517 SetStencilEnabled(true);
2516 GLC(context_, context_->stencilFunc(GL_EQUAL, 1, 1)); 2518 GLC(context_, context_->stencilFunc(GL_EQUAL, 1, 1));
2517 } else { 2519 } else {
2518 SetStencilEnabled(false); 2520 SetStencilEnabled(false);
2519 } 2521 }
2520 } 2522 }
2521 2523
2522 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, 2524 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame,
2523 const ScopedResource* texture, 2525 const ScopedResource* texture,
2524 gfx::Rect target_rect) { 2526 gfx::Rect target_rect) {
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
3152 bool GLRenderer::IsContextLost() { 3154 bool GLRenderer::IsContextLost() {
3153 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 3155 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
3154 } 3156 }
3155 3157
3156 void GLRenderer::LazyLabelOffscreenContext( 3158 void GLRenderer::LazyLabelOffscreenContext(
3157 ContextProvider* offscreen_context_provider) { 3159 ContextProvider* offscreen_context_provider) {
3158 if (offscreen_context_labelled_) 3160 if (offscreen_context_labelled_)
3159 return; 3161 return;
3160 offscreen_context_labelled_ = true; 3162 offscreen_context_labelled_ = true;
3161 std::string unique_context_name = base::StringPrintf( 3163 std::string unique_context_name = base::StringPrintf(
3162 "%s-Offscreen-%p", 3164 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_);
3163 Settings().compositor_name.c_str(), 3165 offscreen_context_provider->Context3d()
3164 context_); 3166 ->pushGroupMarkerEXT(unique_context_name.c_str());
3165 offscreen_context_provider->Context3d()->pushGroupMarkerEXT(
3166 unique_context_name.c_str());
3167 } 3167 }
3168 3168
3169 3169
3170 } // namespace cc 3170 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698