summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/jni
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-06-19 17:32:14 -0700
committerJohn Reck <jreck@google.com>2012-06-19 17:32:14 -0700
commit4d764bbae987791f0b30d46d6ed918b0e1158d3d (patch)
treed8bdd10edeceb9f7cbb1435abd770c4e44c0ca93 /Source/WebKit/android/jni
parent0fa6f02d0a638887ca39f881f852c6d2e23bb374 (diff)
downloadexternal_webkit-4d764bbae987791f0b30d46d6ed918b0e1158d3d.zip
external_webkit-4d764bbae987791f0b30d46d6ed918b0e1158d3d.tar.gz
external_webkit-4d764bbae987791f0b30d46d6ed918b0e1158d3d.tar.bz2
Support recording context in PicturePile
Change-Id: I920d4b967542354136b7f0102ec01c3386a3450a
Diffstat (limited to 'Source/WebKit/android/jni')
-rw-r--r--Source/WebKit/android/jni/PicturePile.cpp136
-rw-r--r--Source/WebKit/android/jni/PicturePile.h30
2 files changed, 103 insertions, 63 deletions
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;