aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-14 18:23:12 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-14 18:23:12 +0000
commit1ab85c8719ef46a8f2de9912b3f84f387bddf0d1 (patch)
treef43e6468e0a7801ff73ca7e7554d007f1978950f /src
parent118252962f89a80db661a0544f1bd61cbaab6321 (diff)
Proposed SkCanvas API for preLoading textures to VRAM v2.0
This is an update to (Proposed SkCanvas API for preLoading textures to VRAM - https://codereview.chromium.org/192853002/). It takes into account in-person feedback on the initial proposal. The main feedback was to land this closer to where we will ultimately wind up with the reordered rendering capability (and don't have an SkCanvas entry point (yet)). R=reed@google.com, bsalomon@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/197123003 git-svn-id: http://skia.googlecode.com/svn/trunk@13810 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkCanvas.cpp15
-rw-r--r--src/core/SkDevice.cpp9
-rw-r--r--src/core/SkPicture.cpp29
-rw-r--r--src/gpu/SkGpuDevice.cpp42
4 files changed, 90 insertions, 5 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 4ac7b29826..f2200a6d8d 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2461,8 +2461,23 @@ void SkCanvas::drawTextOnPathHV(const void* text, size_t byteLength,
}
///////////////////////////////////////////////////////////////////////////////
+void SkCanvas::EXPERIMENTAL_optimize(SkPicture* picture) {
+ SkBaseDevice* device = this->getDevice();
+ if (NULL != device) {
+ device->EXPERIMENTAL_optimize(picture);
+ }
+}
void SkCanvas::drawPicture(SkPicture& picture) {
+ SkBaseDevice* device = this->getTopDevice();
+ if (NULL != device) {
+ // Canvas has to first give the device the opportunity to render
+ // the picture itself.
+ if (device->EXPERIMENTAL_drawPicture(picture)) {
+ return; // the device has rendered the entire picture
+ }
+ }
+
picture.draw(this);
}
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 587181302d..3cfe89cfec 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -213,3 +213,12 @@ void* SkBaseDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) {
#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
void SkBaseDevice::writePixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) {}
#endif
+
+void SkBaseDevice::EXPERIMENTAL_optimize(SkPicture* picture) {
+ // The base class doesn't perform any analysis but derived classes may
+}
+
+bool SkBaseDevice::EXPERIMENTAL_drawPicture(const SkPicture& picture) {
+ // The base class doesn't perform any accelerated picture rendering
+ return false;
+}
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 9270236572..92311f3a3a 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -117,9 +117,12 @@ SkPicture::SkPicture() {
fRecord = NULL;
fPlayback = NULL;
fWidth = fHeight = 0;
+ fAccelData = NULL;
}
-SkPicture::SkPicture(const SkPicture& src) : INHERITED() {
+SkPicture::SkPicture(const SkPicture& src)
+ : INHERITED()
+ , fAccelData(NULL) {
fWidth = src.fWidth;
fHeight = src.fHeight;
fRecord = NULL;
@@ -141,6 +144,7 @@ SkPicture::SkPicture(const SkPicture& src) : INHERITED() {
SkPicture::~SkPicture() {
SkSafeUnref(fRecord);
SkDELETE(fPlayback);
+ SkSafeUnref(fAccelData);
}
void SkPicture::internalOnly_EnableOpts(bool enableOpts) {
@@ -152,6 +156,7 @@ void SkPicture::internalOnly_EnableOpts(bool enableOpts) {
void SkPicture::swap(SkPicture& other) {
SkTSwap(fRecord, other.fRecord);
SkTSwap(fPlayback, other.fPlayback);
+ SkTSwap(fAccelData, other.fAccelData);
SkTSwap(fWidth, other.fWidth);
SkTSwap(fHeight, other.fHeight);
}
@@ -188,6 +193,17 @@ void SkPicture::clone(SkPicture* pictures, int count) const {
}
}
+SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
+ static int32_t gNextID = 0;
+
+ int32_t id = sk_atomic_inc(&gNextID);
+ if (id >= 1 << (8 * sizeof(Domain))) {
+ SK_CRASH();
+ }
+
+ return static_cast<Domain>(id);
+}
+
///////////////////////////////////////////////////////////////////////////////
SkCanvas* SkPicture::beginRecording(int width, int height,
@@ -196,7 +212,7 @@ SkCanvas* SkPicture::beginRecording(int width, int height,
SkDELETE(fPlayback);
fPlayback = NULL;
}
-
+ SkSafeUnref(fAccelData);
SkSafeSetNull(fRecord);
// Must be set before calling createBBoxHierarchy
@@ -250,7 +266,7 @@ void SkPicture::endRecording() {
void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) {
this->endRecording();
- if (fPlayback) {
+ if (NULL != fPlayback) {
fPlayback->draw(*surface, callback);
}
}
@@ -310,7 +326,8 @@ SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
: fPlayback(playback)
, fRecord(NULL)
, fWidth(width)
- , fHeight(height) {}
+ , fHeight(height)
+ , fAccelData(NULL) {}
SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
SkPictInfo info;
@@ -418,7 +435,9 @@ void SkPicture::flatten(SkWriteBuffer& buffer) const {
}
bool SkPicture::willPlayBackBitmaps() const {
- if (!fPlayback) return false;
+ if (!fPlayback) {
+ return false;
+ }
return fPlayback->containsBitmaps();
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index e872f1ac97..a86170b75e 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -25,6 +25,7 @@
#include "SkImageFilter.h"
#include "SkMaskFilter.h"
#include "SkPathEffect.h"
+#include "SkPicture.h"
#include "SkRRect.h"
#include "SkStroke.h"
#include "SkSurface.h"
@@ -2003,3 +2004,44 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
this->initFromRenderTarget(context, texture->asRenderTarget(), true);
fNeedClear = needClear;
}
+
+class GPUAccelData : public SkPicture::AccelData {
+public:
+ GPUAccelData(Key key) : INHERITED(key) { }
+
+protected:
+
+private:
+ typedef SkPicture::AccelData INHERITED;
+};
+
+// In the future this may not be a static method if we need to incorporate the
+// clip and matrix state into the key
+SkPicture::AccelData::Key SkGpuDevice::ComputeAccelDataKey() {
+ static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::GenerateDomain();
+
+ return gGPUID;
+}
+
+void SkGpuDevice::EXPERIMENTAL_optimize(SkPicture* picture) {
+ SkPicture::AccelData::Key key = ComputeAccelDataKey();
+
+ GPUAccelData* data = SkNEW_ARGS(GPUAccelData, (key));
+
+ picture->EXPERIMENTAL_addAccelData(data);
+}
+
+bool SkGpuDevice::EXPERIMENTAL_drawPicture(const SkPicture& picture) {
+ SkPicture::AccelData::Key key = ComputeAccelDataKey();
+
+ const SkPicture::AccelData* data = picture.EXPERIMENTAL_getAccelData(key);
+ if (NULL == data) {
+ return false;
+ }
+
+#if 0
+ const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data);
+#endif
+
+ return false;
+}