diff options
Diffstat (limited to 'WebCore/platform/graphics/skia')
9 files changed, 52 insertions, 36 deletions
diff --git a/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp b/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp index b6d6e65..8301871 100644 --- a/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp +++ b/WebCore/platform/graphics/skia/FontCustomPlatformData.cpp @@ -36,7 +36,7 @@ #include "Base64.h" #include "ChromiumBridge.h" #include "OpenTypeUtilities.h" -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) #include "SkStream.h" #endif @@ -47,7 +47,7 @@ #if OS(WINDOWS) #include <objbase.h> -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) #include <cstring> #endif @@ -58,7 +58,7 @@ FontCustomPlatformData::~FontCustomPlatformData() #if OS(WINDOWS) if (m_fontReference) RemoveFontMemResourceEx(m_fontReference); -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) if (m_fontReference) m_fontReference->unref(); #endif @@ -99,7 +99,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b HFONT hfont = CreateFontIndirect(&logFont); return FontPlatformData(hfont, size); -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) ASSERT(m_fontReference); return FontPlatformData(m_fontReference, "", size, bold && !m_fontReference->isBold(), italic && !m_fontReference->isItalic()); #else @@ -123,7 +123,7 @@ static String createUniqueFontName() } #endif -#if OS(LINUX) +#if OS(LINUX) || OS(FREEBSD) class RemoteFontStream : public SkStream { public: explicit RemoteFontStream(PassRefPtr<SharedBuffer> buffer) @@ -189,7 +189,7 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) if (!fontReference) return 0; return new FontCustomPlatformData(fontReference, fontName); -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) RemoteFontStream* stream = new RemoteFontStream(buffer); SkTypeface* typeface = SkTypeface::CreateFromStream(stream); if (!typeface) diff --git a/WebCore/platform/graphics/skia/FontCustomPlatformData.h b/WebCore/platform/graphics/skia/FontCustomPlatformData.h index d451c9c..94d7ec3 100644 --- a/WebCore/platform/graphics/skia/FontCustomPlatformData.h +++ b/WebCore/platform/graphics/skia/FontCustomPlatformData.h @@ -39,7 +39,7 @@ #if OS(WINDOWS) #include "PlatformString.h" #include <windows.h> -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) #include "SkTypeface.h" #endif @@ -54,7 +54,7 @@ struct FontCustomPlatformData : Noncopyable { : m_fontReference(fontReference) , m_name(name) {} -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) explicit FontCustomPlatformData(SkTypeface* typeface) : m_fontReference(typeface) {} @@ -70,7 +70,7 @@ struct FontCustomPlatformData : Noncopyable { #if OS(WINDOWS) HANDLE m_fontReference; String m_name; -#elif OS(LINUX) +#elif OS(LINUX) || OS(FREEBSD) SkTypeface* m_fontReference; #endif }; diff --git a/WebCore/platform/graphics/skia/GradientSkia.cpp b/WebCore/platform/graphics/skia/GradientSkia.cpp index 66a8976..a636d10 100644 --- a/WebCore/platform/graphics/skia/GradientSkia.cpp +++ b/WebCore/platform/graphics/skia/GradientSkia.cpp @@ -42,7 +42,7 @@ namespace WebCore { void Gradient::platformDestroy() { if (m_gradient) - m_gradient->safeUnref(); + SkSafeUnref(m_gradient); m_gradient = 0; } diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp index d618c19..4bc98fb 100644 --- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp @@ -338,13 +338,15 @@ void GraphicsContext::clearRect(const FloatRect& rect) if (paintingDisabled()) return; - if (platformContext()->useGPU()) { + if (platformContext()->useGPU() && !platformContext()->canvasClipApplied()) { platformContext()->prepareForHardwareDraw(); platformContext()->gpuCanvas()->clearRect(rect); return; } - platformContext()->prepareForSoftwareDraw(); + // Force a readback here (if we're using the GPU), since clearRect() is + // incompatible with mixed-mode rendering. + platformContext()->syncSoftwareCanvas(); SkRect r = rect; if (!isRectSkiaSafe(getCTM(), r)) diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp index 0b96d80..e123256 100644 --- a/WebCore/platform/graphics/skia/ImageSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageSkia.cpp @@ -36,7 +36,6 @@ #include "FloatConversion.h" #include "FloatRect.h" #include "GLES2Canvas.h" -#include "GLES2Context.h" #include "GraphicsContext.h" #include "Logging.h" #include "NativeImageSkia.h" @@ -144,7 +143,9 @@ static ResamplingMode computeResamplingMode(PlatformContextSkia* platformContext // Everything else gets resampled. // If the platform context permits high quality interpolation, use it. - if (platformContext->interpolationQuality() == InterpolationHigh) + // High quality interpolation only enabled for scaling and translation. + if (platformContext->interpolationQuality() == InterpolationHigh + && !(platformContext->canvas()->getTotalMatrix().getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask))) return RESAMPLE_AWESOME; return RESAMPLE_LINEAR; @@ -174,8 +175,12 @@ static void drawResampledBitmap(SkCanvas& canvas, SkPaint& paint, const NativeIm && srcIRect.height() == bitmap.height(); // We will always draw in integer sizes, so round the destination rect. + // First we need to apply canvas transformation matrix to get desired size of + // resampled image. + SkRect destRectTransformed; + canvas.getTotalMatrix().mapRect(&destRectTransformed, destRect); SkIRect destRectRounded; - destRect.round(&destRectRounded); + destRectTransformed.round(&destRectRounded); SkIRect resizedImageRect = // Represents the size of the resized image. { 0, 0, destRectRounded.width(), destRectRounded.height() }; @@ -189,7 +194,10 @@ static void drawResampledBitmap(SkCanvas& canvas, SkPaint& paint, const NativeIm // Compute the visible portion of our rect. SkRect destBitmapSubsetSk; ClipRectToCanvas(canvas, destRect, &destBitmapSubsetSk); - destBitmapSubsetSk.offset(-destRect.fLeft, -destRect.fTop); + // Determine size of resampled image based on clipped destination rect. + SkRect destBitmapSubsetSkTransformed; + canvas.getTotalMatrix().mapRect(&destBitmapSubsetSkTransformed, destBitmapSubsetSk); + destBitmapSubsetSkTransformed.offset(-destBitmapSubsetSkTransformed.fLeft, -destBitmapSubsetSkTransformed.fTop); // The matrix inverting, etc. could have introduced rounding error which // causes the bounds to be outside of the resized bitmap. We round outward @@ -197,7 +205,7 @@ static void drawResampledBitmap(SkCanvas& canvas, SkPaint& paint, const NativeIm // need, and then clamp to the bitmap bounds so we don't get any invalid // data. SkIRect destBitmapSubsetSkI; - destBitmapSubsetSk.roundOut(&destBitmapSubsetSkI); + destBitmapSubsetSkTransformed.roundOut(&destBitmapSubsetSkI); if (!destBitmapSubsetSkI.intersect(resizedImageRect)) return; // Resized image does not intersect. diff --git a/WebCore/platform/graphics/skia/PatternSkia.cpp b/WebCore/platform/graphics/skia/PatternSkia.cpp index bd27b6a..72fac77 100644 --- a/WebCore/platform/graphics/skia/PatternSkia.cpp +++ b/WebCore/platform/graphics/skia/PatternSkia.cpp @@ -42,7 +42,7 @@ namespace WebCore { void Pattern::platformDestroy() { - m_pattern->safeUnref(); + SkSafeUnref(m_pattern); m_pattern = 0; } diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp index 88fbcdd..b469312 100644 --- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp +++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp @@ -162,19 +162,19 @@ PlatformContextSkia::State::State(const State& other) , m_interpolationQuality(other.m_interpolationQuality) , m_canvasClipApplied(other.m_canvasClipApplied) { - // Up the ref count of these. saveRef does nothing if 'this' is NULL. - m_looper->safeRef(); - m_dash->safeRef(); - m_fillShader->safeRef(); - m_strokeShader->safeRef(); + // Up the ref count of these. SkSafeRef does nothing if its argument is 0. + SkSafeRef(m_looper); + SkSafeRef(m_dash); + SkSafeRef(m_fillShader); + SkSafeRef(m_strokeShader); } PlatformContextSkia::State::~State() { - m_looper->safeUnref(); - m_dash->safeUnref(); - m_fillShader->safeUnref(); - m_strokeShader->safeUnref(); + SkSafeUnref(m_looper); + SkSafeUnref(m_dash); + SkSafeUnref(m_fillShader); + SkSafeUnref(m_strokeShader); } // Returns a new State with all of this object's inherited properties copied. @@ -327,7 +327,7 @@ void PlatformContextSkia::drawRect(SkRect rect) // setFillColor() will set the shader to NULL, so save a ref to it now. SkShader* oldFillShader = m_state->m_fillShader; - oldFillShader->safeRef(); + SkSafeRef(oldFillShader); setFillColor(m_state->m_strokeColor); paint.reset(); setupPaintForFilling(&paint); @@ -341,7 +341,7 @@ void PlatformContextSkia::drawRect(SkRect rect) canvas()->drawRect(rightBorder, paint); setFillColor(oldFillColor); setFillShader(oldFillShader); - oldFillShader->safeUnref(); + SkSafeUnref(oldFillShader); } } @@ -487,9 +487,9 @@ void PlatformContextSkia::setStrokeThickness(float thickness) void PlatformContextSkia::setStrokeShader(SkShader* strokeShader) { if (strokeShader != m_state->m_strokeShader) { - m_state->m_strokeShader->safeUnref(); + SkSafeUnref(m_state->m_strokeShader); m_state->m_strokeShader = strokeShader; - m_state->m_strokeShader->safeRef(); + SkSafeRef(m_state->m_strokeShader); } } @@ -561,9 +561,9 @@ void PlatformContextSkia::setFillRule(SkPath::FillType fr) void PlatformContextSkia::setFillShader(SkShader* fillShader) { if (fillShader != m_state->m_fillShader) { - m_state->m_fillShader->safeUnref(); + SkSafeUnref(m_state->m_fillShader); m_state->m_fillShader = fillShader; - m_state->m_fillShader->safeRef(); + SkSafeRef(m_state->m_fillShader); } } @@ -580,7 +580,7 @@ void PlatformContextSkia::setInterpolationQuality(InterpolationQuality interpola void PlatformContextSkia::setDashPathEffect(SkDashPathEffect* dash) { if (dash != m_state->m_dash) { - m_state->m_dash->safeUnref(); + SkSafeUnref(m_state->m_dash); m_state->m_dash = dash; } } @@ -677,6 +677,11 @@ bool PlatformContextSkia::canAccelerate() const && !m_state->m_canvasClipApplied; // Can't accelerate with a clip to path applied. } +bool PlatformContextSkia::canvasClipApplied() const +{ + return m_state->m_canvasClipApplied; +} + class WillPublishCallbackImpl : public DrawingBuffer::WillPublishCallback { public: static PassOwnPtr<WillPublishCallback> create(PlatformContextSkia* pcs) @@ -840,7 +845,7 @@ void PlatformContextSkia::readbackHardwareToSoftware() const for (int i = 0; i < width; ++i) { uint32_t pixel = pixels[i]; // Swizzles from RGBA -> BGRA. - pixels[i] = pixel & 0xFF00FF00 | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16); + pixels[i] = (pixel & 0xFF00FF00) | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16); } } } diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.h b/WebCore/platform/graphics/skia/PlatformContextSkia.h index 4ba85d1..eb03224 100644 --- a/WebCore/platform/graphics/skia/PlatformContextSkia.h +++ b/WebCore/platform/graphics/skia/PlatformContextSkia.h @@ -180,6 +180,7 @@ public: bool hasImageResamplingHint() const; bool canAccelerate() const; + bool canvasClipApplied() const; bool useGPU() { return m_useGPU; } void setSharedGraphicsContext3D(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&); GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); } diff --git a/WebCore/platform/graphics/skia/SkiaFontWin.cpp b/WebCore/platform/graphics/skia/SkiaFontWin.cpp index 9edb775..6acfd35 100644 --- a/WebCore/platform/graphics/skia/SkiaFontWin.cpp +++ b/WebCore/platform/graphics/skia/SkiaFontWin.cpp @@ -340,7 +340,7 @@ bool paintSkiaText(GraphicsContext* context, // thing would be to draw to a new layer and then draw that layer // with a shadow. But this is a lot of extra work for something // that isn't normally an issue. - paint.setLooper(0)->safeUnref(); + SkSafeUnref(paint.setLooper(0)); } if (!skiaDrawText(hfont, dc, platformContext->canvas(), *origin, &paint, |