summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-06-19 17:50:23 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-06-19 17:50:23 -0700
commitba014989e5069fe71be8dd339c87b1a54e87c007 (patch)
treebe4c5a49ed14889a94be5363200d0550f9860f95 /Source
parent063fbf5b66a9b843599e48bce61f7dad817dcfcb (diff)
parent4d764bbae987791f0b30d46d6ed918b0e1158d3d (diff)
downloadexternal_webkit-ba014989e5069fe71be8dd339c87b1a54e87c007.zip
external_webkit-ba014989e5069fe71be8dd339c87b1a54e87c007.tar.gz
external_webkit-ba014989e5069fe71be8dd339c87b1a54e87c007.tar.bz2
Merge "Support recording context in PicturePile"
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp7
-rw-r--r--Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h5
-rw-r--r--Source/WebKit/android/jni/PicturePile.cpp136
-rw-r--r--Source/WebKit/android/jni/PicturePile.h30
4 files changed, 108 insertions, 70 deletions
diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp
index 9e6208d..829be2e 100644
--- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp
+++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp
@@ -13,8 +13,7 @@
namespace WebCore {
-GraphicsOperationCollection::GraphicsOperationCollection(const IntRect& drawArea)
- : m_drawArea(drawArea)
+GraphicsOperationCollection::GraphicsOperationCollection()
{
}
@@ -44,9 +43,9 @@ bool GraphicsOperationCollection::isEmpty()
return !m_operations.size();
}
-AutoGraphicsOperationCollection::AutoGraphicsOperationCollection(const IntRect& area)
+AutoGraphicsOperationCollection::AutoGraphicsOperationCollection()
{
- m_graphicsOperationCollection = new GraphicsOperationCollection(area);
+ m_graphicsOperationCollection = new GraphicsOperationCollection();
m_platformGraphicsContext = new PlatformGraphicsContextRecording(m_graphicsOperationCollection);
m_graphicsContext = new GraphicsContext(m_platformGraphicsContext);
}
diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h
index 9d7b530..d3fc16b 100644
--- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h
+++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h
@@ -39,7 +39,7 @@ class PlatformGraphicsContext;
class GraphicsOperationCollection : public SkRefCnt {
public:
- GraphicsOperationCollection(const IntRect& drawArea);
+ GraphicsOperationCollection();
~GraphicsOperationCollection();
void apply(PlatformGraphicsContext* context);
@@ -48,13 +48,12 @@ public:
bool isEmpty();
private:
- IntRect m_drawArea;
Vector<GraphicsOperation::Operation*> m_operations;
};
class AutoGraphicsOperationCollection {
public:
- AutoGraphicsOperationCollection(const IntRect& area);
+ AutoGraphicsOperationCollection();
~AutoGraphicsOperationCollection();
GraphicsContext* context() { return m_graphicsContext; }
GraphicsOperationCollection* picture() { return m_graphicsOperationCollection; }
diff --git a/Source/WebKit/android/jni/PicturePile.cpp b/Source/WebKit/android/jni/PicturePile.cpp
index bdf347a..6a36ccf 100644
--- a/Source/WebKit/android/jni/PicturePile.cpp
+++ b/Source/WebKit/android/jni/PicturePile.cpp
@@ -35,11 +35,17 @@
#include "PlatformGraphicsContextSkia.h"
#include "SkCanvas.h"
#include "SkNWayCanvas.h"
-#include "SkPicture.h"
#include "SkPixelRef.h"
#include "SkRect.h"
#include "SkRegion.h"
+#if USE_RECORDING_CONTEXT
+#include "GraphicsOperationCollection.h"
+#include "PlatformGraphicsContextRecording.h"
+#else
+#include "SkPicture.h"
+#endif
+
#define ENABLE_PRERENDERED_INVALS true
#define MAX_OVERLAP_COUNT 2
#define MAX_OVERLAP_AREA .7
@@ -57,6 +63,20 @@ static IntRect extractClipBounds(SkCanvas* canvas, const IntSize& size) {
return enclosingIntRect(clip);
}
+PictureContainer::PictureContainer(const PictureContainer& other)
+ : picture(other.picture)
+ , area(other.area)
+ , dirty(other.dirty)
+ , prerendered(other.prerendered)
+{
+ SkSafeRef(picture);
+}
+
+PictureContainer::~PictureContainer()
+{
+ SkSafeUnref(picture);
+}
+
PicturePile::PicturePile(const PicturePile& other)
: m_size(other.m_size)
, m_pile(other.m_pile)
@@ -64,15 +84,6 @@ PicturePile::PicturePile(const PicturePile& other)
{
}
-PicturePile::PicturePile(SkPicture* picture)
-{
- m_size = IntSize(picture->width(), picture->height());
- PictureContainer pc(IntRect(0, 0, m_size.width(), m_size.height()));
- pc.picture = picture;
- pc.dirty = false;
- m_pile.append(pc);
-}
-
void PicturePile::draw(SkCanvas* canvas)
{
/* Loop down recursively, subtracting the previous clip from the SkRegion,
@@ -106,8 +117,7 @@ void PicturePile::drawWithClipRecursive(SkCanvas* canvas, SkRegion& clipRegion,
drawWithClipRecursive(canvas, clipRegion, index - 1);
int saved = canvas->save();
canvas->clipRect(intersection);
- canvas->translate(pc.area.x(), pc.area.y());
- canvas->drawPicture(*pc.picture);
+ drawPicture(canvas, pc);
canvas->restoreToCount(saved);
} else
drawWithClipRecursive(canvas, clipRegion, index - 1);
@@ -162,43 +172,8 @@ void PicturePile::updatePicturesIfNeeded(PicturePainter* painter)
void PicturePile::updatePicture(PicturePainter* painter, PictureContainer& pc)
{
- /* The ref counting here is a bit unusual. What happens is begin/end recording
- * will ref/unref the recording canvas. However, 'canvas' might be pointing
- * at an SkNWayCanvas instead of the recording canvas, which needs to be
- * unref'd. Thus what we do is ref the recording canvas so that we can
- * always unref whatever canvas we have at the end.
- */
TRACE_METHOD();
- SkPicture* picture = new SkPicture();
- SkCanvas* canvas = picture->beginRecording(pc.area.width(), pc.area.height(),
- SkPicture::kUsePathBoundsForClip_RecordingFlag);
- SkSafeRef(canvas);
- canvas->translate(-pc.area.x(), -pc.area.y());
- IntRect drawArea = pc.area;
- if (pc.prerendered.get()) {
- SkCanvas* prerender = painter->createPrerenderCanvas(pc.prerendered.get());
- if (!prerender) {
- ALOGV("Failed to create prerendered for " INT_RECT_FORMAT,
- INT_RECT_ARGS(pc.prerendered->area));
- pc.prerendered.clear();
- } else {
- drawArea.unite(pc.prerendered->area);
- SkNWayCanvas* nwayCanvas = new SkNWayCanvas(drawArea.width(), drawArea.height());
- nwayCanvas->translate(-drawArea.x(), -drawArea.y());
- nwayCanvas->addCanvas(canvas);
- nwayCanvas->addCanvas(prerender);
- SkSafeUnref(canvas);
- SkSafeUnref(prerender);
- canvas = nwayCanvas;
- }
- }
- WebCore::PlatformGraphicsContextSkia pgc(canvas);
- WebCore::GraphicsContext gc(&pgc);
- ALOGV("painting picture: " INT_RECT_FORMAT, INT_RECT_ARGS(drawArea));
- painter->paintContents(&gc, drawArea);
- SkSafeUnref(canvas);
- picture->endRecording();
-
+ Picture* picture = recordPicture(painter, pc);
SkSafeUnref(pc.picture);
pc.picture = picture;
pc.dirty = false;
@@ -297,4 +272,69 @@ PrerenderedInval* PicturePile::prerenderedInvalForArea(const IntRect& area)
return 0;
}
+#if USE_RECORDING_CONTEXT
+void PicturePile::drawPicture(SkCanvas* canvas, PictureContainer& pc)
+{
+ PlatformGraphicsContextSkia pgc(canvas);
+ pc.picture->apply(&pgc);
+}
+
+Picture* PicturePile::recordPicture(PicturePainter* painter, PictureContainer& pc)
+{
+ // TODO: Support? Not needed?
+ pc.prerendered.clear();
+ GraphicsOperationCollection* picture = new GraphicsOperationCollection();
+ WebCore::PlatformGraphicsContextRecording pgc(picture);
+ WebCore::GraphicsContext gc(&pgc);
+ painter->paintContents(&gc, pc.area);
+ return picture;
+}
+#else
+void PicturePile::drawPicture(SkCanvas* canvas, PictureContainer& pc)
+{
+ canvas->translate(pc.area.x(), pc.area.y());
+ pc.picture->draw(canvas);
+}
+
+Picture* PicturePile::recordPicture(PicturePainter* painter, PictureContainer& pc)
+{
+ /* The ref counting here is a bit unusual. What happens is begin/end recording
+ * will ref/unref the recording canvas. However, 'canvas' might be pointing
+ * at an SkNWayCanvas instead of the recording canvas, which needs to be
+ * unref'd. Thus what we do is ref the recording canvas so that we can
+ * always unref whatever canvas we have at the end.
+ */
+ SkPicture* picture = new SkPicture();
+ SkCanvas* canvas = picture->beginRecording(pc.area.width(), pc.area.height(),
+ SkPicture::kUsePathBoundsForClip_RecordingFlag);
+ SkSafeRef(canvas);
+ canvas->translate(-pc.area.x(), -pc.area.y());
+ IntRect drawArea = pc.area;
+ if (pc.prerendered.get()) {
+ SkCanvas* prerender = painter->createPrerenderCanvas(pc.prerendered.get());
+ if (!prerender) {
+ ALOGV("Failed to create prerendered for " INT_RECT_FORMAT,
+ INT_RECT_ARGS(pc.prerendered->area));
+ pc.prerendered.clear();
+ } else {
+ drawArea.unite(pc.prerendered->area);
+ SkNWayCanvas* nwayCanvas = new SkNWayCanvas(drawArea.width(), drawArea.height());
+ nwayCanvas->translate(-drawArea.x(), -drawArea.y());
+ nwayCanvas->addCanvas(canvas);
+ nwayCanvas->addCanvas(prerender);
+ SkSafeUnref(canvas);
+ SkSafeUnref(prerender);
+ canvas = nwayCanvas;
+ }
+ }
+ WebCore::PlatformGraphicsContextSkia pgc(canvas);
+ WebCore::GraphicsContext gc(&pgc);
+ ALOGV("painting picture: " INT_RECT_FORMAT, INT_RECT_ARGS(drawArea));
+ painter->paintContents(&gc, drawArea);
+ SkSafeUnref(canvas);
+ picture->endRecording();
+ return picture;
+}
+#endif
+
} // namespace WebCore
diff --git a/Source/WebKit/android/jni/PicturePile.h b/Source/WebKit/android/jni/PicturePile.h
index b28a792..bdcf4f5 100644
--- a/Source/WebKit/android/jni/PicturePile.h
+++ b/Source/WebKit/android/jni/PicturePile.h
@@ -38,7 +38,17 @@
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Vector.h>
+#define USE_RECORDING_CONTEXT false
+#if USE_RECORDING_CONTEXT
+namespace WebCore {
+class GraphicsOperationCollection;
+}
+typedef WebCore::GraphicsOperationCollection Picture;
+#else
class SkPicture;
+typedef SkPicture Picture;
+#endif
+
class SkCanvas;
namespace WebCore {
@@ -57,7 +67,7 @@ public:
class PictureContainer {
public:
- SkPicture* picture;
+ Picture* picture;
IntRect area;
bool dirty;
RefPtr<PrerenderedInval> prerendered;
@@ -68,26 +78,14 @@ public:
, dirty(true)
{}
- PictureContainer(const PictureContainer& other)
- : picture(other.picture)
- , area(other.area)
- , dirty(other.dirty)
- , prerendered(other.prerendered)
- {
- SkSafeRef(picture);
- }
-
- ~PictureContainer()
- {
- SkSafeUnref(picture);
- }
+ PictureContainer(const PictureContainer& other);
+ ~PictureContainer();
};
class PicturePile {
public:
PicturePile() {}
PicturePile(const PicturePile& other);
- PicturePile(SkPicture* picture);
const IntSize& size() { return m_size; }
@@ -107,8 +105,10 @@ public:
private:
void applyWebkitInvals();
void updatePicture(PicturePainter* painter, PictureContainer& container);
+ Picture* recordPicture(PicturePainter* painter, PictureContainer& container);
void appendToPile(const IntRect& inval, const IntRect& originalInval = IntRect());
void drawWithClipRecursive(SkCanvas* canvas, SkRegion& clipRegion, int index);
+ void drawPicture(SkCanvas* canvas, PictureContainer& pc);
IntSize m_size;
Vector<PictureContainer> m_pile;