| 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 "cc/software_renderer.h" | 7 #include "cc/software_renderer.h" |
| 8 | 8 |
| 9 #include "cc/debug_border_draw_quad.h" | 9 #include "cc/debug_border_draw_quad.h" |
| 10 #include "cc/render_pass_draw_quad.h" | 10 #include "cc/render_pass_draw_quad.h" |
| 11 #include "cc/solid_color_draw_quad.h" | 11 #include "cc/solid_color_draw_quad.h" |
| 12 #include "cc/texture_draw_quad.h" | 12 #include "cc/texture_draw_quad.h" |
| 13 #include "cc/tile_draw_quad.h" | 13 #include "cc/tile_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 "ui/gfx/rect_conversions.h" |
| 20 #include "ui/gfx/skia_util.h" |
| 20 #include <public/WebCompositorSoftwareOutputDevice.h> | 21 #include <public/WebCompositorSoftwareOutputDevice.h> |
| 21 #include <public/WebImage.h> | 22 #include <public/WebImage.h> |
| 22 #include <public/WebSize.h> | 23 #include <public/WebSize.h> |
| 23 #include <public/WebTransformationMatrix.h> | 24 #include <public/WebTransformationMatrix.h> |
| 24 | 25 |
| 25 using WebKit::WebCompositorSoftwareOutputDevice; | 26 using WebKit::WebCompositorSoftwareOutputDevice; |
| 26 using WebKit::WebSize; | 27 using WebKit::WebSize; |
| 27 using WebKit::WebTransformationMatrix; | 28 using WebKit::WebTransformationMatrix; |
| 28 | 29 |
| 29 namespace cc { | 30 namespace cc { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 SkRect toSkRect(const gfx::RectF& rect) | |
| 34 { | |
| 35 return SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | |
| 36 } | |
| 37 | |
| 38 SkIRect toSkIRect(const gfx::Rect& rect) | |
| 39 { | |
| 40 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | |
| 41 } | |
| 42 | |
| 43 void toSkMatrix(SkMatrix* flattened, const WebTransformationMatrix& m) | 34 void toSkMatrix(SkMatrix* flattened, const WebTransformationMatrix& m) |
| 44 { | 35 { |
| 45 // Convert from 4x4 to 3x3 by dropping the third row and column. | 36 // Convert from 4x4 to 3x3 by dropping the third row and column. |
| 46 flattened->set(0, m.m11()); | 37 flattened->set(0, m.m11()); |
| 47 flattened->set(1, m.m21()); | 38 flattened->set(1, m.m21()); |
| 48 flattened->set(2, m.m41()); | 39 flattened->set(2, m.m41()); |
| 49 flattened->set(3, m.m12()); | 40 flattened->set(3, m.m12()); |
| 50 flattened->set(4, m.m22()); | 41 flattened->set(4, m.m22()); |
| 51 flattened->set(5, m.m42()); | 42 flattened->set(5, m.m42()); |
| 52 flattened->set(6, m.m14()); | 43 flattened->set(6, m.m14()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 m_currentFramebufferLock = make_scoped_ptr(new ResourceProvider::ScopedWrite
LockSoftware(m_resourceProvider, texture->id())); | 124 m_currentFramebufferLock = make_scoped_ptr(new ResourceProvider::ScopedWrite
LockSoftware(m_resourceProvider, texture->id())); |
| 134 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); | 125 m_skCurrentCanvas = m_currentFramebufferLock->skCanvas(); |
| 135 initializeMatrices(frame, framebufferRect, false); | 126 initializeMatrices(frame, framebufferRect, false); |
| 136 setDrawViewportSize(framebufferRect.size()); | 127 setDrawViewportSize(framebufferRect.size()); |
| 137 | 128 |
| 138 return true; | 129 return true; |
| 139 } | 130 } |
| 140 | 131 |
| 141 void SoftwareRenderer::enableScissorTestRect(const gfx::Rect& scissorRect) | 132 void SoftwareRenderer::enableScissorTestRect(const gfx::Rect& scissorRect) |
| 142 { | 133 { |
| 143 m_skCurrentCanvas->clipRect(toSkRect(scissorRect), SkRegion::kReplace_Op); | 134 m_skCurrentCanvas->clipRect(gfx::RectFToSkRect(scissorRect), SkRegion::kRepl
ace_Op); |
| 144 } | 135 } |
| 145 | 136 |
| 146 void SoftwareRenderer::disableScissorTest() | 137 void SoftwareRenderer::disableScissorTest() |
| 147 { | 138 { |
| 148 gfx::Rect canvasRect(gfx::Point(), viewportSize()); | 139 gfx::Rect canvasRect(gfx::Point(), viewportSize()); |
| 149 m_skCurrentCanvas->clipRect(toSkRect(canvasRect), SkRegion::kReplace_Op); | 140 m_skCurrentCanvas->clipRect(gfx::RectFToSkRect(canvasRect), SkRegion::kRepla
ce_Op); |
| 150 } | 141 } |
| 151 | 142 |
| 152 void SoftwareRenderer::clearFramebuffer(DrawingFrame& frame) | 143 void SoftwareRenderer::clearFramebuffer(DrawingFrame& frame) |
| 153 { | 144 { |
| 154 if (frame.currentRenderPass->hasTransparentBackground()) { | 145 if (frame.currentRenderPass->hasTransparentBackground()) { |
| 155 m_skCurrentCanvas->clear(SkColorSetARGB(0, 0, 0, 0)); | 146 m_skCurrentCanvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
| 156 } else { | 147 } else { |
| 157 #ifndef NDEBUG | 148 #ifndef NDEBUG |
| 158 // On DEBUG builds, opaque render passes are cleared to blue to easily s
ee regions that were not drawn on the screen. | 149 // On DEBUG builds, opaque render passes are cleared to blue to easily s
ee regions that were not drawn on the screen. |
| 159 m_skCurrentCanvas->clear(SkColorSetARGB(255, 0, 0, 255)); | 150 m_skCurrentCanvas->clear(SkColorSetARGB(255, 0, 0, 255)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 break; | 211 break; |
| 221 } | 212 } |
| 222 | 213 |
| 223 m_skCurrentCanvas->resetMatrix(); | 214 m_skCurrentCanvas->resetMatrix(); |
| 224 } | 215 } |
| 225 | 216 |
| 226 void SoftwareRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const Debu
gBorderDrawQuad* quad) | 217 void SoftwareRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const Debu
gBorderDrawQuad* quad) |
| 227 { | 218 { |
| 228 // We need to apply the matrix manually to have pixel-sized stroke width. | 219 // We need to apply the matrix manually to have pixel-sized stroke width. |
| 229 SkPoint vertices[4]; | 220 SkPoint vertices[4]; |
| 230 toSkRect(quadVertexRect()).toQuad(vertices); | 221 gfx::RectFToSkRect(quadVertexRect()).toQuad(vertices); |
| 231 SkPoint transformedVertices[4]; | 222 SkPoint transformedVertices[4]; |
| 232 m_skCurrentCanvas->getTotalMatrix().mapPoints(transformedVertices, vertices,
4); | 223 m_skCurrentCanvas->getTotalMatrix().mapPoints(transformedVertices, vertices,
4); |
| 233 m_skCurrentCanvas->resetMatrix(); | 224 m_skCurrentCanvas->resetMatrix(); |
| 234 | 225 |
| 235 m_skCurrentPaint.setColor(quad->color()); | 226 m_skCurrentPaint.setColor(quad->color()); |
| 236 m_skCurrentPaint.setAlpha(quad->opacity() * SkColorGetA(quad->color())); | 227 m_skCurrentPaint.setAlpha(quad->opacity() * SkColorGetA(quad->color())); |
| 237 m_skCurrentPaint.setStyle(SkPaint::kStroke_Style); | 228 m_skCurrentPaint.setStyle(SkPaint::kStroke_Style); |
| 238 m_skCurrentPaint.setStrokeWidth(quad->width()); | 229 m_skCurrentPaint.setStrokeWidth(quad->width()); |
| 239 m_skCurrentCanvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, transformedVe
rtices, m_skCurrentPaint); | 230 m_skCurrentCanvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, transformedVe
rtices, m_skCurrentPaint); |
| 240 } | 231 } |
| 241 | 232 |
| 242 void SoftwareRenderer::drawSolidColorQuad(const DrawingFrame& frame, const Solid
ColorDrawQuad* quad) | 233 void SoftwareRenderer::drawSolidColorQuad(const DrawingFrame& frame, const Solid
ColorDrawQuad* quad) |
| 243 { | 234 { |
| 244 m_skCurrentPaint.setColor(quad->color()); | 235 m_skCurrentPaint.setColor(quad->color()); |
| 245 m_skCurrentPaint.setAlpha(quad->opacity() * SkColorGetA(quad->color())); | 236 m_skCurrentPaint.setAlpha(quad->opacity() * SkColorGetA(quad->color())); |
| 246 m_skCurrentCanvas->drawRect(toSkRect(quadVertexRect()), m_skCurrentPaint); | 237 m_skCurrentCanvas->drawRect(gfx::RectFToSkRect(quadVertexRect()), m_skCurren
tPaint); |
| 247 } | 238 } |
| 248 | 239 |
| 249 void SoftwareRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureD
rawQuad* quad) | 240 void SoftwareRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureD
rawQuad* quad) |
| 250 { | 241 { |
| 251 if (!isSoftwareResource(quad->resourceId())) { | 242 if (!isSoftwareResource(quad->resourceId())) { |
| 252 drawUnsupportedQuad(frame, quad); | 243 drawUnsupportedQuad(frame, quad); |
| 253 return; | 244 return; |
| 254 } | 245 } |
| 255 | 246 |
| 256 // FIXME: Add support for non-premultiplied alpha. | 247 // FIXME: Add support for non-premultiplied alpha. |
| 257 ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, quad->reso
urceId()); | 248 ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, quad->reso
urceId()); |
| 258 const SkBitmap* bitmap = lock.skBitmap(); | 249 const SkBitmap* bitmap = lock.skBitmap(); |
| 259 gfx::RectF uvRect = gfx::ScaleRect(quad->uvRect(), bitmap->width(), bitmap->
height()); | 250 gfx::RectF uvRect = gfx::ScaleRect(quad->uvRect(), bitmap->width(), bitmap->
height()); |
| 260 SkIRect skUvRect = toSkIRect(gfx::ToEnclosingRect(uvRect)); | 251 SkIRect skUvRect = gfx::RectToSkIRect(gfx::ToEnclosingRect(uvRect)); |
| 261 if (quad->flipped()) | 252 if (quad->flipped()) |
| 262 m_skCurrentCanvas->scale(1, -1); | 253 m_skCurrentCanvas->scale(1, -1); |
| 263 m_skCurrentCanvas->drawBitmapRect(*bitmap, &skUvRect, toSkRect(quadVertexRec
t()), &m_skCurrentPaint); | 254 m_skCurrentCanvas->drawBitmapRect(*bitmap, &skUvRect, gfx::RectFToSkRect(qua
dVertexRect()), &m_skCurrentPaint); |
| 264 } | 255 } |
| 265 | 256 |
| 266 void SoftwareRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQua
d* quad) | 257 void SoftwareRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQua
d* quad) |
| 267 { | 258 { |
| 268 DCHECK(isSoftwareResource(quad->resourceId())); | 259 DCHECK(isSoftwareResource(quad->resourceId())); |
| 269 ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, quad->reso
urceId()); | 260 ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, quad->reso
urceId()); |
| 270 | 261 |
| 271 SkIRect uvRect = toSkIRect(gfx::Rect(quad->textureOffset(), quad->quadRect()
.size())); | 262 SkIRect uvRect = gfx::RectToSkIRect(gfx::Rect(quad->textureOffset(), quad->q
uadRect().size())); |
| 272 m_skCurrentCanvas->drawBitmapRect(*lock.skBitmap(), &uvRect, toSkRect(quadVe
rtexRect()), &m_skCurrentPaint); | 263 m_skCurrentCanvas->drawBitmapRect(*lock.skBitmap(), &uvRect, gfx::RectFToSkR
ect(quadVertexRect()), &m_skCurrentPaint); |
| 273 } | 264 } |
| 274 | 265 |
| 275 void SoftwareRenderer::drawRenderPassQuad(const DrawingFrame& frame, const Rende
rPassDrawQuad* quad) | 266 void SoftwareRenderer::drawRenderPassQuad(const DrawingFrame& frame, const Rende
rPassDrawQuad* quad) |
| 276 { | 267 { |
| 277 CachedTexture* contentTexture = m_renderPassTextures.get(quad->renderPassId(
)); | 268 CachedTexture* contentTexture = m_renderPassTextures.get(quad->renderPassId(
)); |
| 278 if (!contentTexture || !contentTexture->id()) | 269 if (!contentTexture || !contentTexture->id()) |
| 279 return; | 270 return; |
| 280 | 271 |
| 281 DCHECK(isSoftwareResource(contentTexture->id())); | 272 DCHECK(isSoftwareResource(contentTexture->id())); |
| 282 ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, contentTex
ture->id()); | 273 ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, contentTex
ture->id()); |
| 283 | 274 |
| 284 SkRect destRect = toSkRect(quadVertexRect()); | 275 SkRect destRect = gfx::RectFToSkRect(quadVertexRect()); |
| 285 | 276 |
| 286 const SkBitmap* content = lock.skBitmap(); | 277 const SkBitmap* content = lock.skBitmap(); |
| 287 | 278 |
| 288 SkRect contentRect; | 279 SkRect contentRect; |
| 289 content->getBounds(&contentRect); | 280 content->getBounds(&contentRect); |
| 290 | 281 |
| 291 SkMatrix contentMat; | 282 SkMatrix contentMat; |
| 292 contentMat.setRectToRect(contentRect, destRect, SkMatrix::kFill_ScaleToFit); | 283 contentMat.setRectToRect(contentRect, destRect, SkMatrix::kFill_ScaleToFit); |
| 293 | 284 |
| 294 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(*content, | 285 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(*content, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 } else { | 318 } else { |
| 328 // FIXME: Apply background filters and blend with content | 319 // FIXME: Apply background filters and blend with content |
| 329 m_skCurrentCanvas->drawRect(destRect, m_skCurrentPaint); | 320 m_skCurrentCanvas->drawRect(destRect, m_skCurrentPaint); |
| 330 } | 321 } |
| 331 } | 322 } |
| 332 | 323 |
| 333 void SoftwareRenderer::drawUnsupportedQuad(const DrawingFrame& frame, const Draw
Quad* quad) | 324 void SoftwareRenderer::drawUnsupportedQuad(const DrawingFrame& frame, const Draw
Quad* quad) |
| 334 { | 325 { |
| 335 m_skCurrentPaint.setColor(SK_ColorMAGENTA); | 326 m_skCurrentPaint.setColor(SK_ColorMAGENTA); |
| 336 m_skCurrentPaint.setAlpha(quad->opacity() * 255); | 327 m_skCurrentPaint.setAlpha(quad->opacity() * 255); |
| 337 m_skCurrentCanvas->drawRect(toSkRect(quadVertexRect()), m_skCurrentPaint); | 328 m_skCurrentCanvas->drawRect(gfx::RectFToSkRect(quadVertexRect()), m_skCurren
tPaint); |
| 338 } | 329 } |
| 339 | 330 |
| 340 bool SoftwareRenderer::swapBuffers() | 331 bool SoftwareRenderer::swapBuffers() |
| 341 { | 332 { |
| 342 if (Proxy::hasImplThread()) | 333 if (Proxy::hasImplThread()) |
| 343 m_client->onSwapBuffersComplete(); | 334 m_client->onSwapBuffersComplete(); |
| 344 return true; | 335 return true; |
| 345 } | 336 } |
| 346 | 337 |
| 347 void SoftwareRenderer::getFramebufferPixels(void *pixels, const IntRect& rect) | 338 void SoftwareRenderer::getFramebufferPixels(void *pixels, const IntRect& rect) |
| 348 { | 339 { |
| 349 SkBitmap fullBitmap = m_outputDevice->lock(false)->getSkBitmap(); | 340 SkBitmap fullBitmap = m_outputDevice->lock(false)->getSkBitmap(); |
| 350 SkBitmap subsetBitmap; | 341 SkBitmap subsetBitmap; |
| 351 SkIRect invertRect = SkIRect::MakeXYWH(rect.x(), viewportSize().height() - r
ect.maxY(), rect.width(), rect.height()); | 342 SkIRect invertRect = SkIRect::MakeXYWH(rect.x(), viewportSize().height() - r
ect.maxY(), rect.width(), rect.height()); |
| 352 fullBitmap.extractSubset(&subsetBitmap, invertRect); | 343 fullBitmap.extractSubset(&subsetBitmap, invertRect); |
| 353 subsetBitmap.copyPixelsTo(pixels, rect.width() * rect.height() * 4, rect.wid
th() * 4); | 344 subsetBitmap.copyPixelsTo(pixels, rect.width() * rect.height() * 4, rect.wid
th() * 4); |
| 354 m_outputDevice->unlock(); | 345 m_outputDevice->unlock(); |
| 355 } | 346 } |
| 356 | 347 |
| 357 void SoftwareRenderer::setVisible(bool visible) | 348 void SoftwareRenderer::setVisible(bool visible) |
| 358 { | 349 { |
| 359 if (m_visible == visible) | 350 if (m_visible == visible) |
| 360 return; | 351 return; |
| 361 m_visible = visible; | 352 m_visible = visible; |
| 362 } | 353 } |
| 363 | 354 |
| 364 } | 355 } |
| OLD | NEW |