OLD | NEW |
---|---|
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 break; | 297 break; |
295 case DrawQuad::CHECKERBOARD: | 298 case DrawQuad::CHECKERBOARD: |
296 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); | 299 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); |
297 break; | 300 break; |
298 case DrawQuad::DEBUG_BORDER: | 301 case DrawQuad::DEBUG_BORDER: |
299 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 302 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
300 break; | 303 break; |
301 case DrawQuad::IO_SURFACE_CONTENT: | 304 case DrawQuad::IO_SURFACE_CONTENT: |
302 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); | 305 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); |
303 break; | 306 break; |
307 case DrawQuad::PICTURE_CONTENT: | |
308 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad)); | |
309 break; | |
304 case DrawQuad::RENDER_PASS: | 310 case DrawQuad::RENDER_PASS: |
305 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); | 311 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); |
306 break; | 312 break; |
307 case DrawQuad::SOLID_COLOR: | 313 case DrawQuad::SOLID_COLOR: |
308 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); | 314 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); |
309 break; | 315 break; |
310 case DrawQuad::STREAM_VIDEO_CONTENT: | 316 case DrawQuad::STREAM_VIDEO_CONTENT: |
311 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); | 317 DrawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); |
312 break; | 318 break; |
313 case DrawQuad::TEXTURE_CONTENT: | 319 case DrawQuad::TEXTURE_CONTENT: |
314 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); | 320 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); |
315 break; | 321 break; |
316 case DrawQuad::TILED_CONTENT: | 322 case DrawQuad::TILED_CONTENT: { |
317 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); | 323 const TileDrawQuad* tile_draw_quad = TileDrawQuad::MaterialCast(quad); |
324 DrawTileQuad(frame, tile_draw_quad, tile_draw_quad->resource_id); | |
318 break; | 325 break; |
326 } | |
319 case DrawQuad::YUV_VIDEO_CONTENT: | 327 case DrawQuad::YUV_VIDEO_CONTENT: |
320 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); | 328 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); |
321 break; | 329 break; |
322 } | 330 } |
323 } | 331 } |
324 | 332 |
325 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame& frame, | 333 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame& frame, |
326 const CheckerboardDrawQuad* quad) { | 334 const CheckerboardDrawQuad* quad) { |
327 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 335 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
328 | 336 |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 uniforms->matrix_location = program->vertex_shader().matrixLocation(); | 1034 uniforms->matrix_location = program->vertex_shader().matrixLocation(); |
1027 uniforms->point_location = program->vertex_shader().pointLocation(); | 1035 uniforms->point_location = program->vertex_shader().pointLocation(); |
1028 | 1036 |
1029 uniforms->sampler_location = program->fragment_shader().samplerLocation(); | 1037 uniforms->sampler_location = program->fragment_shader().samplerLocation(); |
1030 uniforms->alpha_location = program->fragment_shader().alphaLocation(); | 1038 uniforms->alpha_location = program->fragment_shader().alphaLocation(); |
1031 uniforms->fragment_tex_transform_location = | 1039 uniforms->fragment_tex_transform_location = |
1032 program->fragment_shader().fragmentTexTransformLocation(); | 1040 program->fragment_shader().fragmentTexTransformLocation(); |
1033 uniforms->edge_location = program->fragment_shader().edgeLocation(); | 1041 uniforms->edge_location = program->fragment_shader().edgeLocation(); |
1034 } | 1042 } |
1035 | 1043 |
1036 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, | 1044 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, |
danakj
2013/03/21 02:34:42
nit: Can you call this function DrawTileOrPictureQ
Leandro Graciá Gil
2013/03/21 16:42:48
Done.
| |
1037 const TileDrawQuad* quad) { | 1045 const TileDrawQuadBase* quad, |
1046 unsigned resource_id) { | |
1038 gfx::Rect tile_rect = quad->visible_rect; | 1047 gfx::Rect tile_rect = quad->visible_rect; |
1039 | 1048 |
1040 gfx::RectF tex_coord_rect = quad->tex_coord_rect; | 1049 gfx::RectF tex_coord_rect = quad->tex_coord_rect; |
1041 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); | 1050 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); |
1042 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); | 1051 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); |
1043 | 1052 |
1044 // tex_coord_rect corresponds to quad_rect, but quad_visible_rect may be | 1053 // tex_coord_rect corresponds to quad_rect, but quad_visible_rect may be |
1045 // smaller than quad_rect due to occlusion or clipping. Adjust | 1054 // smaller than quad_rect due to occlusion or clipping. Adjust |
1046 // tex_coord_rect to match. | 1055 // tex_coord_rect to match. |
1047 gfx::Vector2d top_left_diff = tile_rect.origin() - quad->rect.origin(); | 1056 gfx::Vector2d top_left_diff = tile_rect.origin() - quad->rect.origin(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 } | 1125 } |
1117 | 1126 |
1118 SetUseProgram(uniforms.program); | 1127 SetUseProgram(uniforms.program); |
1119 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); | 1128 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); |
1120 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1129 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
1121 GLenum filter = (use_aa || scaled || | 1130 GLenum filter = (use_aa || scaled || |
1122 !quad->quadTransform().IsIdentityOrIntegerTranslation()) | 1131 !quad->quadTransform().IsIdentityOrIntegerTranslation()) |
1123 ? GL_LINEAR | 1132 ? GL_LINEAR |
1124 : GL_NEAREST; | 1133 : GL_NEAREST; |
1125 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1134 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
1126 resource_provider_, quad->resource_id, GL_TEXTURE_2D, filter); | 1135 resource_provider_, resource_id, GL_TEXTURE_2D, filter); |
1127 | 1136 |
1128 if (use_aa) { | 1137 if (use_aa) { |
1129 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); | 1138 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); |
1130 | 1139 |
1131 GLC(Context(), | 1140 GLC(Context(), |
1132 Context()->uniform4f(uniforms.vertex_tex_transform_location, | 1141 Context()->uniform4f(uniforms.vertex_tex_transform_location, |
1133 vertex_tex_translate_x, | 1142 vertex_tex_translate_x, |
1134 vertex_tex_translate_y, | 1143 vertex_tex_translate_y, |
1135 vertex_tex_scale_x, | 1144 vertex_tex_scale_x, |
1136 vertex_tex_scale_y)); | 1145 vertex_tex_scale_y)); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1270 GLC(Context(), | 1279 GLC(Context(), |
1271 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 1280 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); |
1272 | 1281 |
1273 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); | 1282 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); |
1274 DrawQuadGeometry(frame, | 1283 DrawQuadGeometry(frame, |
1275 quad->quadTransform(), | 1284 quad->quadTransform(), |
1276 quad->rect, | 1285 quad->rect, |
1277 program->vertex_shader().matrixLocation()); | 1286 program->vertex_shader().matrixLocation()); |
1278 } | 1287 } |
1279 | 1288 |
1289 void GLRenderer::DrawPictureQuad(const DrawingFrame& frame, const PictureDrawQua d* quad) { | |
1290 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || | |
1291 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { | |
1292 on_demand_tile_raster_bitmap_.setConfig( | |
1293 SkBitmap::kARGB_8888_Config, | |
1294 quad->texture_size.width(), | |
1295 quad->texture_size.height()); | |
1296 on_demand_tile_raster_bitmap_.allocPixels(); | |
1297 } | |
1298 | |
1299 SkDevice device(on_demand_tile_raster_bitmap_); | |
1300 SkCanvas canvas(&device); | |
1301 | |
1302 int64 total_pixels_rasterized = 0; | |
1303 quad->picture_pile->Raster( | |
1304 &canvas, | |
1305 quad->content_rect, | |
1306 quad->contents_scale, | |
1307 &total_pixels_rasterized); | |
1308 | |
1309 GLC(Context(), Context()->bindTexture( | |
1310 GL_TEXTURE_2D, | |
1311 on_demand_tile_raster_texture_)); | |
1312 | |
1313 GLC(Context(), Context()->texImage2D( | |
1314 GL_TEXTURE_2D, | |
1315 0, | |
1316 GL_RGBA, | |
1317 quad->texture_size.width(), | |
1318 quad->texture_size.height(), | |
1319 0, | |
1320 GL_RGBA, | |
1321 GL_UNSIGNED_BYTE, | |
1322 on_demand_tile_raster_bitmap_.getPixels())); | |
1323 | |
1324 DrawTileQuad(frame, quad, on_demand_tile_raster_resource_id_); | |
1325 } | |
1326 | |
1280 struct TextureProgramBinding { | 1327 struct TextureProgramBinding { |
1281 template <class Program> | 1328 template <class Program> |
1282 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1329 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
1283 DCHECK(program && (program->initialized() || context->isContextLost())); | 1330 DCHECK(program && (program->initialized() || context->isContextLost())); |
1284 program_id = program->program(); | 1331 program_id = program->program(); |
1285 sampler_location = program->fragment_shader().samplerLocation(); | 1332 sampler_location = program->fragment_shader().samplerLocation(); |
1286 matrix_location = program->vertex_shader().matrixLocation(); | 1333 matrix_location = program->vertex_shader().matrixLocation(); |
1287 alpha_location = program->fragment_shader().alphaLocation(); | 1334 alpha_location = program->fragment_shader().alphaLocation(); |
1288 } | 1335 } |
1289 int program_id; | 1336 int program_id; |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1953 | 2000 |
1954 // We will always need these programs to render, so create the programs | 2001 // We will always need these programs to render, so create the programs |
1955 // eagerly so that the shader compilation can start while we do other work. | 2002 // eagerly so that the shader compilation can start while we do other work. |
1956 // Other programs are created lazily on first access. | 2003 // Other programs are created lazily on first access. |
1957 shared_geometry_ = | 2004 shared_geometry_ = |
1958 make_scoped_ptr(new GeometryBinding(context_, QuadVertexRect())); | 2005 make_scoped_ptr(new GeometryBinding(context_, QuadVertexRect())); |
1959 render_pass_program_ = make_scoped_ptr(new RenderPassProgram(context_)); | 2006 render_pass_program_ = make_scoped_ptr(new RenderPassProgram(context_)); |
1960 tile_program_ = make_scoped_ptr(new TileProgram(context_)); | 2007 tile_program_ = make_scoped_ptr(new TileProgram(context_)); |
1961 tile_program_opaque_ = make_scoped_ptr(new TileProgramOpaque(context_)); | 2008 tile_program_opaque_ = make_scoped_ptr(new TileProgramOpaque(context_)); |
1962 | 2009 |
2010 on_demand_tile_raster_texture_ = Context()->createTexture(); | |
danakj
2013/03/21 02:34:42
Can you do this in DrawPictureQuad() the first tim
Leandro Graciá Gil
2013/03/21 16:42:48
Done.
| |
2011 on_demand_tile_raster_resource_id_ = | |
2012 resource_provider_->CreateResourceFromExternalTexture( | |
2013 on_demand_tile_raster_texture_); | |
2014 | |
1963 GLC(context_, context_->flush()); | 2015 GLC(context_, context_->flush()); |
1964 | 2016 |
1965 return true; | 2017 return true; |
1966 } | 2018 } |
1967 | 2019 |
1968 const GLRenderer::TileCheckerboardProgram* | 2020 const GLRenderer::TileCheckerboardProgram* |
1969 GLRenderer::GetTileCheckerboardProgram() { | 2021 GLRenderer::GetTileCheckerboardProgram() { |
1970 if (!tile_checkerboard_program_) { | 2022 if (!tile_checkerboard_program_) { |
1971 tile_checkerboard_program_ = | 2023 tile_checkerboard_program_ = |
1972 make_scoped_ptr(new TileCheckerboardProgram(context_)); | 2024 make_scoped_ptr(new TileCheckerboardProgram(context_)); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2215 if (debug_border_program_) | 2267 if (debug_border_program_) |
2216 debug_border_program_->Cleanup(context_); | 2268 debug_border_program_->Cleanup(context_); |
2217 if (solid_color_program_) | 2269 if (solid_color_program_) |
2218 solid_color_program_->Cleanup(context_); | 2270 solid_color_program_->Cleanup(context_); |
2219 if (solid_color_program_aa_) | 2271 if (solid_color_program_aa_) |
2220 solid_color_program_aa_->Cleanup(context_); | 2272 solid_color_program_aa_->Cleanup(context_); |
2221 | 2273 |
2222 if (offscreen_framebuffer_id_) | 2274 if (offscreen_framebuffer_id_) |
2223 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2275 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
2224 | 2276 |
2277 if (on_demand_tile_raster_texture_) | |
2278 GLC(context_, context_->deleteTexture(on_demand_tile_raster_texture_)); | |
danakj
2013/03/21 02:34:42
You need to clean up with the ResourceProvider too
Leandro Graciá Gil
2013/03/21 03:35:50
Can I use ResourceProvider to clean external textu
danakj
2013/03/21 04:33:39
ya, there's actually no need for this to be an ext
Leandro Graciá Gil
2013/03/21 16:42:48
Looking at ResourceProvider it seems that doing it
danakj
2013/03/21 17:20:22
I talked to piman@ and he suggested to just not re
Leandro Graciá Gil
2013/03/21 18:14:16
Registering as an external texture makes things si
piman
2013/03/21 18:26:30
I want to get rid of the non-mailbox external text
| |
2279 | |
2225 ReleaseRenderPassTextures(); | 2280 ReleaseRenderPassTextures(); |
2226 } | 2281 } |
2227 | 2282 |
2228 bool GLRenderer::IsContextLost() { | 2283 bool GLRenderer::IsContextLost() { |
2229 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2284 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
2230 } | 2285 } |
2231 | 2286 |
2232 } // namespace cc | 2287 } // namespace cc |
OLD | NEW |