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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 | 1035 |
1031 uniforms->sampler_location = program->fragment_shader().samplerLocation(); | 1036 uniforms->sampler_location = program->fragment_shader().samplerLocation(); |
1032 uniforms->alpha_location = program->fragment_shader().alphaLocation(); | 1037 uniforms->alpha_location = program->fragment_shader().alphaLocation(); |
1033 uniforms->fragment_tex_transform_location = | 1038 uniforms->fragment_tex_transform_location = |
1034 program->fragment_shader().fragmentTexTransformLocation(); | 1039 program->fragment_shader().fragmentTexTransformLocation(); |
1035 uniforms->edge_location = program->fragment_shader().edgeLocation(); | 1040 uniforms->edge_location = program->fragment_shader().edgeLocation(); |
1036 } | 1041 } |
1037 | 1042 |
1038 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, | 1043 void GLRenderer::DrawTileQuad(const DrawingFrame& frame, |
1039 const TileDrawQuad* quad) { | 1044 const TileDrawQuad* quad) { |
| 1045 DrawContentQuad(frame, quad, quad->resource_id); |
| 1046 } |
| 1047 |
| 1048 void GLRenderer::DrawContentQuad(const DrawingFrame& frame, |
| 1049 const ContentDrawQuadBase* quad, |
| 1050 ResourceProvider::ResourceId resource_id) { |
1040 gfx::Rect tile_rect = quad->visible_rect; | 1051 gfx::Rect tile_rect = quad->visible_rect; |
1041 | 1052 |
1042 gfx::RectF tex_coord_rect = quad->tex_coord_rect; | 1053 gfx::RectF tex_coord_rect = quad->tex_coord_rect; |
1043 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); | 1054 float tex_to_geom_scale_x = quad->rect.width() / tex_coord_rect.width(); |
1044 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); | 1055 float tex_to_geom_scale_y = quad->rect.height() / tex_coord_rect.height(); |
1045 | 1056 |
1046 // tex_coord_rect corresponds to quad_rect, but quad_visible_rect may be | 1057 // tex_coord_rect corresponds to quad_rect, but quad_visible_rect may be |
1047 // smaller than quad_rect due to occlusion or clipping. Adjust | 1058 // smaller than quad_rect due to occlusion or clipping. Adjust |
1048 // tex_coord_rect to match. | 1059 // tex_coord_rect to match. |
1049 gfx::Vector2d top_left_diff = tile_rect.origin() - quad->rect.origin(); | 1060 gfx::Vector2d top_left_diff = tile_rect.origin() - quad->rect.origin(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 } | 1129 } |
1119 | 1130 |
1120 SetUseProgram(uniforms.program); | 1131 SetUseProgram(uniforms.program); |
1121 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); | 1132 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); |
1122 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1133 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
1123 GLenum filter = (use_aa || scaled || | 1134 GLenum filter = (use_aa || scaled || |
1124 !quad->quadTransform().IsIdentityOrIntegerTranslation()) | 1135 !quad->quadTransform().IsIdentityOrIntegerTranslation()) |
1125 ? GL_LINEAR | 1136 ? GL_LINEAR |
1126 : GL_NEAREST; | 1137 : GL_NEAREST; |
1127 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1138 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
1128 resource_provider_, quad->resource_id, GL_TEXTURE_2D, filter); | 1139 resource_provider_, resource_id, GL_TEXTURE_2D, filter); |
1129 | 1140 |
1130 if (use_aa) { | 1141 if (use_aa) { |
1131 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); | 1142 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); |
1132 | 1143 |
1133 GLC(Context(), | 1144 GLC(Context(), |
1134 Context()->uniform4f(uniforms.vertex_tex_transform_location, | 1145 Context()->uniform4f(uniforms.vertex_tex_transform_location, |
1135 vertex_tex_translate_x, | 1146 vertex_tex_translate_x, |
1136 vertex_tex_translate_y, | 1147 vertex_tex_translate_y, |
1137 vertex_tex_scale_x, | 1148 vertex_tex_scale_x, |
1138 vertex_tex_scale_y)); | 1149 vertex_tex_scale_y)); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 GLC(Context(), | 1283 GLC(Context(), |
1273 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); | 1284 Context()->uniform1i(program->fragment_shader().samplerLocation(), 0)); |
1274 | 1285 |
1275 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); | 1286 SetShaderOpacity(quad->opacity(), program->fragment_shader().alphaLocation()); |
1276 DrawQuadGeometry(frame, | 1287 DrawQuadGeometry(frame, |
1277 quad->quadTransform(), | 1288 quad->quadTransform(), |
1278 quad->rect, | 1289 quad->rect, |
1279 program->vertex_shader().matrixLocation()); | 1290 program->vertex_shader().matrixLocation()); |
1280 } | 1291 } |
1281 | 1292 |
| 1293 void GLRenderer::DrawPictureQuad(const DrawingFrame& frame, |
| 1294 const PictureDrawQuad* quad) { |
| 1295 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || |
| 1296 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { |
| 1297 on_demand_tile_raster_bitmap_.setConfig( |
| 1298 SkBitmap::kARGB_8888_Config, |
| 1299 quad->texture_size.width(), |
| 1300 quad->texture_size.height()); |
| 1301 on_demand_tile_raster_bitmap_.allocPixels(); |
| 1302 } |
| 1303 |
| 1304 SkDevice device(on_demand_tile_raster_bitmap_); |
| 1305 SkCanvas canvas(&device); |
| 1306 |
| 1307 int64 total_pixels_rasterized = 0; |
| 1308 quad->picture_pile->Raster( |
| 1309 &canvas, |
| 1310 quad->content_rect, |
| 1311 quad->contents_scale, |
| 1312 &total_pixels_rasterized); |
| 1313 |
| 1314 if (!on_demand_tile_raster_resource_id_) { |
| 1315 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( |
| 1316 quad->texture_size, |
| 1317 GL_RGBA, |
| 1318 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 1319 ResourceProvider::TextureUsageAny); |
| 1320 } |
| 1321 |
| 1322 resource_provider_->ResizeResource(on_demand_tile_raster_resource_id_, |
| 1323 quad->texture_size); |
| 1324 |
| 1325 { |
| 1326 ResourceProvider::ScopedWriteLockGL lock( |
| 1327 resource_provider_, |
| 1328 on_demand_tile_raster_resource_id_); |
| 1329 |
| 1330 GLC(Context(), Context()->texImage2D( |
| 1331 GL_TEXTURE_2D, |
| 1332 0, |
| 1333 GL_RGBA, |
| 1334 quad->texture_size.width(), |
| 1335 quad->texture_size.height(), |
| 1336 0, |
| 1337 GL_RGBA, |
| 1338 GL_UNSIGNED_BYTE, |
| 1339 on_demand_tile_raster_bitmap_.getPixels())); |
| 1340 } |
| 1341 |
| 1342 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
| 1343 } |
| 1344 |
1282 struct TextureProgramBinding { | 1345 struct TextureProgramBinding { |
1283 template <class Program> | 1346 template <class Program> |
1284 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1347 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
1285 DCHECK(program && (program->initialized() || context->isContextLost())); | 1348 DCHECK(program && (program->initialized() || context->isContextLost())); |
1286 program_id = program->program(); | 1349 program_id = program->program(); |
1287 sampler_location = program->fragment_shader().samplerLocation(); | 1350 sampler_location = program->fragment_shader().samplerLocation(); |
1288 matrix_location = program->vertex_shader().matrixLocation(); | 1351 matrix_location = program->vertex_shader().matrixLocation(); |
1289 alpha_location = program->fragment_shader().alphaLocation(); | 1352 alpha_location = program->fragment_shader().alphaLocation(); |
1290 } | 1353 } |
1291 int program_id; | 1354 int program_id; |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2217 if (debug_border_program_) | 2280 if (debug_border_program_) |
2218 debug_border_program_->Cleanup(context_); | 2281 debug_border_program_->Cleanup(context_); |
2219 if (solid_color_program_) | 2282 if (solid_color_program_) |
2220 solid_color_program_->Cleanup(context_); | 2283 solid_color_program_->Cleanup(context_); |
2221 if (solid_color_program_aa_) | 2284 if (solid_color_program_aa_) |
2222 solid_color_program_aa_->Cleanup(context_); | 2285 solid_color_program_aa_->Cleanup(context_); |
2223 | 2286 |
2224 if (offscreen_framebuffer_id_) | 2287 if (offscreen_framebuffer_id_) |
2225 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2288 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
2226 | 2289 |
| 2290 if (on_demand_tile_raster_resource_id_) |
| 2291 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| 2292 |
2227 ReleaseRenderPassTextures(); | 2293 ReleaseRenderPassTextures(); |
2228 } | 2294 } |
2229 | 2295 |
2230 bool GLRenderer::IsContextLost() { | 2296 bool GLRenderer::IsContextLost() { |
2231 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2297 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
2232 } | 2298 } |
2233 | 2299 |
2234 } // namespace cc | 2300 } // namespace cc |
OLD | NEW |