| 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 "CCSolidColorDrawQuad.h" | 10 #include "CCSolidColorDrawQuad.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 using WebKit::WebCompositorSoftwareOutputDevice; | 22 using WebKit::WebCompositorSoftwareOutputDevice; |
| 23 using WebKit::WebImage; | 23 using WebKit::WebImage; |
| 24 using WebKit::WebSize; | 24 using WebKit::WebSize; |
| 25 using WebKit::WebTransformationMatrix; | 25 using WebKit::WebTransformationMatrix; |
| 26 | 26 |
| 27 namespace cc { | 27 namespace cc { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 SkRect toSkRect(const FloatRect& rect) | 31 SkRect toSkRect(const ccmath::FloatRect& rect) |
| 32 { | 32 { |
| 33 return SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | 33 return SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 SkIRect toSkIRect(const IntRect& rect) | 36 SkIRect toSkIRect(const ccmath::IntRect& rect) |
| 37 { | 37 { |
| 38 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | 38 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void toSkMatrix(SkMatrix* flattened, const WebTransformationMatrix& m) | 41 void toSkMatrix(SkMatrix* flattened, const WebTransformationMatrix& m) |
| 42 { | 42 { |
| 43 // Convert from 4x4 to 3x3 by dropping the third row and column. | 43 // Convert from 4x4 to 3x3 by dropping the third row and column. |
| 44 flattened->set(0, m.m11()); | 44 flattened->set(0, m.m11()); |
| 45 flattened->set(1, m.m21()); | 45 flattened->set(1, m.m21()); |
| 46 flattened->set(2, m.m41()); | 46 flattened->set(2, m.m41()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 void CCRendererSoftware::finish() | 111 void CCRendererSoftware::finish() |
| 112 { | 112 { |
| 113 } | 113 } |
| 114 | 114 |
| 115 void CCRendererSoftware::bindFramebufferToOutputSurface(DrawingFrame& frame) | 115 void CCRendererSoftware::bindFramebufferToOutputSurface(DrawingFrame& frame) |
| 116 { | 116 { |
| 117 m_currentFramebufferLock.clear(); | 117 m_currentFramebufferLock.clear(); |
| 118 m_skCurrentCanvas = &m_skRootCanvas; | 118 m_skCurrentCanvas = &m_skRootCanvas; |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool CCRendererSoftware::bindFramebufferToTexture(DrawingFrame& frame, const CCS
copedTexture* texture, const IntRect& framebufferRect) | 121 bool CCRendererSoftware::bindFramebufferToTexture(DrawingFrame& frame, const CCS
copedTexture* texture, const ccmath::IntRect& framebufferRect) |
| 122 { | 122 { |
| 123 m_currentFramebufferLock = adoptPtr(new CCResourceProvider::ScopedWriteLockS
oftware(m_resourceProvider, texture->id())); | 123 m_currentFramebufferLock = adoptPtr(new CCResourceProvider::ScopedWriteLockS
oftware(m_resourceProvider, texture->id())); |
| 124 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); | 124 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); |
| 125 initializeMatrices(frame, framebufferRect, false); | 125 initializeMatrices(frame, framebufferRect, false); |
| 126 setDrawViewportSize(framebufferRect.size()); | 126 setDrawViewportSize(framebufferRect.size()); |
| 127 | 127 |
| 128 return true; | 128 return true; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void CCRendererSoftware::enableScissorTestRect(const IntRect& scissorRect) | 131 void CCRendererSoftware::enableScissorTestRect(const ccmath::IntRect& scissorRec
t) |
| 132 { | 132 { |
| 133 m_skCurrentCanvas->clipRect(toSkRect(scissorRect), SkRegion::kReplace_Op); | 133 m_skCurrentCanvas->clipRect(toSkRect(scissorRect), SkRegion::kReplace_Op); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void CCRendererSoftware::disableScissorTest() | 136 void CCRendererSoftware::disableScissorTest() |
| 137 { | 137 { |
| 138 IntRect canvasRect(IntPoint(), viewportSize()); | 138 ccmath::IntRect canvasRect(ccmath::IntPoint(), viewportSize()); |
| 139 m_skCurrentCanvas->clipRect(toSkRect(canvasRect), SkRegion::kReplace_Op); | 139 m_skCurrentCanvas->clipRect(toSkRect(canvasRect), SkRegion::kReplace_Op); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void CCRendererSoftware::clearFramebuffer(DrawingFrame& frame) | 142 void CCRendererSoftware::clearFramebuffer(DrawingFrame& frame) |
| 143 { | 143 { |
| 144 m_skCurrentCanvas->clear(SK_ColorGREEN); | 144 m_skCurrentCanvas->clear(SK_ColorGREEN); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void CCRendererSoftware::setDrawViewportSize(const IntSize& viewportSize) | 147 void CCRendererSoftware::setDrawViewportSize(const ccmath::IntSize& viewportSize
) |
| 148 { | 148 { |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool CCRendererSoftware::isSoftwareResource(CCResourceProvider::ResourceId id) c
onst | 151 bool CCRendererSoftware::isSoftwareResource(CCResourceProvider::ResourceId id) c
onst |
| 152 { | 152 { |
| 153 switch (m_resourceProvider->resourceType(id)) { | 153 switch (m_resourceProvider->resourceType(id)) { |
| 154 case CCResourceProvider::GLTexture: | 154 case CCResourceProvider::GLTexture: |
| 155 return false; | 155 return false; |
| 156 case CCResourceProvider::Bitmap: | 156 case CCResourceProvider::Bitmap: |
| 157 return true; | 157 return true; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 void CCRendererSoftware::drawTextureQuad(const DrawingFrame& frame, const CCText
ureDrawQuad* quad) | 223 void CCRendererSoftware::drawTextureQuad(const DrawingFrame& frame, const CCText
ureDrawQuad* quad) |
| 224 { | 224 { |
| 225 if (!isSoftwareResource(quad->resourceId())) { | 225 if (!isSoftwareResource(quad->resourceId())) { |
| 226 drawUnsupportedQuad(frame, quad); | 226 drawUnsupportedQuad(frame, quad); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 // FIXME: Add support for non-premultiplied alpha. | 230 // FIXME: Add support for non-premultiplied alpha. |
| 231 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); | 231 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); |
| 232 FloatRect uvRect = quad->uvRect(); | 232 ccmath::FloatRect uvRect = quad->uvRect(); |
| 233 uvRect.scale(quad->quadRect().width(), quad->quadRect().height()); | 233 uvRect.Scale(quad->quadRect().width(), quad->quadRect().height()); |
| 234 SkIRect skUvRect = toSkIRect(enclosingIntRect(uvRect)); | 234 SkIRect skUvRect = toSkIRect(uvRect.EnclosingIntRect()); |
| 235 if (quad->flipped()) | 235 if (quad->flipped()) |
| 236 m_skCurrentCanvas->scale(1, -1); | 236 m_skCurrentCanvas->scale(1, -1); |
| 237 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &skUvRect, t
oSkRect(quadVertexRect()), &m_skCurrentPaint); | 237 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &skUvRect, t
oSkRect(quadVertexRect()), &m_skCurrentPaint); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void CCRendererSoftware::drawTileQuad(const DrawingFrame& frame, const CCTileDra
wQuad* quad) | 240 void CCRendererSoftware::drawTileQuad(const DrawingFrame& frame, const CCTileDra
wQuad* quad) |
| 241 { | 241 { |
| 242 ASSERT(isSoftwareResource(quad->resourceId())); | 242 ASSERT(isSoftwareResource(quad->resourceId())); |
| 243 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); | 243 CCResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvid
er, quad->resourceId()); |
| 244 | 244 |
| 245 SkIRect uvRect = toSkIRect(IntRect(quad->textureOffset(), quad->quadRect().s
ize())); | 245 SkIRect uvRect = toSkIRect(ccmath::IntRect(quad->textureOffset(), quad->quad
Rect().size())); |
| 246 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &uvRect, toS
kRect(quadVertexRect()), &m_skCurrentPaint); | 246 m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &uvRect, toS
kRect(quadVertexRect()), &m_skCurrentPaint); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void CCRendererSoftware::drawUnsupportedQuad(const DrawingFrame& frame, const CC
DrawQuad* quad) | 249 void CCRendererSoftware::drawUnsupportedQuad(const DrawingFrame& frame, const CC
DrawQuad* quad) |
| 250 { | 250 { |
| 251 m_skCurrentPaint.setColor(SK_ColorMAGENTA); | 251 m_skCurrentPaint.setColor(SK_ColorMAGENTA); |
| 252 m_skCurrentPaint.setAlpha(quad->opacity() * 255); | 252 m_skCurrentPaint.setAlpha(quad->opacity() * 255); |
| 253 m_skCurrentCanvas->drawRect(toSkRect(quadVertexRect()), m_skCurrentPaint); | 253 m_skCurrentCanvas->drawRect(toSkRect(quadVertexRect()), m_skCurrentPaint); |
| 254 } | 254 } |
| 255 | 255 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 271 } | 271 } |
| 272 | 272 |
| 273 void CCRendererSoftware::setVisible(bool visible) | 273 void CCRendererSoftware::setVisible(bool visible) |
| 274 { | 274 { |
| 275 if (m_visible == visible) | 275 if (m_visible == visible) |
| 276 return; | 276 return; |
| 277 m_visible = visible; | 277 m_visible = visible; |
| 278 } | 278 } |
| 279 | 279 |
| 280 } | 280 } |
| OLD | NEW |