summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/skia
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-10-22 13:02:20 +0100
committerBen Murdoch <benm@google.com>2010-10-26 15:21:41 +0100
commita94275402997c11dd2e778633dacf4b7e630a35d (patch)
treee66f56c67e3b01f22c9c23cd932271ee9ac558ed /WebCore/platform/graphics/skia
parent09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff)
downloadexternal_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'WebCore/platform/graphics/skia')
-rw-r--r--WebCore/platform/graphics/skia/ImageBufferSkia.cpp7
-rw-r--r--WebCore/platform/graphics/skia/ImageSkia.cpp17
-rw-r--r--WebCore/platform/graphics/skia/PathSkia.cpp56
-rw-r--r--WebCore/platform/graphics/skia/PlatformContextSkia.cpp19
-rw-r--r--WebCore/platform/graphics/skia/PlatformContextSkia.h9
5 files changed, 32 insertions, 76 deletions
diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
index 2be7dc5..143d667 100644
--- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
@@ -45,6 +45,8 @@
#include "SkColorPriv.h"
#include "SkiaUtils.h"
+#include <wtf/text/StringConcatenate.h>
+
using namespace std;
namespace WebCore {
@@ -58,7 +60,7 @@ ImageBufferData::ImageBufferData(const IntSize& size)
{
}
-ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success)
+ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, bool& success)
: m_data(size)
, m_size(size)
{
@@ -290,6 +292,7 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint&
void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint)
{
+ context()->platformContext()->prepareForSoftwareDraw();
putImageData<Unmultiplied>(source, sourceRect, destPoint, *context()->platformContext()->bitmap(), m_size);
}
@@ -311,7 +314,7 @@ String ImageBuffer::toDataURL(const String&, const double*) const
base64EncodedData.append('\0');
// And the resulting string.
- return String::format("data:image/png;base64,%s", base64EncodedData.data());
+ return makeString("data:image/png;base64,", base64EncodedData.data());
}
} // namespace WebCore
diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp
index e123256..23e7be6 100644
--- a/WebCore/platform/graphics/skia/ImageSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageSkia.cpp
@@ -143,9 +143,7 @@ static ResamplingMode computeResamplingMode(PlatformContextSkia* platformContext
// Everything else gets resampled.
// If the platform context permits high quality interpolation, use it.
- // High quality interpolation only enabled for scaling and translation.
- if (platformContext->interpolationQuality() == InterpolationHigh
- && !(platformContext->canvas()->getTotalMatrix().getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)))
+ if (platformContext->interpolationQuality() == InterpolationHigh)
return RESAMPLE_AWESOME;
return RESAMPLE_LINEAR;
@@ -175,12 +173,8 @@ 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;
- destRectTransformed.round(&destRectRounded);
+ destRect.round(&destRectRounded);
SkIRect resizedImageRect = // Represents the size of the resized image.
{ 0, 0, destRectRounded.width(), destRectRounded.height() };
@@ -194,10 +188,7 @@ static void drawResampledBitmap(SkCanvas& canvas, SkPaint& paint, const NativeIm
// Compute the visible portion of our rect.
SkRect destBitmapSubsetSk;
ClipRectToCanvas(canvas, destRect, &destBitmapSubsetSk);
- // Determine size of resampled image based on clipped destination rect.
- SkRect destBitmapSubsetSkTransformed;
- canvas.getTotalMatrix().mapRect(&destBitmapSubsetSkTransformed, destBitmapSubsetSk);
- destBitmapSubsetSkTransformed.offset(-destBitmapSubsetSkTransformed.fLeft, -destBitmapSubsetSkTransformed.fTop);
+ destBitmapSubsetSk.offset(-destRect.fLeft, -destRect.fTop);
// The matrix inverting, etc. could have introduced rounding error which
// causes the bounds to be outside of the resized bitmap. We round outward
@@ -205,7 +196,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;
- destBitmapSubsetSkTransformed.roundOut(&destBitmapSubsetSkI);
+ destBitmapSubsetSk.roundOut(&destBitmapSubsetSkI);
if (!destBitmapSubsetSkI.intersect(resizedImageRect))
return; // Resized image does not intersect.
diff --git a/WebCore/platform/graphics/skia/PathSkia.cpp b/WebCore/platform/graphics/skia/PathSkia.cpp
index 12241f8..89323c4 100644
--- a/WebCore/platform/graphics/skia/PathSkia.cpp
+++ b/WebCore/platform/graphics/skia/PathSkia.cpp
@@ -227,62 +227,6 @@ void Path::transform(const AffineTransform& xform)
m_path->transform(xform);
}
-String Path::debugString() const
-{
- String result;
-
- SkPath::Iter iter(*m_path, false);
- SkPoint pts[4];
-
- int numPoints = m_path->getPoints(0, 0);
- SkPath::Verb verb;
-
- do {
- verb = iter.next(pts);
- switch (verb) {
- case SkPath::kMove_Verb:
- result += String::format("M%.2f,%.2f ", pts[0].fX, pts[0].fY);
- numPoints -= 1;
- break;
- case SkPath::kLine_Verb:
- if (!iter.isCloseLine()) {
- result += String::format("L%.2f,%.2f ", pts[1].fX, pts[1].fY);
- numPoints -= 1;
- }
- break;
- case SkPath::kQuad_Verb:
- result += String::format("Q%.2f,%.2f,%.2f,%.2f ",
- pts[1].fX, pts[1].fY,
- pts[2].fX, pts[2].fY);
- numPoints -= 2;
- break;
- case SkPath::kCubic_Verb:
- result += String::format("C%.2f,%.2f,%.2f,%.2f,%.2f,%.2f ",
- pts[1].fX, pts[1].fY,
- pts[2].fX, pts[2].fY,
- pts[3].fX, pts[3].fY);
- numPoints -= 3;
- break;
- case SkPath::kClose_Verb:
- result += "Z ";
- break;
- case SkPath::kDone_Verb:
- break;
- }
- } while (verb != SkPath::kDone_Verb);
-
- // If you have a path that ends with an M, Skia will not iterate the
- // trailing M. That's nice of it, but Apple's paths output the trailing M
- // and we want out layout dumps to look like theirs
- if (numPoints) {
- ASSERT(numPoints==1);
- m_path->getLastPt(pts);
- result += String::format("M%.2f,%.2f ", pts[0].fX, pts[0].fY);
- }
-
- return result.stripWhiteSpace();
-}
-
// Computes the bounding box for the stroke and style currently selected into
// the given bounding box. This also takes into account the stroke width.
static FloatRect boundingBoxForCurrentStroke(const GraphicsContext* context)
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
index b469312..3f9e4c1 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
@@ -34,12 +34,10 @@
#include "AffineTransform.h"
#include "DrawingBuffer.h"
-#include "GLES2Canvas.h"
#include "GraphicsContext.h"
#include "GraphicsContext3D.h"
#include "ImageBuffer.h"
#include "NativeImageSkia.h"
-#include "SharedGraphicsContext3D.h"
#include "SkiaUtils.h"
#include "Texture.h"
#include "TilingData.h"
@@ -56,6 +54,11 @@
#include <wtf/OwnArrayPtr.h>
#include <wtf/Vector.h>
+#if ENABLE(ACCELERATED_2D_CANVAS)
+#include "GLES2Canvas.h"
+#include "SharedGraphicsContext3D.h"
+#endif
+
namespace WebCore {
extern bool isPathSkiaSafe(const SkMatrix& transform, const SkPath& path);
@@ -207,7 +210,9 @@ PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas)
: m_canvas(canvas)
, m_drawingToImageBuffer(false)
, m_useGPU(false)
+#if ENABLE(ACCELERATED_2D_CANVAS)
, m_gpuCanvas(0)
+#endif
, m_backingStoreState(None)
{
m_stateStack.append(State());
@@ -216,8 +221,10 @@ PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas)
PlatformContextSkia::~PlatformContextSkia()
{
+#if ENABLE(ACCELERATED_2D_CANVAS)
if (m_gpuCanvas)
m_gpuCanvas->drawingBuffer()->setWillPublishCallback(0);
+#endif
}
void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas)
@@ -705,6 +712,7 @@ private:
void PlatformContextSkia::setSharedGraphicsContext3D(SharedGraphicsContext3D* context, DrawingBuffer* drawingBuffer, const WebCore::IntSize& size)
{
+#if ENABLE(ACCELERATED_2D_CANVAS)
if (context && drawingBuffer) {
m_useGPU = true;
m_gpuCanvas = new GLES2Canvas(context, drawingBuffer, size);
@@ -716,6 +724,7 @@ void PlatformContextSkia::setSharedGraphicsContext3D(SharedGraphicsContext3D* co
m_gpuCanvas.clear();
m_useGPU = false;
}
+#endif
}
void PlatformContextSkia::prepareForSoftwareDraw() const
@@ -808,6 +817,7 @@ void PlatformContextSkia::markDirtyRect(const IntRect& rect)
void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const
{
+#if ENABLE(ACCELERATED_2D_CANVAS)
const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false);
SkAutoLockPixels lock(bitmap);
SharedGraphicsContext3D* context = m_gpuCanvas->context();
@@ -816,7 +826,7 @@ void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const
m_uploadTexture->updateSubRect(bitmap.getPixels(), m_softwareDirtyRect);
AffineTransform identity;
- gpuCanvas()->drawTexturedRect(m_uploadTexture.get(), m_softwareDirtyRect, m_softwareDirtyRect, identity, 1.0, DeviceColorSpace, op);
+ gpuCanvas()->drawTexturedRect(m_uploadTexture.get(), m_softwareDirtyRect, m_softwareDirtyRect, identity, 1.0, ColorSpaceDeviceRGB, op);
// Clear out the region of the software canvas we just uploaded.
m_canvas->save();
m_canvas->resetMatrix();
@@ -825,10 +835,12 @@ void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const
m_canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
m_canvas->restore();
m_softwareDirtyRect.setWidth(0); // Clear dirty rect.
+#endif
}
void PlatformContextSkia::readbackHardwareToSoftware() const
{
+#if ENABLE(ACCELERATED_2D_CANVAS)
const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(true);
SkAutoLockPixels lock(bitmap);
int width = bitmap.width(), height = bitmap.height();
@@ -850,6 +862,7 @@ void PlatformContextSkia::readbackHardwareToSoftware() const
}
}
m_softwareDirtyRect.unite(IntRect(0, 0, width, height)); // Mark everything as dirty.
+#endif
}
} // namespace WebCore
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.h b/WebCore/platform/graphics/skia/PlatformContextSkia.h
index eb03224..84e5d78 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.h
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.h
@@ -183,8 +183,11 @@ public:
bool canvasClipApplied() const;
bool useGPU() { return m_useGPU; }
void setSharedGraphicsContext3D(SharedGraphicsContext3D*, DrawingBuffer*, const IntSize&);
+#if ENABLE(ACCELERATED_2D_CANVAS)
GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); }
-
+#else
+ GLES2Canvas* gpuCanvas() const { return 0; }
+#endif
// Call these before making a call that manipulates the underlying
// skia::PlatformCanvas or WebCore::GLES2Canvas
void prepareForSoftwareDraw() const;
@@ -224,9 +227,11 @@ private:
FloatSize m_imageResamplingHintDstSize;
bool m_drawingToImageBuffer;
bool m_useGPU;
+#if ENABLE(ACCELERATED_2D_CANVAS)
OwnPtr<GLES2Canvas> m_gpuCanvas;
- mutable enum { None, Software, Mixed, Hardware } m_backingStoreState;
mutable RefPtr<Texture> m_uploadTexture;
+#endif
+ mutable enum { None, Software, Mixed, Hardware } m_backingStoreState;
mutable IntRect m_softwareDirtyRect;
};