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.
*/
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
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.
*/
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.
// 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.
#include "SkGr.h"
#include "SkBitmap.h"
#include "SkBitmapDevice.h"
+#include "SkPicture.h"
#include "SkRegion.h"
#include "GrContext.h"
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;
int tileSize,
bool bicubic);
+ static SkPicture::AccelData::Key ComputeAccelDataKey();
+
typedef SkBitmapDevice INHERITED;
};
}
///////////////////////////////////////////////////////////////////////////////
+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);
}
#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;
+}
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;
SkPicture::~SkPicture() {
SkSafeUnref(fRecord);
SkDELETE(fPlayback);
+ SkSafeUnref(fAccelData);
}
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);
}
}
}
+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,
SkDELETE(fPlayback);
fPlayback = NULL;
}
-
+ SkSafeUnref(fAccelData);
SkSafeSetNull(fRecord);
// Must be set before calling createBBoxHierarchy
void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) {
this->endRecording();
- if (fPlayback) {
+ if (NULL != fPlayback) {
fPlayback->draw(*surface, callback);
}
}
: fPlayback(playback)
, fRecord(NULL)
, fWidth(width)
- , fHeight(height) {}
+ , fHeight(height)
+ , fAccelData(NULL) {}
SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
SkPictInfo info;
}
bool SkPicture::willPlayBackBitmaps() const {
- if (!fPlayback) return false;
+ if (!fPlayback) {
+ return false;
+ }
return fPlayback->containsBitmaps();
}
#include "SkImageFilter.h"
#include "SkMaskFilter.h"
#include "SkPathEffect.h"
+#include "SkPicture.h"
#include "SkRRect.h"
#include "SkStroke.h"
#include "SkSurface.h"
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;
+}
}
/**
- * Draw the specified playback to the canvas translated to rectangle provided, so that this mini
+ * Draw the specified picture to the canvas translated to rectangle provided, so that this mini
* canvas represents the rectangle's portion of the overall picture.
* Saves and restores so that the initial clip and matrix return to their state before this function
* is called.
*/
-template<class T>
-static void DrawTileToCanvas(SkCanvas* canvas, const SkRect& tileRect, T* playback) {
+static void draw_tile_to_canvas(SkCanvas* canvas, const SkRect& tileRect, SkPicture* picture) {
int saveCount = canvas->save();
// Translate so that we draw the correct portion of the picture.
// Perform a postTranslate so that the scaleFactor does not interfere with the positioning.
SkMatrix mat(canvas->getTotalMatrix());
mat.postTranslate(-tileRect.fLeft, -tileRect.fTop);
canvas->setMatrix(mat);
- playback->draw(canvas);
+ canvas->drawPicture(*picture);
canvas->restoreToCount(saveCount);
canvas->flush();
}
void TiledPictureRenderer::drawCurrentTile() {
SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count());
- DrawTileToCanvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture);
+ draw_tile_to_canvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture);
}
bool TiledPictureRenderer::render(const SkString* path, SkBitmap** out) {
}
bool success = true;
for (int i = 0; i < fTileRects.count(); ++i) {
- DrawTileToCanvas(fCanvas, fTileRects[i], fPicture);
+ draw_tile_to_canvas(fCanvas, fTileRects[i], fPicture);
if (NULL != path) {
success &= writeAppendNumber(fCanvas, path, i, fJsonSummaryPtr);
}
}
for (int i = fStart; i < fEnd; i++) {
- DrawTileToCanvas(fCanvas, fRects[i], fClone);
+ draw_tile_to_canvas(fCanvas, fRects[i], fClone);
if ((fPath != NULL) && !writeAppendNumber(fCanvas, fPath, i, fJsonSummaryPtr)
&& fSuccess != NULL) {
*fSuccess = false;
}
#endif
+ SkCanvas* getCanvas() {
+ return fCanvas;
+ }
+
PictureRenderer()
: fPicture(NULL)
, fJsonSummaryPtr(NULL)
DEFINE_bool(bench_record, false, "If true, drop into an infinite loop of recording the picture.");
+DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before rendering.");
+
static void make_output_filepath(SkString* path, const SkString& dir,
const SkString& name) {
sk_tools::make_filepath(path, dir, name);
inputPath.c_str());
renderer.init(picture);
+
+ if (FLAGS_preprocess) {
+ if (NULL != renderer.getCanvas()) {
+ renderer.getCanvas()->EXPERIMENTAL_optimize(picture);
+ }
+ }
+
renderer.setup();
SkString* outputPath = NULL;