Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/software_renderer.h" | 5 #include "cc/software_renderer.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "cc/compositor_frame.h" | |
| 9 #include "cc/compositor_frame_ack.h" | |
| 10 #include "cc/compositor_frame_metadata.h" | |
| 8 #include "cc/debug_border_draw_quad.h" | 11 #include "cc/debug_border_draw_quad.h" |
| 9 #include "cc/math_util.h" | 12 #include "cc/math_util.h" |
| 13 #include "cc/output_surface.h" | |
| 10 #include "cc/render_pass_draw_quad.h" | 14 #include "cc/render_pass_draw_quad.h" |
| 11 #include "cc/software_output_device.h" | 15 #include "cc/software_output_device.h" |
| 12 #include "cc/solid_color_draw_quad.h" | 16 #include "cc/solid_color_draw_quad.h" |
| 13 #include "cc/texture_draw_quad.h" | 17 #include "cc/texture_draw_quad.h" |
| 14 #include "cc/tile_draw_quad.h" | 18 #include "cc/tile_draw_quad.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebImage.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebImage.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "third_party/skia/include/core/SkDevice.h" | 22 #include "third_party/skia/include/core/SkDevice.h" |
| 19 #include "third_party/skia/include/core/SkMatrix.h" | 23 #include "third_party/skia/include/core/SkMatrix.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 45 { | 49 { |
| 46 return SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && | 50 return SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && |
| 47 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && | 51 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && |
| 48 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && | 52 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && |
| 49 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && | 53 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && |
| 50 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); | 54 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); |
| 51 } | 55 } |
| 52 | 56 |
| 53 } // anonymous namespace | 57 } // anonymous namespace |
| 54 | 58 |
| 55 scoped_ptr<SoftwareRenderer> SoftwareRenderer::create(RendererClient* client, Re sourceProvider* resourceProvider, SoftwareOutputDevice* outputDevice) | 59 scoped_ptr<SoftwareRenderer> SoftwareRenderer::create(RendererClient* client, Ou tputSurface* outputSurface, ResourceProvider* resourceProvider) |
| 56 { | 60 { |
| 57 return make_scoped_ptr(new SoftwareRenderer(client, resourceProvider, output Device)); | 61 return make_scoped_ptr(new SoftwareRenderer(client, outputSurface, resourceP rovider)); |
| 58 } | 62 } |
| 59 | 63 |
| 60 SoftwareRenderer::SoftwareRenderer(RendererClient* client, ResourceProvider* res ourceProvider, SoftwareOutputDevice* outputDevice) | 64 SoftwareRenderer::SoftwareRenderer(RendererClient* client, |
| 65 OutputSurface* outputSurface, | |
| 66 ResourceProvider* resourceProvider) | |
| 61 : DirectRenderer(client, resourceProvider) | 67 : DirectRenderer(client, resourceProvider) |
| 68 , m_outputSurface(outputSurface) | |
| 62 , m_visible(true) | 69 , m_visible(true) |
| 63 , m_isScissorEnabled(false) | 70 , m_isScissorEnabled(false) |
| 64 , m_outputDevice(outputDevice) | 71 , m_outputDevice(outputSurface->software_device()) |
| 65 , m_skCurrentCanvas(0) | 72 , m_skCurrentCanvas(0) |
| 66 { | 73 { |
| 67 m_resourceProvider->setDefaultResourceType(ResourceProvider::Bitmap); | 74 m_resourceProvider->setDefaultResourceType(ResourceProvider::Bitmap); |
| 68 | 75 |
| 69 m_capabilities.maxTextureSize = m_resourceProvider->maxTextureSize(); | 76 m_capabilities.maxTextureSize = m_resourceProvider->maxTextureSize(); |
| 70 m_capabilities.bestTextureFormat = m_resourceProvider->bestTextureFormat(); | 77 m_capabilities.bestTextureFormat = m_resourceProvider->bestTextureFormat(); |
| 71 m_capabilities.usingSetVisibility = true; | 78 m_capabilities.usingSetVisibility = true; |
| 72 // The updater can access bitmaps while the SoftwareRenderer is using them. | 79 // The updater can access bitmaps while the SoftwareRenderer is using them. |
| 73 m_capabilities.allowPartialTextureUpdates = true; | 80 m_capabilities.allowPartialTextureUpdates = true; |
| 74 m_capabilities.usingPartialSwap = true; | 81 m_capabilities.usingPartialSwap = true; |
| 82 if (m_client->hasImplThread()) | |
| 83 m_capabilities.usingSwapCompleteCallback = true; | |
| 84 m_compositorFrame.software_frame_data.reset(new SoftwareFrameData()); | |
| 75 | 85 |
| 76 viewportChanged(); | 86 viewportChanged(); |
| 77 } | 87 } |
| 78 | 88 |
| 79 SoftwareRenderer::~SoftwareRenderer() | 89 SoftwareRenderer::~SoftwareRenderer() |
| 80 { | 90 { |
| 81 } | 91 } |
| 82 | 92 |
| 83 const RendererCapabilities& SoftwareRenderer::capabilities() const | 93 const RendererCapabilities& SoftwareRenderer::capabilities() const |
| 84 { | 94 { |
| 85 return m_capabilities; | 95 return m_capabilities; |
| 86 } | 96 } |
| 87 | 97 |
| 88 void SoftwareRenderer::viewportChanged() | 98 void SoftwareRenderer::viewportChanged() |
| 89 { | 99 { |
| 90 m_outputDevice->DidChangeViewportSize(viewportSize()); | 100 m_outputDevice->Resize(viewportSize()); |
| 91 } | 101 } |
| 92 | 102 |
| 93 void SoftwareRenderer::beginDrawingFrame(DrawingFrame& frame) | 103 void SoftwareRenderer::beginDrawingFrame(DrawingFrame& frame) |
| 94 { | 104 { |
| 95 TRACE_EVENT0("cc", "SoftwareRenderer::beginDrawingFrame"); | 105 TRACE_EVENT0("cc", "SoftwareRenderer::beginDrawingFrame"); |
| 96 m_skRootCanvas = make_scoped_ptr(new SkCanvas(m_outputDevice->Lock(true)->ge tSkBitmap())); | 106 m_skRootCanvas = m_outputDevice->BeginPaint( |
| 107 gfx::ToEnclosingRect(frame.rootDamageRect)); | |
| 97 } | 108 } |
| 98 | 109 |
| 99 void SoftwareRenderer::finishDrawingFrame(DrawingFrame& frame) | 110 void SoftwareRenderer::finishDrawingFrame(DrawingFrame& frame) |
| 100 { | 111 { |
| 101 TRACE_EVENT0("cc", "SoftwareRenderer::finishDrawingFrame"); | 112 TRACE_EVENT0("cc", "SoftwareRenderer::finishDrawingFrame"); |
| 102 m_currentFramebufferLock.reset(); | 113 m_currentFramebufferLock.reset(); |
| 103 m_skCurrentCanvas = 0; | 114 m_skCurrentCanvas = NULL; |
| 104 m_skRootCanvas.reset(); | 115 m_skRootCanvas = NULL; |
| 105 m_outputDevice->Unlock(); | 116 if (settings().compositorFrameMessage) { |
| 117 m_compositorFrame.metadata = m_client->makeCompositorFrameMetadata(); | |
| 118 m_outputDevice->EndPaint(m_compositorFrame.software_frame_data.get()); | |
| 119 } else { | |
| 120 m_outputDevice->EndPaint(); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 bool SoftwareRenderer::swapBuffers() | |
| 125 { | |
| 126 if (settings().compositorFrameMessage) | |
| 127 m_outputSurface->SendFrameToParentCompositor(&m_compositorFrame); | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 void SoftwareRenderer::receiveCompositorFrameAck(const CompositorFrameAck& ack) | |
| 132 { | |
| 133 if (m_client->hasImplThread()) | |
| 134 m_client->onSwapBuffersComplete(); | |
| 135 m_outputDevice->ReclaimDIB(ack.last_content_dib); | |
|
enne (OOO)
2013/03/01 23:51:34
It seems weird to land this function that calls Re
| |
| 106 } | 136 } |
| 107 | 137 |
| 108 bool SoftwareRenderer::flippedFramebuffer() const | 138 bool SoftwareRenderer::flippedFramebuffer() const |
| 109 { | 139 { |
| 110 return false; | 140 return false; |
| 111 } | 141 } |
| 112 | 142 |
| 113 void SoftwareRenderer::ensureScissorTestEnabled() | 143 void SoftwareRenderer::ensureScissorTestEnabled() |
| 114 { | 144 { |
| 115 m_isScissorEnabled = true; | 145 m_isScissorEnabled = true; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 127 setClipRect(gfx::Rect(device->width(), device->height())); | 157 setClipRect(gfx::Rect(device->width(), device->height())); |
| 128 } | 158 } |
| 129 | 159 |
| 130 void SoftwareRenderer::finish() | 160 void SoftwareRenderer::finish() |
| 131 { | 161 { |
| 132 } | 162 } |
| 133 | 163 |
| 134 void SoftwareRenderer::bindFramebufferToOutputSurface(DrawingFrame& frame) | 164 void SoftwareRenderer::bindFramebufferToOutputSurface(DrawingFrame& frame) |
| 135 { | 165 { |
| 136 m_currentFramebufferLock.reset(); | 166 m_currentFramebufferLock.reset(); |
| 137 m_skCurrentCanvas = m_skRootCanvas.get(); | 167 m_skCurrentCanvas = m_skRootCanvas; |
| 138 } | 168 } |
| 139 | 169 |
| 140 bool SoftwareRenderer::bindFramebufferToTexture(DrawingFrame& frame, const Scope dResource* texture, const gfx::Rect& framebufferRect) | 170 bool SoftwareRenderer::bindFramebufferToTexture(DrawingFrame& frame, const Scope dResource* texture, const gfx::Rect& framebufferRect) |
| 141 { | 171 { |
| 142 m_currentFramebufferLock = make_scoped_ptr(new ResourceProvider::ScopedWrite LockSoftware(m_resourceProvider, texture->id())); | 172 m_currentFramebufferLock = make_scoped_ptr(new ResourceProvider::ScopedWrite LockSoftware(m_resourceProvider, texture->id())); |
| 143 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); | 173 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); |
| 144 initializeMatrices(frame, framebufferRect, false); | 174 initializeMatrices(frame, framebufferRect, false); |
| 145 setDrawViewportSize(framebufferRect.size()); | 175 setDrawViewportSize(framebufferRect.size()); |
| 146 | 176 |
| 147 return true; | 177 return true; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 } | 397 } |
| 368 } | 398 } |
| 369 | 399 |
| 370 void SoftwareRenderer::drawUnsupportedQuad(const DrawingFrame& frame, const Draw Quad* quad) | 400 void SoftwareRenderer::drawUnsupportedQuad(const DrawingFrame& frame, const Draw Quad* quad) |
| 371 { | 401 { |
| 372 m_skCurrentPaint.setColor(SK_ColorMAGENTA); | 402 m_skCurrentPaint.setColor(SK_ColorMAGENTA); |
| 373 m_skCurrentPaint.setAlpha(quad->opacity() * 255); | 403 m_skCurrentPaint.setAlpha(quad->opacity() * 255); |
| 374 m_skCurrentCanvas->drawRect(gfx::RectFToSkRect(quadVertexRect()), m_skCurren tPaint); | 404 m_skCurrentCanvas->drawRect(gfx::RectFToSkRect(quadVertexRect()), m_skCurren tPaint); |
| 375 } | 405 } |
| 376 | 406 |
| 377 bool SoftwareRenderer::swapBuffers() | |
| 378 { | |
| 379 if (m_client->hasImplThread()) | |
| 380 m_client->onSwapBuffersComplete(); | |
| 381 return true; | |
| 382 } | |
| 383 | |
| 384 void SoftwareRenderer::getFramebufferPixels(void *pixels, const gfx::Rect& rect) | 407 void SoftwareRenderer::getFramebufferPixels(void *pixels, const gfx::Rect& rect) |
| 385 { | 408 { |
| 386 TRACE_EVENT0("cc", "SoftwareRenderer::getFramebufferPixels"); | 409 TRACE_EVENT0("cc", "SoftwareRenderer::getFramebufferPixels"); |
| 387 SkBitmap fullBitmap = m_outputDevice->Lock(false)->getSkBitmap(); | |
| 388 SkBitmap subsetBitmap; | 410 SkBitmap subsetBitmap; |
| 389 SkIRect invertRect = SkIRect::MakeXYWH(rect.x(), viewportSize().height() - r ect.bottom(), rect.width(), rect.height()); | 411 m_outputDevice->CopyToBitmap(rect, &subsetBitmap); |
| 390 fullBitmap.extractSubset(&subsetBitmap, invertRect); | 412 subsetBitmap.copyPixelsTo(pixels, |
| 391 subsetBitmap.copyPixelsTo(pixels, rect.width() * rect.height() * 4, rect.wid th() * 4); | 413 4 * rect.width() * rect.height(), |
| 392 m_outputDevice->Unlock(); | 414 4 * rect.width()); |
| 393 } | 415 } |
| 394 | 416 |
| 395 void SoftwareRenderer::setVisible(bool visible) | 417 void SoftwareRenderer::setVisible(bool visible) |
| 396 { | 418 { |
| 397 if (m_visible == visible) | 419 if (m_visible == visible) |
| 398 return; | 420 return; |
| 399 m_visible = visible; | 421 m_visible = visible; |
| 400 } | 422 } |
| 401 | 423 |
| 402 } // namespace cc | 424 } // namespace cc |
| OLD | NEW |