Chromium Code Reviews| Index: Source/core/platform/graphics/GraphicsContext.cpp |
| diff --git a/Source/core/platform/graphics/GraphicsContext.cpp b/Source/core/platform/graphics/GraphicsContext.cpp |
| index 60a7f88e0dcf4b7b44412e4932b1afca4495c65c..eb2c0c5e12d70ddeb2962651701222f970880a3a 100644 |
| --- a/Source/core/platform/graphics/GraphicsContext.cpp |
| +++ b/Source/core/platform/graphics/GraphicsContext.cpp |
| @@ -43,6 +43,7 @@ |
| #include "third_party/skia/include/core/SkRefCnt.h" |
| #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| +#include "third_party/skia/include/effects/SkLumaXfermode.h" |
| #include "weborigin/KURL.h" |
| #include "wtf/Assertions.h" |
| #include "wtf/MathExtras.h" |
| @@ -68,7 +69,7 @@ GraphicsContext::GraphicsContext(SkCanvas* canvas) |
| , m_annotationMode(0) |
| #if !ASSERT_DISABLED |
| , m_annotationCount(0) |
| - , m_transparencyCount(0) |
| + , m_layerCount(0) |
| #endif |
| , m_trackOpaqueRegion(false) |
| , m_trackTextRegion(false) |
| @@ -86,7 +87,7 @@ GraphicsContext::~GraphicsContext() |
| { |
| ASSERT(m_stateStack.size() == 1); |
| ASSERT(!m_annotationCount); |
| - ASSERT(!m_transparencyCount); |
| + ASSERT(!m_layerCount); |
| } |
| const SkBitmap* GraphicsContext::bitmap() const |
| @@ -130,11 +131,6 @@ void GraphicsContext::restore() |
| return; |
| } |
| - if (!m_state->m_imageBufferClip.empty()) { |
| - applyClipFromImage(m_state->m_clip, m_state->m_imageBufferClip); |
| - m_canvas->restore(); |
| - } |
| - |
| m_stateStack.removeLast(); |
| m_state = m_stateStack.last().get(); |
| @@ -370,6 +366,11 @@ void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation |
| m_state->m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode); |
| } |
| +void GraphicsContext::setColorSpaceConversion(ColorSpace srcColorSpace, ColorSpace dstColorSpace) |
| +{ |
| + m_state->m_colorFilter = ImageBuffer::createColorSpaceFilter(srcColorSpace, dstColorSpace); |
| +} |
| + |
| bool GraphicsContext::readPixels(SkBitmap* bitmap, int x, int y, SkCanvas::Config8888 config8888) |
| { |
| if (paintingDisabled()) |
| @@ -398,7 +399,7 @@ bool GraphicsContext::concat(const SkMatrix& matrix) |
| return m_canvas->concat(matrix); |
| } |
| -void GraphicsContext::beginTransparencyLayer(float opacity) |
| +void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bounds) |
| { |
| if (paintingDisabled()) |
| return; |
| @@ -413,65 +414,50 @@ void GraphicsContext::beginTransparencyLayer(float opacity) |
| layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); |
| layerPaint.setXfermodeMode(m_state->m_xferMode); |
| - saveLayer(0, &layerPaint, saveFlags); |
| + SkRect* skBounds = 0; |
| + SkRect skBoundsStorage; |
| + |
| + if (bounds) { |
| + skBoundsStorage = WebCoreFloatRectToSKRect(*bounds); |
| + skBounds = &skBoundsStorage; |
| + } |
| + |
| + saveLayer(skBounds, &layerPaint, saveFlags); |
|
Stephen White
2013/08/28 20:16:12
As an alternative, this could be:
if (bounds)
f(malita)
2013/08/28 20:24:04
It does look cleaner, will do.
|
| #if !ASSERT_DISABLED |
| - ++m_transparencyCount; |
| + ++m_layerCount; |
| #endif |
| } |
| -void GraphicsContext::endTransparencyLayer() |
| +void GraphicsContext::beginMaskedLayer(const FloatRect& bounds, MaskType maskType) |
| { |
| if (paintingDisabled()) |
| return; |
| - restoreLayer(); |
| + SkPaint layerPaint; |
| + layerPaint.setXfermode(maskType == AlphaMaskType |
| + ? SkXfermode::Create(SkXfermode::kSrcIn_Mode) |
| + : SkLumaMaskXfermode::Create(SkXfermode::kSrcIn_Mode)); |
| + |
| + SkRect skBounds = WebCoreFloatRectToSKRect(bounds); |
| + saveLayer(&skBounds, &layerPaint); |
| - ASSERT(m_transparencyCount > 0); |
| #if !ASSERT_DISABLED |
| - --m_transparencyCount; |
| + ++m_layerCount; |
| #endif |
| } |
| -void GraphicsContext::clipToImageBuffer(const ImageBuffer* imageBuffer, const FloatRect& rect) |
| +void GraphicsContext::endLayer() |
|
Stephen White
2013/08/28 20:16:12
I guess the name change is this because endLayer()
|
| { |
| if (paintingDisabled()) |
| return; |
| - SkRect bounds = WebCoreFloatRectToSKRect(rect); |
| - |
| - if (imageBuffer->internalSize().isEmpty()) { |
| - clipRect(bounds); |
| - return; |
| - } |
| - |
| - // Skia doesn't support clipping to an image, so we create a layer. The next |
| - // time restore is invoked the layer and |imageBuffer| are combined to |
| - // create the resulting image. |
| - m_state->m_clip = bounds; |
| - |
| - // Get the absolute coordinates of the stored clipping rectangle to make it |
| - // independent of any transform changes. |
| - getTotalMatrix().mapRect(&m_state->m_clip); |
| - |
| - SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>(SkCanvas::kHasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag); |
| - saveLayer(&bounds, 0, saveFlags); |
| - |
| - const SkBitmap* bitmap = imageBuffer->context()->bitmap(); |
| - |
| - if (m_trackOpaqueRegion) { |
| - SkRect opaqueRect = bitmap->isOpaque() ? m_state->m_clip : SkRect::MakeEmpty(); |
| - m_opaqueRegion.setImageMask(opaqueRect); |
| - } |
| + restoreLayer(); |
| - // Copy off the image as |imageBuffer| may be deleted before restore is invoked. |
| - if (bitmap->isImmutable()) |
| - m_state->m_imageBufferClip = *bitmap; |
| - else { |
| - // We need to make a deep-copy of the pixels themselves, so they don't |
| - // change on us between now and when we want to apply them in restore() |
| - bitmap->copyTo(&m_state->m_imageBufferClip, SkBitmap::kARGB_8888_Config); |
| - } |
| + ASSERT(m_layerCount > 0); |
| +#if !ASSERT_DISABLED |
| + --m_layerCount; |
| +#endif |
| } |
| void GraphicsContext::setupPaintForFilling(SkPaint* paint) const |
| @@ -1719,6 +1705,7 @@ void GraphicsContext::setupPaintCommon(SkPaint* paint) const |
| paint->setAntiAlias(m_state->m_shouldAntialias); |
| paint->setXfermodeMode(m_state->m_xferMode); |
| paint->setLooper(m_state->m_looper.get()); |
| + paint->setColorFilter(m_state->m_colorFilter.get()); |
| } |
| void GraphicsContext::drawOuterPath(const SkPath& path, SkPaint& paint, int width) |
| @@ -1870,23 +1857,6 @@ void GraphicsContext::setupShader(SkPaint* paint, Gradient* grad, Pattern* pat, |
| paint->setShader(shader.get()); |
| } |
| - |
| -void GraphicsContext::applyClipFromImage(const SkRect& rect, const SkBitmap& imageBuffer) |
| -{ |
| - if (paintingDisabled()) |
| - return; |
| - |
| - // NOTE: this assumes the image mask contains opaque black for the portions that are to be shown, as such we |
| - // only look at the alpha when compositing. I'm not 100% sure this is what WebKit expects for image clipping. |
| - SkPaint paint; |
| - paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
| - realizeSave(SkCanvas::kMatrixClip_SaveFlag); |
| - m_canvas->save(SkCanvas::kMatrix_SaveFlag); |
| - m_canvas->resetMatrix(); |
| - m_canvas->drawBitmapRect(imageBuffer, 0, rect, &paint); |
| - m_canvas->restore(); |
| -} |
| - |
| void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
| { |
| if (m_trackTextRegion) { |