From 145d1c0fdcef63991d7f910cc067a653a8aa2c4c Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Sun, 16 Mar 2014 19:46:36 +0000 Subject: 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)). Committed: http://code.google.com/p/skia/source/detail?r=13810 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@13822 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkCanvas.h | 8 ++++++++ include/core/SkDevice.h | 18 ++++++++++++++++++ include/core/SkPicture.h | 40 +++++++++++++++++++++++++++++++++++++--- include/gpu/SkGpuDevice.h | 9 +++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 716720bc3e..7fd21352a4 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -962,6 +962,14 @@ public: const SkPath& path, const SkMatrix* matrix, const SkPaint& paint); + /** PRIVATE / EXPERIMENTAL -- do not call + Perform back-end analysis/optimization of a picture. This may attach + optimization data to the picture which can be used by a later + drawPicture call. + @param picture The recorded drawing commands to analyze/optimize + */ + void EXPERIMENTAL_optimize(SkPicture* picture); + /** Draw the picture into this canvas. This method effective brackets the playback of the picture's draw calls with save/restore, so the state of this canvas will be unchanged after this call. diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 2d9b0fc43b..7161bb141d 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -423,6 +423,24 @@ protected: */ SkDeviceProperties fLeakyProperties; + /** + * PRIVATE / EXPERIMENTAL -- do not call + * Construct an acceleration object and attach it to 'picture' + */ + virtual void EXPERIMENTAL_optimize(SkPicture* picture); + + /** + * PRIVATE / EXPERIMENTAL -- do not call + * This entry point gives the backend an opportunity to take over the rendering + * of 'picture'. If optimization data is available (due to an earlier + * 'optimize' call) this entry point should make use of it and return true + * if all rendering has been done. If false is returned, SkCanvas will + * perform its own rendering pass. It is acceptable for the backend + * to perform some device-specific warm up tasks and then let SkCanvas + * perform the main rendering loop (by return false from here). + */ + virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture); + private: friend class SkCanvas; friend struct DeviceCM; //for setMatrixClip diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index ef6f4a2063..8fa777792f 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -34,6 +34,27 @@ class SK_API SkPicture : public SkRefCnt { public: SK_DECLARE_INST_COUNT(SkPicture) + // AccelData provides a base class for device-specific acceleration + // data. It is added to the picture via a call to a device's optimize + // method. + class AccelData : public SkRefCnt { + public: + typedef uint8_t Domain; + typedef uint32_t Key; + + AccelData(Key key) : fKey(key) { } + + const Key& getKey() const { return fKey; } + + // This entry point allows user's to get a unique domain prefix + // for their keys + static Domain GenerateDomain(); + private: + Key fKey; + + typedef SkRefCnt INHERITED; + }; + /** The constructor prepares the picture to record. @param width the width of the virtual device the picture records. @param height the height of the virtual device the picture records. @@ -44,6 +65,18 @@ public: */ SkPicture(const SkPicture& src); + /** PRIVATE / EXPERIMENTAL -- do not call */ + void EXPERIMENTAL_addAccelData(const AccelData* data) { + SkRefCnt_SafeAssign(fAccelData, data); + } + /** PRIVATE / EXPERIMENTAL -- do not call */ + const AccelData* EXPERIMENTAL_getAccelData(AccelData::Key key) const { + if (NULL != fAccelData && fAccelData->getKey() == key) { + return fAccelData; + } + return NULL; + } + /** * Function signature defining a function that sets up an SkBitmap from encoded data. On * success, the SkBitmap should have its Config, width, height, rowBytes and pixelref set. @@ -262,9 +295,10 @@ protected: // fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to // install their own SkPicturePlayback-derived players,SkPictureRecord-derived // recorders and set the picture size - SkPicturePlayback* fPlayback; - SkPictureRecord* fRecord; - int fWidth, fHeight; + SkPicturePlayback* fPlayback; + SkPictureRecord* fRecord; + int fWidth, fHeight; + const AccelData* fAccelData; // Create a new SkPicture from an existing SkPicturePlayback. Ref count of // playback is unchanged. diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index f8ee7817bc..7394361ff1 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -14,6 +14,7 @@ #include "SkGr.h" #include "SkBitmap.h" #include "SkBitmapDevice.h" +#include "SkPicture.h" #include "SkRegion.h" #include "GrContext.h" @@ -146,10 +147,16 @@ public: class SkAutoCachedTexture; // used internally + protected: virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE; virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE; + /** PRIVATE / EXPERIMENTAL -- do not call */ + virtual void EXPERIMENTAL_optimize(SkPicture* picture) SK_OVERRIDE; + /** PRIVATE / EXPERIMENTAL -- do not call */ + virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture) SK_OVERRIDE; + private: GrContext* fContext; @@ -215,6 +222,8 @@ private: int tileSize, bool bicubic); + static SkPicture::AccelData::Key ComputeAccelDataKey(); + typedef SkBitmapDevice INHERITED; }; -- cgit v1.2.3