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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "cc/trees/damage_tracker.h" | 33 #include "cc/trees/damage_tracker.h" |
| 34 #include "cc/trees/proxy.h" | 34 #include "cc/trees/proxy.h" |
| 35 #include "cc/trees/single_thread_proxy.h" | 35 #include "cc/trees/single_thread_proxy.h" |
| 36 #include "gpu/GLES2/gl2extchromium.h" | 36 #include "gpu/GLES2/gl2extchromium.h" |
| 37 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 37 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| 38 #include "third_party/khronos/GLES2/gl2.h" | 38 #include "third_party/khronos/GLES2/gl2.h" |
| 39 #include "third_party/khronos/GLES2/gl2ext.h" | 39 #include "third_party/khronos/GLES2/gl2ext.h" |
| 40 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
| 41 #include "third_party/skia/include/core/SkColor.h" | 41 #include "third_party/skia/include/core/SkColor.h" |
| 42 #include "third_party/skia/include/core/SkColorFilter.h" | 42 #include "third_party/skia/include/core/SkColorFilter.h" |
| 43 #include "third_party/skia/include/core/SkSurface.h" | |
| 43 #include "third_party/skia/include/gpu/GrContext.h" | 44 #include "third_party/skia/include/gpu/GrContext.h" |
| 44 #include "third_party/skia/include/gpu/GrTexture.h" | 45 #include "third_party/skia/include/gpu/GrTexture.h" |
| 45 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 46 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 46 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" | 47 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" |
| 47 #include "ui/gfx/quad_f.h" | 48 #include "ui/gfx/quad_f.h" |
| 48 #include "ui/gfx/rect_conversions.h" | 49 #include "ui/gfx/rect_conversions.h" |
| 49 | 50 |
| 50 using WebKit::WebGraphicsContext3D; | 51 using WebKit::WebGraphicsContext3D; |
| 51 using WebKit::WebGraphicsMemoryAllocation; | 52 using WebKit::WebGraphicsMemoryAllocation; |
| 52 | 53 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 74 bool NeedsIOSurfaceReadbackWorkaround() { | 75 bool NeedsIOSurfaceReadbackWorkaround() { |
| 75 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
| 76 // This isn't strictly required in DumpRenderTree-mode when Mesa is used, | 77 // This isn't strictly required in DumpRenderTree-mode when Mesa is used, |
| 77 // but it doesn't seem to hurt. | 78 // but it doesn't seem to hurt. |
| 78 return true; | 79 return true; |
| 79 #else | 80 #else |
| 80 return false; | 81 return false; |
| 81 #endif | 82 #endif |
| 82 } | 83 } |
| 83 | 84 |
| 85 // TODO(enne): move this to SkUtils | |
| 86 void ToSkMatrix(SkMatrix* flattened, const gfx::Transform& m) { | |
| 87 // Convert from 4x4 to 3x3 by dropping the third row and column. | |
| 88 flattened->set(0, SkDoubleToScalar(m.matrix().getDouble(0, 0))); | |
| 89 flattened->set(1, SkDoubleToScalar(m.matrix().getDouble(0, 1))); | |
| 90 flattened->set(2, SkDoubleToScalar(m.matrix().getDouble(0, 3))); | |
| 91 flattened->set(3, SkDoubleToScalar(m.matrix().getDouble(1, 0))); | |
| 92 flattened->set(4, SkDoubleToScalar(m.matrix().getDouble(1, 1))); | |
| 93 flattened->set(5, SkDoubleToScalar(m.matrix().getDouble(1, 3))); | |
| 94 flattened->set(6, SkDoubleToScalar(m.matrix().getDouble(3, 0))); | |
| 95 flattened->set(7, SkDoubleToScalar(m.matrix().getDouble(3, 1))); | |
| 96 flattened->set(8, SkDoubleToScalar(m.matrix().getDouble(3, 3))); | |
| 97 } | |
| 98 | |
| 84 } // anonymous namespace | 99 } // anonymous namespace |
| 85 | 100 |
| 86 scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client, | 101 scoped_ptr<GLRenderer> GLRenderer::Create(RendererClient* client, |
| 87 OutputSurface* output_surface, | 102 OutputSurface* output_surface, |
| 88 ResourceProvider* resource_provider, | 103 ResourceProvider* resource_provider, |
| 89 int highp_threshold_min) { | 104 int highp_threshold_min) { |
| 90 scoped_ptr<GLRenderer> renderer(new GLRenderer( | 105 scoped_ptr<GLRenderer> renderer(new GLRenderer( |
| 91 client, output_surface, resource_provider, highp_threshold_min)); | 106 client, output_surface, resource_provider, highp_threshold_min)); |
| 92 if (!renderer->Initialize()) | 107 if (!renderer->Initialize()) |
| 93 return scoped_ptr<GLRenderer>(); | 108 return scoped_ptr<GLRenderer>(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 106 context_(output_surface->context3d()), | 121 context_(output_surface->context3d()), |
| 107 is_viewport_changed_(false), | 122 is_viewport_changed_(false), |
| 108 is_backbuffer_discarded_(false), | 123 is_backbuffer_discarded_(false), |
| 109 discard_backbuffer_when_not_visible_(false), | 124 discard_backbuffer_when_not_visible_(false), |
| 110 is_using_bind_uniform_(false), | 125 is_using_bind_uniform_(false), |
| 111 visible_(true), | 126 visible_(true), |
| 112 is_scissor_enabled_(false), | 127 is_scissor_enabled_(false), |
| 113 highp_threshold_min_(highp_threshold_min), | 128 highp_threshold_min_(highp_threshold_min), |
| 114 on_demand_tile_raster_resource_id_(0) { | 129 on_demand_tile_raster_resource_id_(0) { |
| 115 DCHECK(context_); | 130 DCHECK(context_); |
| 131 | |
| 132 gr_context_.reset( | |
| 133 new webkit::gpu::GrContextForWebGraphicsContext3D(context_)); | |
| 134 | |
| 135 ReinitializeGrContext(); | |
| 116 } | 136 } |
| 117 | 137 |
| 118 bool GLRenderer::Initialize() { | 138 bool GLRenderer::Initialize() { |
| 119 if (!context_->makeContextCurrent()) | 139 if (!context_->makeContextCurrent()) |
| 120 return false; | 140 return false; |
| 121 | 141 |
| 122 context_->pushGroupMarkerEXT("CompositorContext"); | 142 context_->pushGroupMarkerEXT("CompositorContext"); |
| 123 | 143 |
| 124 std::string extensions_string = | 144 std::string extensions_string = |
| 125 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); | 145 UTF16ToASCII(context_->getString(GL_EXTENSIONS)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 // Check for texture fast paths. Currently we always use MO8 textures, | 188 // Check for texture fast paths. Currently we always use MO8 textures, |
| 169 // so we only need to avoid POT textures if we have an NPOT fast-path. | 189 // so we only need to avoid POT textures if we have an NPOT fast-path. |
| 170 capabilities_.avoid_pow2_textures = | 190 capabilities_.avoid_pow2_textures = |
| 171 extensions.count("GL_CHROMIUM_fast_NPOT_MO8_textures") > 0; | 191 extensions.count("GL_CHROMIUM_fast_NPOT_MO8_textures") > 0; |
| 172 | 192 |
| 173 capabilities_.using_offscreen_context3d = true; | 193 capabilities_.using_offscreen_context3d = true; |
| 174 | 194 |
| 175 is_using_bind_uniform_ = | 195 is_using_bind_uniform_ = |
| 176 extensions.count("GL_CHROMIUM_bind_uniform_location") > 0; | 196 extensions.count("GL_CHROMIUM_bind_uniform_location") > 0; |
| 177 | 197 |
| 178 // Make sure scissoring starts as disabled. | |
| 179 GLC(context_, context_->disable(GL_SCISSOR_TEST)); | |
| 180 DCHECK(!is_scissor_enabled_); | |
| 181 | |
| 182 if (!InitializeSharedObjects()) | 198 if (!InitializeSharedObjects()) |
| 183 return false; | 199 return false; |
| 184 | 200 |
| 185 // Make sure the viewport and context gets initialized, even if it is to zero. | 201 // Make sure the viewport and context gets initialized, even if it is to zero. |
| 186 ViewportChanged(); | 202 ViewportChanged(); |
| 187 return true; | 203 return true; |
| 188 } | 204 } |
| 189 | 205 |
| 190 GLRenderer::~GLRenderer() { | 206 GLRenderer::~GLRenderer() { |
| 191 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); | 207 context_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 WebKit::WebGraphicsManagedMemoryStats stats; | 245 WebKit::WebGraphicsManagedMemoryStats stats; |
| 230 stats.bytesVisible = bytes_visible; | 246 stats.bytesVisible = bytes_visible; |
| 231 stats.bytesVisibleAndNearby = bytes_visible_and_nearby; | 247 stats.bytesVisibleAndNearby = bytes_visible_and_nearby; |
| 232 stats.bytesAllocated = bytes_allocated; | 248 stats.bytesAllocated = bytes_allocated; |
| 233 stats.backbufferRequested = !is_backbuffer_discarded_; | 249 stats.backbufferRequested = !is_backbuffer_discarded_; |
| 234 context_->sendManagedMemoryStatsCHROMIUM(&stats); | 250 context_->sendManagedMemoryStatsCHROMIUM(&stats); |
| 235 } | 251 } |
| 236 | 252 |
| 237 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } | 253 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } |
| 238 | 254 |
| 239 void GLRenderer::ViewportChanged() { is_viewport_changed_ = true; } | 255 void GLRenderer::ViewportChanged() { |
| 256 is_viewport_changed_ = true; | |
| 257 ReinitializeGrContext(); | |
| 258 } | |
| 240 | 259 |
| 241 void GLRenderer::ClearFramebuffer(DrawingFrame* frame) { | 260 void GLRenderer::ClearFramebuffer(DrawingFrame* frame) { |
| 242 // On DEBUG builds, opaque render passes are cleared to blue to easily see | 261 // On DEBUG builds, opaque render passes are cleared to blue to easily see |
| 243 // regions that were not drawn on the screen. | 262 // regions that were not drawn on the screen. |
| 244 if (frame->current_render_pass->has_transparent_background) | 263 if (frame->current_render_pass->has_transparent_background) |
| 245 GLC(context_, context_->clearColor(0, 0, 0, 0)); | 264 GLC(context_, context_->clearColor(0, 0, 0, 0)); |
| 246 else | 265 else |
| 247 GLC(context_, context_->clearColor(0, 0, 1, 1)); | 266 GLC(context_, context_->clearColor(0, 0, 1, 1)); |
| 248 | 267 |
| 249 #ifdef NDEBUG | 268 #ifdef NDEBUG |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 262 TRACE_EVENT0("cc", "GLRenderer::DrawLayers"); | 281 TRACE_EVENT0("cc", "GLRenderer::DrawLayers"); |
| 263 if (is_viewport_changed_) { | 282 if (is_viewport_changed_) { |
| 264 // Only reshape when we know we are going to draw. Otherwise, the reshape | 283 // Only reshape when we know we are going to draw. Otherwise, the reshape |
| 265 // can leave the window at the wrong size if we never draw and the proper | 284 // can leave the window at the wrong size if we never draw and the proper |
| 266 // viewport size is never set. | 285 // viewport size is never set. |
| 267 is_viewport_changed_ = false; | 286 is_viewport_changed_ = false; |
| 268 output_surface_->Reshape(gfx::Size(ViewportWidth(), ViewportHeight())); | 287 output_surface_->Reshape(gfx::Size(ViewportWidth(), ViewportHeight())); |
| 269 } | 288 } |
| 270 | 289 |
| 271 MakeContextCurrent(); | 290 MakeContextCurrent(); |
| 272 // Bind the common vertex attributes used for drawing all the layers. | |
| 273 shared_geometry_->PrepareForDraw(); | |
| 274 | 291 |
| 275 GLC(context_, context_->disable(GL_DEPTH_TEST)); | 292 ReinitializeGLState(); |
| 276 GLC(context_, context_->disable(GL_CULL_FACE)); | |
| 277 GLC(context_, context_->colorMask(true, true, true, true)); | |
| 278 GLC(context_, context_->enable(GL_BLEND)); | |
| 279 blend_shadow_ = true; | |
| 280 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | |
| 281 GLC(Context(), Context()->activeTexture(GL_TEXTURE0)); | |
| 282 program_shadow_ = 0; | |
| 283 } | 293 } |
| 284 | 294 |
| 285 void GLRenderer::DoNoOp() { | 295 void GLRenderer::DoNoOp() { |
| 286 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 296 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
| 287 GLC(context_, context_->flush()); | 297 GLC(context_, context_->flush()); |
| 288 } | 298 } |
| 289 | 299 |
| 290 void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { | 300 void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { |
| 291 DCHECK(quad->rect.Contains(quad->visible_rect)); | 301 DCHECK(quad->rect.Contains(quad->visible_rect)); |
| 292 if (quad->material != DrawQuad::TEXTURE_CONTENT) { | 302 if (quad->material != DrawQuad::TEXTURE_CONTENT) { |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1424 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | 1434 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1425 | 1435 |
| 1426 SetShaderOpacity(quad->opacity(), | 1436 SetShaderOpacity(quad->opacity(), |
| 1427 program->fragment_shader().alpha_location()); | 1437 program->fragment_shader().alpha_location()); |
| 1428 DrawQuadGeometry(frame, | 1438 DrawQuadGeometry(frame, |
| 1429 quad->quadTransform(), | 1439 quad->quadTransform(), |
| 1430 quad->rect, | 1440 quad->rect, |
| 1431 program->vertex_shader().matrix_location()); | 1441 program->vertex_shader().matrix_location()); |
| 1432 } | 1442 } |
| 1433 | 1443 |
| 1444 void GLRenderer::DrawPictureQuadDirectToBackbuffer( | |
| 1445 const DrawingFrame* frame, | |
| 1446 const PictureDrawQuad* quad) { | |
| 1447 // TODO(enne): Only do this if we've set some state since the last time | |
| 1448 // Ganesh drew anything. | |
| 1449 gr_context_->get()->resetContext(); | |
| 1450 | |
| 1451 if (is_scissor_enabled_) { | |
| 1452 sk_canvas_->clipRect(gfx::RectToSkRect(scissor_rect_), | |
| 1453 SkRegion::kReplace_Op); | |
| 1454 } else { | |
| 1455 sk_canvas_->clipRect(gfx::RectToSkRect(gfx::Rect(ViewportSize())), | |
| 1456 SkRegion::kReplace_Op); | |
| 1457 } | |
| 1458 | |
| 1459 gfx::Transform y_flip; | |
| 1460 y_flip.Scale3d(1.0, -1.0, 1.0); | |
| 1461 | |
| 1462 gfx::Transform contents_device_transform = frame->window_matrix * y_flip * | |
| 1463 frame->projection_matrix * quad->quadTransform(); | |
| 1464 contents_device_transform.FlattenTo2d(); | |
| 1465 SkMatrix sk_device_matrix; | |
| 1466 ToSkMatrix(&sk_device_matrix, contents_device_transform); | |
| 1467 sk_canvas_->setMatrix(sk_device_matrix); | |
| 1468 | |
| 1469 quad->picture_pile->Raster(sk_canvas_.get(), | |
| 1470 quad->content_rect, | |
| 1471 quad->contents_scale); | |
| 1472 | |
| 1473 ReinitializeGLState(); | |
| 1474 output_surface_->BindFramebuffer(); | |
| 1475 } | |
| 1476 | |
| 1434 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, | 1477 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, |
| 1435 const PictureDrawQuad* quad) { | 1478 const PictureDrawQuad* quad) { |
| 1479 if (quad->draw_direct_to_backbuffer) { | |
| 1480 DrawPictureQuadDirectToBackbuffer(frame, quad); | |
| 1481 return; | |
| 1482 } | |
| 1483 | |
| 1436 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || | 1484 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || |
| 1437 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { | 1485 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { |
| 1438 on_demand_tile_raster_bitmap_.setConfig( | 1486 on_demand_tile_raster_bitmap_.setConfig( |
| 1439 SkBitmap::kARGB_8888_Config, | 1487 SkBitmap::kARGB_8888_Config, |
| 1440 quad->texture_size.width(), | 1488 quad->texture_size.width(), |
| 1441 quad->texture_size.height()); | 1489 quad->texture_size.height()); |
| 1442 on_demand_tile_raster_bitmap_.allocPixels(); | 1490 on_demand_tile_raster_bitmap_.allocPixels(); |
| 1443 | 1491 |
| 1444 if (on_demand_tile_raster_resource_id_) | 1492 if (on_demand_tile_raster_resource_id_) |
| 1445 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 1493 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2566 | 2614 |
| 2567 if (offscreen_framebuffer_id_) | 2615 if (offscreen_framebuffer_id_) |
| 2568 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2616 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); |
| 2569 | 2617 |
| 2570 if (on_demand_tile_raster_resource_id_) | 2618 if (on_demand_tile_raster_resource_id_) |
| 2571 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 2619 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| 2572 | 2620 |
| 2573 ReleaseRenderPassTextures(); | 2621 ReleaseRenderPassTextures(); |
| 2574 } | 2622 } |
| 2575 | 2623 |
| 2624 void GLRenderer::ReinitializeGrContext() { | |
| 2625 GrBackendRenderTargetDesc desc; | |
| 2626 desc.fWidth = ViewportWidth(); | |
| 2627 desc.fHeight = ViewportHeight(); | |
| 2628 desc.fConfig = kRGBA_8888_GrPixelConfig; | |
| 2629 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
| 2630 desc.fSampleCnt = 1; | |
| 2631 desc.fStencilBits = 0; | |
| 2632 desc.fRenderTargetHandle = 0; | |
| 2633 | |
| 2634 SkAutoTUnref<GrSurface> surface( | |
| 2635 gr_context_->get()->wrapBackendRenderTarget(desc)); | |
| 2636 SkAutoTUnref<SkDevice> device(SkGpuDevice::Create(surface)); | |
| 2637 sk_canvas_.reset(new SkCanvas(device.get())); | |
| 2638 } | |
| 2639 | |
| 2640 void GLRenderer::ReinitializeGLState() { | |
|
enne (OOO)
2013/04/24 22:49:53
This patch is clearly missing something here in th
| |
| 2641 // Bind the common vertex attributes used for drawing all the layers. | |
| 2642 shared_geometry_->PrepareForDraw(); | |
| 2643 | |
| 2644 GLC(context_, context_->disable(GL_STENCIL_TEST)); | |
| 2645 GLC(context_, context_->disable(GL_DEPTH_TEST)); | |
| 2646 GLC(context_, context_->disable(GL_CULL_FACE)); | |
| 2647 GLC(context_, context_->colorMask(true, true, true, true)); | |
| 2648 GLC(context_, context_->enable(GL_BLEND)); | |
| 2649 blend_shadow_ = true; | |
| 2650 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | |
| 2651 GLC(context_, context_->activeTexture(GL_TEXTURE0)); | |
| 2652 program_shadow_ = 0; | |
| 2653 | |
| 2654 // Make sure scissoring starts as disabled. | |
| 2655 is_scissor_enabled_ = false; | |
| 2656 GLC(context_, context_->disable(GL_SCISSOR_TEST)); | |
| 2657 } | |
| 2658 | |
| 2576 bool GLRenderer::IsContextLost() { | 2659 bool GLRenderer::IsContextLost() { |
| 2577 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 2660 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 2578 } | 2661 } |
| 2579 | 2662 |
| 2580 } // namespace cc | 2663 } // namespace cc |
| OLD | NEW |