| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCRendererSoftware.h" | 7 #include "CCRendererSoftware.h" |
| 8 | 8 |
| 9 #include "CCDebugBorderDrawQuad.h" | 9 #include "CCDebugBorderDrawQuad.h" |
| 10 #include "CCRenderPassDrawQuad.h" | 10 #include "CCRenderPassDrawQuad.h" |
| 11 #include "CCTileDrawQuad.h" | 11 #include "CCTileDrawQuad.h" |
| 12 #include "cc/solid_color_draw_quad.h" | 12 #include "cc/solid_color_draw_quad.h" |
| 13 #include "cc/texture_draw_quad.h" | 13 #include "cc/texture_draw_quad.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "third_party/skia/include/core/SkMatrix.h" | 16 #include "third_party/skia/include/core/SkMatrix.h" |
| 17 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
| 18 #include "third_party/skia/include/effects/SkLayerRasterizer.h" | 18 #include "third_party/skia/include/effects/SkLayerRasterizer.h" |
| 19 #include "ui/gfx/rect_conversions.h" |
| 19 #include <public/WebImage.h> | 20 #include <public/WebImage.h> |
| 20 #include <public/WebSize.h> | 21 #include <public/WebSize.h> |
| 21 #include <public/WebTransformationMatrix.h> | 22 #include <public/WebTransformationMatrix.h> |
| 22 | 23 |
| 23 using WebKit::WebCompositorSoftwareOutputDevice; | 24 using WebKit::WebCompositorSoftwareOutputDevice; |
| 24 using WebKit::WebImage; | 25 using WebKit::WebImage; |
| 25 using WebKit::WebSize; | 26 using WebKit::WebSize; |
| 26 using WebKit::WebTransformationMatrix; | 27 using WebKit::WebTransformationMatrix; |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 SkRect toSkRect(const FloatRect& rect) | 33 SkRect toSkRect(const gfx::RectF& rect) |
| 33 { | 34 { |
| 34 return SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | 35 return SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 SkIRect toSkIRect(const IntRect& rect) | 38 SkIRect toSkIRect(const gfx::Rect& rect) |
| 38 { | 39 { |
| 39 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | 40 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void toSkMatrix(SkMatrix* flattened, const WebTransformationMatrix& m) | 43 void toSkMatrix(SkMatrix* flattened, const WebTransformationMatrix& m) |
| 43 { | 44 { |
| 44 // Convert from 4x4 to 3x3 by dropping the third row and column. | 45 // Convert from 4x4 to 3x3 by dropping the third row and column. |
| 45 flattened->set(0, m.m11()); | 46 flattened->set(0, m.m11()); |
| 46 flattened->set(1, m.m21()); | 47 flattened->set(1, m.m21()); |
| 47 flattened->set(2, m.m41()); | 48 flattened->set(2, m.m41()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 void CCRendererSoftware::finish() | 121 void CCRendererSoftware::finish() |
| 121 { | 122 { |
| 122 } | 123 } |
| 123 | 124 |
| 124 void CCRendererSoftware::bindFramebufferToOutputSurface(DrawingFrame& frame) | 125 void CCRendererSoftware::bindFramebufferToOutputSurface(DrawingFrame& frame) |
| 125 { | 126 { |
| 126 m_currentFramebufferLock.reset(); | 127 m_currentFramebufferLock.reset(); |
| 127 m_skCurrentCanvas = m_skRootCanvas.get(); | 128 m_skCurrentCanvas = m_skRootCanvas.get(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool CCRendererSoftware::bindFramebufferToTexture(DrawingFrame& frame, const CCS
copedTexture* texture, const IntRect& framebufferRect) | 131 bool CCRendererSoftware::bindFramebufferToTexture(DrawingFrame& frame, const CCS
copedTexture* texture, const gfx::Rect& framebufferRect) |
| 131 { | 132 { |
| 132 m_currentFramebufferLock = make_scoped_ptr(new CCResourceProvider::ScopedWri
teLockSoftware(m_resourceProvider, texture->id())); | 133 m_currentFramebufferLock = make_scoped_ptr(new CCResourceProvider::ScopedWri
teLockSoftware(m_resourceProvider, texture->id())); |
| 133 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); | 134 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); |
| 134 initializeMatrices(frame, framebufferRect, false); | 135 initializeMatrices(frame, framebufferRect, false); |
| 135 setDrawViewportSize(framebufferRect.size()); | 136 setDrawViewportSize(framebufferRect.size()); |
| 136 | 137 |
| 137 return true; | 138 return true; |
| 138 } | 139 } |
| 139 | 140 |
| 140 void CCRendererSoftware::enableScissorTestRect(const IntRect& scissorRect) | 141 void CCRendererSoftware::enableScissorTestRect(const gfx::Rect& scissorRect) |
| 141 { | 142 { |
| 142 m_skCurrentCanvas->clipRect(toSkRect(scissorRect), SkRegion::kReplace_Op); | 143 m_skCurrentCanvas->clipRect(toSkRect(scissorRect), SkRegion::kReplace_Op); |
| 143 } | 144 } |
| 144 | 145 |
| 145 void CCRendererSoftware::disableScissorTest() | 146 void CCRendererSoftware::disableScissorTest() |
| 146 { | 147 { |
| 147 IntRect canvasRect(IntPoint(), viewportSize()); | 148 gfx::Rect canvasRect(gfx::Point(), viewportSize()); |
| 148 m_skCurrentCanvas->clipRect(toSkRect(canvasRect), SkRegion::kReplace_Op); | 149 m_skCurrentCanvas->clipRect(toSkRect(canvasRect), SkRegion::kReplace_Op); |
| 149 } | 150 } |
| 150 | 151 |
| 151 void CCRendererSoftware::clearFramebuffer(DrawingFrame& frame) | 152 void CCRendererSoftware::clearFramebuffer(DrawingFrame& frame) |
| 152 { | 153 { |
| 153 if (frame.currentRenderPass->hasTransparentBackground()) { | 154 if (frame.currentRenderPass->hasTransparentBackground()) { |
| 154 m_skCurrentCanvas->clear(SkColorSetARGB(0, 0, 0, 0)); | 155 m_skCurrentCanvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
| 155 } else { | 156 } else { |
| 156 #ifndef NDEBUG | 157 #ifndef NDEBUG |
| 157 // On DEBUG builds, opaque render passes are cleared to blue to easily s
ee regions that were not drawn on the screen. | 158 // On DEBUG builds, opaque render passes are cleared to blue to easily s
ee regions that were not drawn on the screen. |
| 158 m_skCurrentCanvas->clear(SkColorSetARGB(255, 0, 0, 255)); | 159 m_skCurrentCanvas->clear(SkColorSetARGB(255, 0, 0, 255)); |
| 159 #endif | 160 #endif |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 | 163 |
| 163 void CCRendererSoftware::setDrawViewportSize(const IntSize& viewportSize) | 164 void CCRendererSoftware::setDrawViewportSize(const gfx::Size& viewportSize) |
| 164 { | 165 { |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool CCRendererSoftware::isSoftwareResource(CCResourceProvider::ResourceId id) c
onst | 168 bool CCRendererSoftware::isSoftwareResource(CCResourceProvider::ResourceId id) c
onst |
| 168 { | 169 { |
| 169 switch (m_resourceProvider->resourceType(id)) { | 170 switch (m_resourceProvider->resourceType(id)) { |
| 170 case CCResourceProvider::GLTexture: | 171 case CCResourceProvider::GLTexture: |
| 171 return false; | 172 return false; |
| 172 case CCResourceProvider::Bitmap: | 173 case CCResourceProvider::Bitmap: |
| 173 return true; | 174 return true; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 248 |
| 248 void CCRendererSoftware::drawTextureQuad(const DrawingFrame& frame, const CCText
ureDrawQuad* quad) | 249 void CCRendererSoftware::drawTextureQuad(const DrawingFrame& frame, const CCText
ureDrawQuad* quad) |
| 249 { | 250 { |
| 250 if (!isSoftwareResource(quad->resourceId())) { | 251 if (!isSoftwareResource(quad->resourceId())) { |
| 251 drawUnsupportedQuad(frame, quad); | 252 drawUnsupportedQuad(frame, quad); |
| 252 return; | 253 return; |
| 253 } | 254 } |
| 254 | 255 |
| 255 // FIXME: Add support for non-premultiplied alpha. | 256 // FIXME: Add support for non-premultiplied alpha. |
| 256 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); | 257 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); |
| 257 FloatRect uvRect = quad->uvRect(); | 258 gfx::RectF uvRect = quad->uvRect().Scale(quad->quadRect().width(), quad->qua
dRect().height()); |
| 258 uvRect.scale(quad->quadRect().width(), quad->quadRect().height()); | 259 SkIRect skUvRect = toSkIRect(gfx::ToEnclosingRect(uvRect)); |
| 259 SkIRect skUvRect = toSkIRect(enclosingIntRect(uvRect)); | |
| 260 if (quad->flipped()) | 260 if (quad->flipped()) |
| 261 m_skCurrentCanvas->scale(1, -1); | 261 m_skCurrentCanvas->scale(1, -1); |
| 262 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &skUvRect, t
oSkRect(quadVertexRect()), &m_skCurrentPaint); | 262 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &skUvRect, t
oSkRect(quadVertexRect()), &m_skCurrentPaint); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void CCRendererSoftware::drawTileQuad(const DrawingFrame& frame, const CCTileDra
wQuad* quad) | 265 void CCRendererSoftware::drawTileQuad(const DrawingFrame& frame, const CCTileDra
wQuad* quad) |
| 266 { | 266 { |
| 267 DCHECK(isSoftwareResource(quad->resourceId())); | 267 DCHECK(isSoftwareResource(quad->resourceId())); |
| 268 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); | 268 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); |
| 269 | 269 |
| 270 SkIRect uvRect = toSkIRect(IntRect(quad->textureOffset(), quad->quadRect().s
ize())); | 270 SkIRect uvRect = toSkIRect(gfx::Rect(quad->textureOffset(), quad->quadRect()
.size())); |
| 271 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &uvRect, toS
kRect(quadVertexRect()), &m_skCurrentPaint); | 271 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &uvRect, toS
kRect(quadVertexRect()), &m_skCurrentPaint); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void CCRendererSoftware::drawRenderPassQuad(const DrawingFrame& frame, const CCR
enderPassDrawQuad* quad) | 274 void CCRendererSoftware::drawRenderPassQuad(const DrawingFrame& frame, const CCR
enderPassDrawQuad* quad) |
| 275 { | 275 { |
| 276 CachedTexture* contentsTexture = m_renderPassTextures.get(quad->renderPassId
()); | 276 CachedTexture* contentsTexture = m_renderPassTextures.get(quad->renderPassId
()); |
| 277 if (!contentsTexture || !contentsTexture->id()) | 277 if (!contentsTexture || !contentsTexture->id()) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 DCHECK(isSoftwareResource(contentsTexture->id())); | 280 DCHECK(isSoftwareResource(contentsTexture->id())); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 348 } |
| 349 | 349 |
| 350 void CCRendererSoftware::setVisible(bool visible) | 350 void CCRendererSoftware::setVisible(bool visible) |
| 351 { | 351 { |
| 352 if (m_visible == visible) | 352 if (m_visible == visible) |
| 353 return; | 353 return; |
| 354 m_visible = visible; | 354 m_visible = visible; |
| 355 } | 355 } |
| 356 | 356 |
| 357 } | 357 } |
| OLD | NEW |