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 0be006cf772c58b71df2af4ebfaa4a6f5643aff0..ed449b70506b5e1a9a3727588ff2b078a368c8eb 100644 |
| --- a/Source/core/platform/graphics/GraphicsContext.cpp |
| +++ b/Source/core/platform/graphics/GraphicsContext.cpp |
| @@ -44,6 +44,8 @@ |
| #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| +#include "third_party/skia/include/gpu/GrRenderTarget.h" |
| +#include "third_party/skia/include/gpu/GrTexture.h" |
| #include "wtf/Assertions.h" |
| #include "wtf/MathExtras.h" |
| @@ -56,6 +58,40 @@ using blink::WebBlendMode; |
| namespace WebCore { |
| +namespace { |
| + |
| +class CompatibleImageBufferSurface : public ImageBufferSurface { |
| + WTF_MAKE_NONCOPYABLE(CompatibleImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; |
| +public: |
| + CompatibleImageBufferSurface(SkCanvas* canvas, const IntSize& size, OpacityMode opacityMode) |
| + : ImageBufferSurface(size, opacityMode, 1.0f) |
| + { |
| + RefPtr<SkBaseDevice> device = adoptRef(canvas->createCompatibleDevice(SkBitmap::kARGB_8888_Config, size.width(), size.height(), opacityMode == Opaque)); |
|
Stephen White
2013/12/04 21:18:40
It's a little confusing to have a canvas that's pa
|
| + if (!device) |
| + return; |
| + m_canvas = adoptPtr(new SkCanvas(device.get())); |
| + } |
| + virtual ~CompatibleImageBufferSurface() { } |
| + |
| + virtual SkCanvas* canvas() const OVERRIDE { return m_canvas.get(); } |
| + virtual bool isValid() const OVERRIDE { return m_canvas; } |
| + virtual bool isAccelerated() const OVERRIDE { return isValid() && m_canvas->getTopDevice()->accessRenderTarget(); } |
| + virtual Platform3DObject getBackingTexture() const OVERRIDE |
| + { |
| + ASSERT(isAccelerated()); |
| + GrRenderTarget* renderTarget = m_canvas->getTopDevice()->accessRenderTarget(); |
| + if (renderTarget) { |
| + return renderTarget->asTexture()->getTextureHandle(); |
| + } |
| + return 0; |
| + }; |
| + |
| +private: |
| + OwnPtr<SkCanvas> m_canvas; |
| +}; |
| + |
| +} // unnamed namespace |
| + |
| struct GraphicsContext::DeferredSaveState { |
| DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount(count) { } |
| @@ -115,14 +151,6 @@ const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const |
| return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); |
| } |
| -SkBaseDevice* GraphicsContext::createCompatibleDevice(const IntSize& size, bool hasAlpha) const |
| -{ |
| - if (paintingDisabled()) |
| - return 0; |
| - |
| - return m_canvas->createCompatibleDevice(SkBitmap::kARGB_8888_Config, size.width(), size.height(), !hasAlpha); |
| -} |
| - |
| void GraphicsContext::save() |
| { |
| if (paintingDisabled()) |
| @@ -1700,7 +1728,7 @@ void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 |
| } |
| } |
| -PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& size, bool hasAlpha) const |
| +PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& size, OpacityMode opacityMode) const |
| { |
| // Make the buffer larger if the context's transform is scaling it so we need a higher |
| // resolution than one pixel per unit. Also set up a corresponding scale factor on the |
| @@ -1709,9 +1737,10 @@ PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s |
| AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); |
| IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())), static_cast<int>(ceil(size.height() * transform.yScale()))); |
| - OwnPtr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(scaledSize, 1, this, hasAlpha); |
| - if (!buffer) |
| + OwnPtr<ImageBufferSurface> surface = adoptPtr(new CompatibleImageBufferSurface(m_canvas, scaledSize, opacityMode)); |
| + if (!surface->isValid()) |
| return nullptr; |
| + OwnPtr<ImageBuffer> buffer = adoptPtr(new ImageBuffer(surface.release())); |
| buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) / size.width(), |
| static_cast<float>(scaledSize.height()) / size.height())); |