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

Side by Side Diff: cc/gl_renderer.cc

Issue 12642010: Implement on demand quad rasterization for PicturePiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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/gl_renderer.h" 5 #include "cc/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/compositor_frame.h" 16 #include "cc/compositor_frame.h"
17 #include "cc/compositor_frame_metadata.h" 17 #include "cc/compositor_frame_metadata.h"
18 #include "cc/context_provider.h" 18 #include "cc/context_provider.h"
19 #include "cc/damage_tracker.h" 19 #include "cc/damage_tracker.h"
20 #include "cc/geometry_binding.h" 20 #include "cc/geometry_binding.h"
21 #include "cc/gl_frame_data.h" 21 #include "cc/gl_frame_data.h"
22 #include "cc/layer_quad.h" 22 #include "cc/layer_quad.h"
23 #include "cc/math_util.h" 23 #include "cc/math_util.h"
24 #include "cc/output_surface.h" 24 #include "cc/output_surface.h"
25 #include "cc/picture_draw_quad.h"
25 #include "cc/priority_calculator.h" 26 #include "cc/priority_calculator.h"
26 #include "cc/proxy.h" 27 #include "cc/proxy.h"
27 #include "cc/render_pass.h" 28 #include "cc/render_pass.h"
28 #include "cc/render_surface_filters.h" 29 #include "cc/render_surface_filters.h"
29 #include "cc/scoped_resource.h" 30 #include "cc/scoped_resource.h"
30 #include "cc/single_thread_proxy.h" 31 #include "cc/single_thread_proxy.h"
31 #include "cc/stream_video_draw_quad.h" 32 #include "cc/stream_video_draw_quad.h"
32 #include "cc/texture_draw_quad.h" 33 #include "cc/texture_draw_quad.h"
33 #include "cc/video_layer_impl.h" 34 #include "cc/video_layer_impl.h"
34 #include "gpu/GLES2/gl2extchromium.h" 35 #include "gpu/GLES2/gl2extchromium.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 : DirectRenderer(client, resource_provider), 96 : DirectRenderer(client, resource_provider),
96 offscreen_framebuffer_id_(0), 97 offscreen_framebuffer_id_(0),
97 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)), 98 shared_geometry_quad_(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)),
98 output_surface_(output_surface), 99 output_surface_(output_surface),
99 context_(output_surface->context3d()), 100 context_(output_surface->context3d()),
100 is_viewport_changed_(false), 101 is_viewport_changed_(false),
101 is_backbuffer_discarded_(false), 102 is_backbuffer_discarded_(false),
102 discard_backbuffer_when_not_visible_(false), 103 discard_backbuffer_when_not_visible_(false),
103 is_using_bind_uniform_(false), 104 is_using_bind_uniform_(false),
104 visible_(true), 105 visible_(true),
105 is_scissor_enabled_(false) { 106 is_scissor_enabled_(false),
107 on_demand_tile_raster_texture_(0),
108 on_demand_tile_raster_resource_id_(0) {
106 DCHECK(context_); 109 DCHECK(context_);
107 } 110 }
108 111
109 bool GLRenderer::Initialize() { 112 bool GLRenderer::Initialize() {
110 if (!context_->makeContextCurrent()) 113 if (!context_->makeContextCurrent())
111 return false; 114 return false;
112 115
113 context_->setContextLostCallback(this); 116 context_->setContextLostCallback(this);
114 context_->pushGroupMarkerEXT("CompositorContext"); 117 context_->pushGroupMarkerEXT("CompositorContext");
115 118
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 break; 315 break;
313 case DrawQuad::TEXTURE_CONTENT: 316 case DrawQuad::TEXTURE_CONTENT:
314 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); 317 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad));
315 break; 318 break;
316 case DrawQuad::TILED_CONTENT: 319 case DrawQuad::TILED_CONTENT:
317 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); 320 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad));
318 break; 321 break;
319 case DrawQuad::YUV_VIDEO_CONTENT: 322 case DrawQuad::YUV_VIDEO_CONTENT:
320 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); 323 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad));
321 break; 324 break;
325 case DrawQuad::PICTURE_CONTENT:
danakj 2013/03/14 18:00:56 alphabetical please
Leandro Graciá Gil 2013/03/19 17:30:07 Done.
326 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad));
327 break;
322 } 328 }
323 } 329 }
324 330
325 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame& frame, 331 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame& frame,
326 const CheckerboardDrawQuad* quad) { 332 const CheckerboardDrawQuad* quad) {
327 SetBlendEnabled(quad->ShouldDrawWithBlending()); 333 SetBlendEnabled(quad->ShouldDrawWithBlending());
328 334
329 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); 335 const TileCheckerboardProgram* program = GetTileCheckerboardProgram();
330 DCHECK(program && (program->initialized() || IsContextLost())); 336 DCHECK(program && (program->initialized() || IsContextLost()));
331 SetUseProgram(program->program()); 337 SetUseProgram(program->program());
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } 984 }
979 } 985 }
980 986
981 SetUseProgram(uniforms.program); 987 SetUseProgram(uniforms.program);
982 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); 988 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0));
983 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); 989 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f);
984 GLenum filter = (use_aa || scaled || 990 GLenum filter = (use_aa || scaled ||
985 !quad->quadTransform().IsIdentityOrIntegerTranslation()) 991 !quad->quadTransform().IsIdentityOrIntegerTranslation())
986 ? GL_LINEAR 992 ? GL_LINEAR
987 : GL_NEAREST; 993 : GL_NEAREST;
994 ResourceProvider::ResourceId resource_id = quad->IsPictureQuad() ?
danakj 2013/03/14 18:00:56 How would you ever get here with IsPictureQuad() t
danakj 2013/03/14 18:01:21 Sorry, ignore this, I answered this myself later.
enne (OOO) 2013/03/15 03:29:28 I'd prefer if you just passed drawTileQuad the res
Leandro Graciá Gil 2013/03/19 17:30:07 I agree. I'm going with the base class. Seems a cl
995 on_demand_tile_raster_resource_id_ : quad->resource_id;
988 ResourceProvider::ScopedSamplerGL quad_resource_lock( 996 ResourceProvider::ScopedSamplerGL quad_resource_lock(
989 resource_provider_, quad->resource_id, GL_TEXTURE_2D, filter); 997 resource_provider_, resource_id, GL_TEXTURE_2D, filter);
990 998
991 if (use_aa) { 999 if (use_aa) {
992 LayerQuad deviceLayerBounds(gfx::QuadF(device_layer_quad.BoundingBox())); 1000 LayerQuad deviceLayerBounds(gfx::QuadF(device_layer_quad.BoundingBox()));
993 deviceLayerBounds.InflateAntiAliasingDistance(); 1001 deviceLayerBounds.InflateAntiAliasingDistance();
994 1002
995 LayerQuad device_layer_edges(device_layer_quad); 1003 LayerQuad device_layer_edges(device_layer_quad);
996 device_layer_edges.InflateAntiAliasingDistance(); 1004 device_layer_edges.InflateAntiAliasingDistance();
997 1005
998 float edge[24]; 1006 float edge[24];
999 device_layer_edges.ToFloatArray(edge); 1007 device_layer_edges.ToFloatArray(edge);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 GLC(Context(), 1206 GLC(Context(),
1199 Context()->uniform1i(program->fragmentShader().samplerLocation(), 0)); 1207 Context()->uniform1i(program->fragmentShader().samplerLocation(), 0));
1200 1208
1201 SetShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()); 1209 SetShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation());
1202 DrawQuadGeometry(frame, 1210 DrawQuadGeometry(frame,
1203 quad->quadTransform(), 1211 quad->quadTransform(),
1204 quad->rect, 1212 quad->rect,
1205 program->vertexShader().matrixLocation()); 1213 program->vertexShader().matrixLocation());
1206 } 1214 }
1207 1215
1216 void GLRenderer::DrawPictureQuad(const DrawingFrame& frame, const PictureDrawQua d* quad) {
1217 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() ||
1218 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) {
1219 on_demand_tile_raster_bitmap_.setConfig(
1220 SkBitmap::kARGB_8888_Config,
1221 quad->texture_size.width(),
1222 quad->texture_size.height());
1223 on_demand_tile_raster_bitmap_.allocPixels();
1224 }
1225
1226 SkDevice device(on_demand_tile_raster_bitmap_);
1227 SkCanvas canvas(&device);
1228
1229 int64 total_pixels_rasterized = 0;
1230 quad->picture_pile->Raster(
1231 &canvas,
1232 quad->content_rect,
1233 quad->contents_scale,
1234 &total_pixels_rasterized);
1235
1236 GLC(Context(), Context()->bindTexture(
1237 GL_TEXTURE_2D,
1238 on_demand_tile_raster_texture_));
1239
1240 GLC(Context(), Context()->texImage2D(
1241 GL_TEXTURE_2D,
1242 0,
1243 GL_RGBA,
1244 quad->texture_size.width(),
1245 quad->texture_size.height(),
1246 0,
1247 GL_RGBA,
1248 GL_UNSIGNED_BYTE,
1249 on_demand_tile_raster_bitmap_.getPixels()));
1250
1251 DrawTileQuad(frame, quad);
1252 }
1253
1208 struct TextureProgramBinding { 1254 struct TextureProgramBinding {
1209 template <class Program> 1255 template <class Program>
1210 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { 1256 void Set(Program* program, WebKit::WebGraphicsContext3D* context) {
1211 DCHECK(program && (program->initialized() || context->isContextLost())); 1257 DCHECK(program && (program->initialized() || context->isContextLost()));
1212 program_id = program->program(); 1258 program_id = program->program();
1213 sampler_location = program->fragmentShader().samplerLocation(); 1259 sampler_location = program->fragmentShader().samplerLocation();
1214 matrix_location = program->vertexShader().matrixLocation(); 1260 matrix_location = program->vertexShader().matrixLocation();
1215 alpha_location = program->fragmentShader().alphaLocation(); 1261 alpha_location = program->fragmentShader().alphaLocation();
1216 } 1262 }
1217 int program_id; 1263 int program_id;
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 1927
1882 // We will always need these programs to render, so create the programs 1928 // We will always need these programs to render, so create the programs
1883 // eagerly so that the shader compilation can start while we do other work. 1929 // eagerly so that the shader compilation can start while we do other work.
1884 // Other programs are created lazily on first access. 1930 // Other programs are created lazily on first access.
1885 shared_geometry_ = 1931 shared_geometry_ =
1886 make_scoped_ptr(new GeometryBinding(context_, QuadVertexRect())); 1932 make_scoped_ptr(new GeometryBinding(context_, QuadVertexRect()));
1887 render_pass_program_ = make_scoped_ptr(new RenderPassProgram(context_)); 1933 render_pass_program_ = make_scoped_ptr(new RenderPassProgram(context_));
1888 tile_program_ = make_scoped_ptr(new TileProgram(context_)); 1934 tile_program_ = make_scoped_ptr(new TileProgram(context_));
1889 tile_program_opaque_ = make_scoped_ptr(new TileProgramOpaque(context_)); 1935 tile_program_opaque_ = make_scoped_ptr(new TileProgramOpaque(context_));
1890 1936
1937 on_demand_tile_raster_texture_ = Context()->createTexture();
vmpstr 2013/03/13 21:03:08 Should this be cleaned up in CleanupSharedObjects?
Leandro Graciá Gil 2013/03/19 17:30:07 Yes. This was accidentally missed while rebasing o
1938 on_demand_tile_raster_resource_id_ =
1939 resource_provider_->CreateResourceFromExternalTexture(
1940 on_demand_tile_raster_texture_);
1941
1891 GLC(context_, context_->flush()); 1942 GLC(context_, context_->flush());
1892 1943
1893 return true; 1944 return true;
1894 } 1945 }
1895 1946
1896 const GLRenderer::TileCheckerboardProgram* 1947 const GLRenderer::TileCheckerboardProgram*
1897 GLRenderer::GetTileCheckerboardProgram() { 1948 GLRenderer::GetTileCheckerboardProgram() {
1898 if (!tile_checkerboard_program_) 1949 if (!tile_checkerboard_program_)
1899 tile_checkerboard_program_ = 1950 tile_checkerboard_program_ =
1900 make_scoped_ptr(new TileCheckerboardProgram(context_)); 1951 make_scoped_ptr(new TileCheckerboardProgram(context_));
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); 2173 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_));
2123 2174
2124 ReleaseRenderPassTextures(); 2175 ReleaseRenderPassTextures();
2125 } 2176 }
2126 2177
2127 bool GLRenderer::IsContextLost() { 2178 bool GLRenderer::IsContextLost() {
2128 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 2179 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
2129 } 2180 }
2130 2181
2131 } // namespace cc 2182 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698