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

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

Issue 12642010: Implement on demand quad rasterization for PicturePiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 7 years, 9 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/quads/content_draw_quad_base.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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "cc/base/math_util.h" 16 #include "cc/base/math_util.h"
17 #include "cc/layers/video_layer_impl.h" 17 #include "cc/layers/video_layer_impl.h"
18 #include "cc/output/compositor_frame.h" 18 #include "cc/output/compositor_frame.h"
19 #include "cc/output/compositor_frame_metadata.h" 19 #include "cc/output/compositor_frame_metadata.h"
20 #include "cc/output/context_provider.h" 20 #include "cc/output/context_provider.h"
21 #include "cc/output/geometry_binding.h" 21 #include "cc/output/geometry_binding.h"
22 #include "cc/output/gl_frame_data.h" 22 #include "cc/output/gl_frame_data.h"
23 #include "cc/output/output_surface.h" 23 #include "cc/output/output_surface.h"
24 #include "cc/output/render_surface_filters.h" 24 #include "cc/output/render_surface_filters.h"
25 #include "cc/quads/picture_draw_quad.h"
25 #include "cc/quads/render_pass.h" 26 #include "cc/quads/render_pass.h"
26 #include "cc/quads/stream_video_draw_quad.h" 27 #include "cc/quads/stream_video_draw_quad.h"
27 #include "cc/quads/texture_draw_quad.h" 28 #include "cc/quads/texture_draw_quad.h"
28 #include "cc/resources/layer_quad.h" 29 #include "cc/resources/layer_quad.h"
29 #include "cc/resources/priority_calculator.h" 30 #include "cc/resources/priority_calculator.h"
30 #include "cc/resources/scoped_resource.h" 31 #include "cc/resources/scoped_resource.h"
31 #include "cc/trees/damage_tracker.h" 32 #include "cc/trees/damage_tracker.h"
32 #include "cc/trees/proxy.h" 33 #include "cc/trees/proxy.h"
33 #include "cc/trees/single_thread_proxy.h" 34 #include "cc/trees/single_thread_proxy.h"
34 #include "gpu/GLES2/gl2extchromium.h" 35 #include "gpu/GLES2/gl2extchromium.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 : DirectRenderer(client, resource_provider), 98 : DirectRenderer(client, resource_provider),
98 offscreen_framebuffer_id_(0), 99 offscreen_framebuffer_id_(0),
99 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), 100 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)),
100 output_surface_(output_surface), 101 output_surface_(output_surface),
101 context_(output_surface->context3d()), 102 context_(output_surface->context3d()),
102 is_viewport_changed_(false), 103 is_viewport_changed_(false),
103 is_backbuffer_discarded_(false), 104 is_backbuffer_discarded_(false),
104 discard_backbuffer_when_not_visible_(false), 105 discard_backbuffer_when_not_visible_(false),
105 is_using_bind_uniform_(false), 106 is_using_bind_uniform_(false),
106 visible_(true), 107 visible_(true),
107 is_scissor_enabled_(false) { 108 is_scissor_enabled_(false),
109 on_demand_tile_raster_resource_id_(0) {
108 DCHECK(context_); 110 DCHECK(context_);
109 } 111 }
110 112
111 bool GLRenderer::Initialize() { 113 bool GLRenderer::Initialize() {
112 if (!context_->makeContextCurrent()) 114 if (!context_->makeContextCurrent())
113 return false; 115 return false;
114 116
115 context_->setContextLostCallback(this); 117 context_->setContextLostCallback(this);
116 context_->pushGroupMarkerEXT("CompositorContext"); 118 context_->pushGroupMarkerEXT("CompositorContext");
117 119
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 break; 298 break;
297 case DrawQuad::CHECKERBOARD: 299 case DrawQuad::CHECKERBOARD:
298 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); 300 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad));
299 break; 301 break;
300 case DrawQuad::DEBUG_BORDER: 302 case DrawQuad::DEBUG_BORDER:
301 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); 303 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad));
302 break; 304 break;
303 case DrawQuad::IO_SURFACE_CONTENT: 305 case DrawQuad::IO_SURFACE_CONTENT:
304 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); 306 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad));
305 break; 307 break;
308 case DrawQuad::PICTURE_CONTENT:
309 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad));
310 break;
306 case DrawQuad::RENDER_PASS: 311 case DrawQuad::RENDER_PASS:
307 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); 312 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad));
308 break; 313 break;
309 case DrawQuad::SOLID_COLOR: 314 case DrawQuad::SOLID_COLOR:
310 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); 315 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad));
311 break; 316 break;
312 case DrawQuad::STREAM_VIDEO_CONTENT: 317 case DrawQuad::STREAM_VIDEO_CONTENT:
313 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); 318 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad));
314 break; 319 break;
315 case DrawQuad::TEXTURE_CONTENT: 320 case DrawQuad::TEXTURE_CONTENT:
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1036
1032 uniforms->sampler_location = program->fragment_shader().sampler_location(); 1037 uniforms->sampler_location = program->fragment_shader().sampler_location();
1033 uniforms->alpha_location = program->fragment_shader().alpha_location(); 1038 uniforms->alpha_location = program->fragment_shader().alpha_location();
1034 uniforms->fragment_tex_transform_location = 1039 uniforms->fragment_tex_transform_location =
1035 program->fragment_shader().fragment_tex_transform_location(); 1040 program->fragment_shader().fragment_tex_transform_location();
1036 uniforms->edge_location = program->fragment_shader().edge_location(); 1041 uniforms->edge_location = program->fragment_shader().edge_location();
1037 } 1042 }
1038 1043
1039 void GLRenderer::DrawTileQuad(const DrawingFrame* frame, 1044 void GLRenderer::DrawTileQuad(const DrawingFrame* frame,
1040 const TileDrawQuad* quad) { 1045 const TileDrawQuad* quad) {
1046 DrawContentQuad(frame, quad, quad->resource_id);
1047 }
1048
1049 void GLRenderer::DrawContentQuad(const DrawingFrame* frame,
1050 const ContentDrawQuadBase* quad,
1051 ResourceProvider::ResourceId resource_id) {
1041 gfx::Rect tile_rect = quad->visible_rect; 1052 gfx::Rect tile_rect = quad->visible_rect;
1042 1053
1043 gfx::RectF tex_coord_rect = quad->tex_coord_rect; 1054 gfx::RectF tex_coord_rect = quad->tex_coord_rect;
1044 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); 1055 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width();
1045 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); 1056 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height();
1046 1057
1047 // tex_coord_rect corresponds to quad_rect, but quad_visible_rect may be 1058 // tex_coord_rect corresponds to quad_rect, but quad_visible_rect may be
1048 // smaller than quad_rect due to occlusion or clipping. Adjust 1059 // smaller than quad_rect due to occlusion or clipping. Adjust
1049 // tex_coord_rect to match. 1060 // tex_coord_rect to match.
1050 gfx::Vector2d top_left_diff = tile_rect.origin() - quad->rect.origin(); 1061 gfx::Vector2d top_left_diff = tile_rect.origin() - quad->rect.origin();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 } 1130 }
1120 1131
1121 SetUseProgram(uniforms.program); 1132 SetUseProgram(uniforms.program);
1122 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); 1133 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0));
1123 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); 1134 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f);
1124 GLenum filter = (use_aa || scaled || 1135 GLenum filter = (use_aa || scaled ||
1125 !quad->quadTransform().IsIdentityOrIntegerTranslation()) 1136 !quad->quadTransform().IsIdentityOrIntegerTranslation())
1126 ? GL_LINEAR 1137 ? GL_LINEAR
1127 : GL_NEAREST; 1138 : GL_NEAREST;
1128 ResourceProvider::ScopedSamplerGL quad_resource_lock( 1139 ResourceProvider::ScopedSamplerGL quad_resource_lock(
1129 resource_provider_, quad->resource_id, GL_TEXTURE_2D, filter); 1140 resource_provider_, resource_id, GL_TEXTURE_2D, filter);
1130 1141
1131 if (use_aa) { 1142 if (use_aa) {
1132 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); 1143 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge));
1133 1144
1134 GLC(Context(), 1145 GLC(Context(),
1135 Context()->uniform4f(uniforms.vertex_tex_transform_location, 1146 Context()->uniform4f(uniforms.vertex_tex_transform_location,
1136 vertex_tex_translate_x, 1147 vertex_tex_translate_x,
1137 vertex_tex_translate_y, 1148 vertex_tex_translate_y,
1138 vertex_tex_scale_x, 1149 vertex_tex_scale_x,
1139 vertex_tex_scale_y)); 1150 vertex_tex_scale_y));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); 1286 Context()->uniform1i(program->fragment_shader().sampler_location(), 0));
1276 1287
1277 SetShaderOpacity(quad->opacity(), 1288 SetShaderOpacity(quad->opacity(),
1278 program->fragment_shader().alpha_location()); 1289 program->fragment_shader().alpha_location());
1279 DrawQuadGeometry(frame, 1290 DrawQuadGeometry(frame,
1280 quad->quadTransform(), 1291 quad->quadTransform(),
1281 quad->rect, 1292 quad->rect,
1282 program->vertex_shader().matrix_location()); 1293 program->vertex_shader().matrix_location());
1283 } 1294 }
1284 1295
1296 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame,
1297 const PictureDrawQuad* quad) {
1298 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() ||
1299 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) {
1300 on_demand_tile_raster_bitmap_.setConfig(
1301 SkBitmap::kARGB_8888_Config,
1302 quad->texture_size.width(),
1303 quad->texture_size.height());
1304 on_demand_tile_raster_bitmap_.allocPixels();
1305
1306 if (on_demand_tile_raster_resource_id_)
1307 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
1308
1309 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture(
1310 quad->texture_size,
1311 GL_RGBA,
1312 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
1313 ResourceProvider::TextureUsageAny);
1314 }
1315
1316 SkDevice device(on_demand_tile_raster_bitmap_);
1317 SkCanvas canvas(&device);
1318
1319 quad->picture_pile->Raster(&canvas, quad->content_rect, quad->contents_scale);
1320
1321 resource_provider_->SetPixels(
1322 on_demand_tile_raster_resource_id_,
1323 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()),
1324 gfx::Rect(quad->texture_size),
1325 gfx::Rect(quad->texture_size),
1326 gfx::Vector2d());
1327
1328 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_);
1329 }
1330
1285 struct TextureProgramBinding { 1331 struct TextureProgramBinding {
1286 template <class Program> 1332 template <class Program>
1287 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { 1333 void Set(Program* program, WebKit::WebGraphicsContext3D* context) {
1288 DCHECK(program && (program->initialized() || context->isContextLost())); 1334 DCHECK(program && (program->initialized() || context->isContextLost()));
1289 program_id = program->program(); 1335 program_id = program->program();
1290 sampler_location = program->fragment_shader().sampler_location(); 1336 sampler_location = program->fragment_shader().sampler_location();
1291 matrix_location = program->vertex_shader().matrix_location(); 1337 matrix_location = program->vertex_shader().matrix_location();
1292 alpha_location = program->fragment_shader().alpha_location(); 1338 alpha_location = program->fragment_shader().alpha_location();
1293 } 1339 }
1294 int program_id; 1340 int program_id;
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 if (debug_border_program_) 2267 if (debug_border_program_)
2222 debug_border_program_->Cleanup(context_); 2268 debug_border_program_->Cleanup(context_);
2223 if (solid_color_program_) 2269 if (solid_color_program_)
2224 solid_color_program_->Cleanup(context_); 2270 solid_color_program_->Cleanup(context_);
2225 if (solid_color_program_aa_) 2271 if (solid_color_program_aa_)
2226 solid_color_program_aa_->Cleanup(context_); 2272 solid_color_program_aa_->Cleanup(context_);
2227 2273
2228 if (offscreen_framebuffer_id_) 2274 if (offscreen_framebuffer_id_)
2229 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); 2275 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_));
2230 2276
2277 if (on_demand_tile_raster_resource_id_)
2278 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
2279
2231 ReleaseRenderPassTextures(); 2280 ReleaseRenderPassTextures();
2232 } 2281 }
2233 2282
2234 bool GLRenderer::IsContextLost() { 2283 bool GLRenderer::IsContextLost() {
2235 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 2284 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
2236 } 2285 }
2237 2286
2238 } // namespace cc 2287 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/quads/content_draw_quad_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698