Chromium Code Reviews| 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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 on_demand_tile_raster_resource_id_ = 0; | |
| 1309 } | |
| 1310 } | |
| 1311 | |
| 1312 SkDevice device(on_demand_tile_raster_bitmap_); | |
| 1313 SkCanvas canvas(&device); | |
| 1314 | |
| 1315 quad->picture_pile->Raster(&canvas, quad->content_rect, quad->contents_scale); | |
| 1316 | |
| 1317 if (!on_demand_tile_raster_resource_id_) { | |
| 1318 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( | |
| 1319 quad->texture_size, | |
| 1320 GL_RGBA, | |
| 1321 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | |
| 1322 ResourceProvider::TextureUsageAny); | |
|
piman
2013/03/26 17:19:30
nit: you could move this in the if block above, af
Leandro Graciá Gil
2013/03/26 18:05:02
Done.
| |
| 1323 } | |
| 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())); | |
|
piman
2013/03/26 17:19:30
You should be able to just use ResourceProvider::S
Leandro Graciá Gil
2013/03/26 18:05:02
We want this to happen synchronously for this spec
piman
2013/03/26 18:22:39
SetPixels is synchronous.
| |
| 1340 } | |
| 1341 | |
| 1342 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | |
| 1343 } | |
| 1344 | |
| 1285 struct TextureProgramBinding { | 1345 struct TextureProgramBinding { |
| 1286 template <class Program> | 1346 template <class Program> |
| 1287 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1347 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| 1288 DCHECK(program && (program->initialized() || context->isContextLost())); | 1348 DCHECK(program && (program->initialized() || context->isContextLost())); |
| 1289 program_id = program->program(); | 1349 program_id = program->program(); |
| 1290 sampler_location = program->fragment_shader().sampler_location(); | 1350 sampler_location = program->fragment_shader().sampler_location(); |
| 1291 matrix_location = program->vertex_shader().matrix_location(); | 1351 matrix_location = program->vertex_shader().matrix_location(); |
| 1292 alpha_location = program->fragment_shader().alpha_location(); | 1352 alpha_location = program->fragment_shader().alpha_location(); |
| 1293 } | 1353 } |
| 1294 int program_id; | 1354 int program_id; |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2221 if (debug_border_program_) | 2281 if (debug_border_program_) |
| 2222 debug_border_program_->Cleanup(context_); | 2282 debug_border_program_->Cleanup(context_); |
| 2223 if (solid_color_program_) | 2283 if (solid_color_program_) |
| 2224 solid_color_program_->Cleanup(context_); | 2284 solid_color_program_->Cleanup(context_); |
| 2225 if (solid_color_program_aa_) | 2285 if (solid_color_program_aa_) |
| 2226 solid_color_program_aa_->Cleanup(context_); | 2286 solid_color_program_aa_->Cleanup(context_); |
| 2227 | 2287 |
| 2228 if (offscreen_framebuffer_id_) | 2288 if (offscreen_framebuffer_id_) |
| 2229 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2289 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
| 2230 | 2290 |
| 2291 if (on_demand_tile_raster_resource_id_) | |
| 2292 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | |
| 2293 | |
| 2231 ReleaseRenderPassTextures(); | 2294 ReleaseRenderPassTextures(); |
| 2232 } | 2295 } |
| 2233 | 2296 |
| 2234 bool GLRenderer::IsContextLost() { | 2297 bool GLRenderer::IsContextLost() { |
| 2235 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2298 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2236 } | 2299 } |
| 2237 | 2300 |
| 2238 } // namespace cc | 2301 } // namespace cc |
| OLD | NEW |