2012-07-26 17:27:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PictureRenderer_DEFINED
|
|
|
|
#define PictureRenderer_DEFINED
|
2012-11-02 21:28:12 +00:00
|
|
|
|
|
|
|
#include "SkCountdown.h"
|
2012-08-23 20:53:25 +00:00
|
|
|
#include "SkMath.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "SkPicture.h"
|
2012-09-18 14:32:35 +00:00
|
|
|
#include "SkRect.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "SkRefCnt.h"
|
2012-11-02 21:28:12 +00:00
|
|
|
#include "SkRunnable.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "SkString.h"
|
2012-11-02 21:28:12 +00:00
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkThreadPool.h"
|
|
|
|
#include "SkTypes.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2012-08-20 15:03:33 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContextFactory.h"
|
|
|
|
#include "GrContext.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
class SkBitmap;
|
|
|
|
class SkCanvas;
|
2012-08-20 15:03:29 +00:00
|
|
|
class SkGLContext;
|
2012-11-02 21:28:12 +00:00
|
|
|
class SkThread;
|
2012-07-26 17:27:57 +00:00
|
|
|
|
|
|
|
namespace sk_tools {
|
|
|
|
|
|
|
|
class PictureRenderer : public SkRefCnt {
|
|
|
|
public:
|
2012-08-20 15:04:04 +00:00
|
|
|
enum SkDeviceTypes {
|
|
|
|
kBitmap_DeviceType,
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
kGPU_DeviceType
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-11-02 18:11:49 +00:00
|
|
|
enum BBoxHierarchyType {
|
|
|
|
kNone_BBoxHierarchyType = 0,
|
|
|
|
kRTree_BBoxHierarchyType,
|
2012-11-06 18:58:43 +00:00
|
|
|
kTileGrid_BBoxHierarchyType,
|
2012-11-02 18:11:49 +00:00
|
|
|
};
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
/**
|
|
|
|
* Called with each new SkPicture to render.
|
|
|
|
*/
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void init(SkPicture* pict);
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform any setup that should done prior to each iteration of render() which should not be
|
|
|
|
* timed.
|
|
|
|
*/
|
|
|
|
virtual void setup() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform work that is to be timed. Typically this is rendering, but is also used for recording
|
|
|
|
* and preparing picture for playback by the subclasses which do those.
|
2012-09-20 14:54:21 +00:00
|
|
|
* If path is non-null, subclass implementations should call write().
|
|
|
|
* @param path If non-null, also write the output to the file specified by path. path should
|
|
|
|
* have no extension; it will be added by write().
|
2012-10-26 13:26:55 +00:00
|
|
|
* @return bool True if rendering succeeded and, if path is non-null, the output was
|
|
|
|
* successfully written to a file.
|
2012-09-07 15:21:18 +00:00
|
|
|
*/
|
2012-09-20 14:54:21 +00:00
|
|
|
virtual bool render(const SkString* path) = 0;
|
2012-09-07 15:21:18 +00:00
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
/**
|
|
|
|
* Called once finished with a particular SkPicture, before calling init again, and before
|
|
|
|
* being done with this Renderer.
|
|
|
|
*/
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void end();
|
2012-11-02 21:28:12 +00:00
|
|
|
|
2012-08-20 15:04:15 +00:00
|
|
|
void resetState();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2012-08-20 15:04:04 +00:00
|
|
|
void setDeviceType(SkDeviceTypes deviceType) {
|
|
|
|
fDeviceType = deviceType;
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 18:11:49 +00:00
|
|
|
void setBBoxHierarchyType(BBoxHierarchyType bbhType) {
|
|
|
|
fBBoxHierarchyType = bbhType;
|
|
|
|
}
|
|
|
|
|
2012-11-06 18:58:43 +00:00
|
|
|
void setGridSize(int width, int height) {
|
|
|
|
fGridWidth = width;
|
|
|
|
fGridHeight = height;
|
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
bool isUsingBitmapDevice() {
|
2012-08-20 15:03:44 +00:00
|
|
|
return kBitmap_DeviceType == fDeviceType;
|
2012-08-20 15:03:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
virtual SkString getPerIterTimeFormat() { return SkString("%.2f"); }
|
|
|
|
|
|
|
|
virtual SkString getNormalTimeFormat() { return SkString("%6.2f"); }
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
/**
|
|
|
|
* Reports the configuration of this PictureRenderer.
|
|
|
|
*/
|
|
|
|
SkString getConfigName() {
|
|
|
|
SkString config = this->getConfigNameInternal();
|
|
|
|
if (kRTree_BBoxHierarchyType == fBBoxHierarchyType) {
|
|
|
|
config.append("_rtree");
|
2012-11-06 18:58:43 +00:00
|
|
|
} else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
|
|
|
|
config.append("_grid");
|
2012-11-02 22:01:26 +00:00
|
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (this->isUsingGpuDevice()) {
|
|
|
|
config.append("_gpu");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:29 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-08-20 15:03:41 +00:00
|
|
|
bool isUsingGpuDevice() {
|
2012-08-20 15:03:44 +00:00
|
|
|
return kGPU_DeviceType == fDeviceType;
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
2012-08-20 15:03:47 +00:00
|
|
|
|
|
|
|
SkGLContext* getGLContext() {
|
|
|
|
if (this->isUsingGpuDevice()) {
|
|
|
|
return fGrContextFactory.getGLContext(GrContextFactory::kNative_GLContextType);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-09-13 15:40:37 +00:00
|
|
|
|
|
|
|
GrContext* getGrContext() {
|
|
|
|
return fGrContext;
|
|
|
|
}
|
2012-08-20 15:03:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-20 15:03:36 +00:00
|
|
|
PictureRenderer()
|
2012-08-20 15:03:33 +00:00
|
|
|
: fPicture(NULL)
|
|
|
|
, fDeviceType(kBitmap_DeviceType)
|
2012-11-02 19:16:22 +00:00
|
|
|
, fBBoxHierarchyType(kNone_BBoxHierarchyType)
|
2012-11-06 18:58:43 +00:00
|
|
|
, fGridWidth(0)
|
|
|
|
, fGridHeight(0)
|
2012-08-20 15:03:33 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
, fGrContext(fGrContextFactory.get(GrContextFactory::kNative_GLContextType))
|
|
|
|
#endif
|
|
|
|
{}
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
protected:
|
2012-11-02 18:11:49 +00:00
|
|
|
void buildBBoxHierarchy();
|
|
|
|
SkPicture* createPicture();
|
|
|
|
uint32_t recordFlags();
|
2012-08-20 15:03:57 +00:00
|
|
|
SkCanvas* setupCanvas();
|
2012-09-20 14:42:33 +00:00
|
|
|
virtual SkCanvas* setupCanvas(int width, int height);
|
2012-08-20 15:03:57 +00:00
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
SkAutoTUnref<SkCanvas> fCanvas;
|
|
|
|
SkPicture* fPicture;
|
2012-08-20 15:03:29 +00:00
|
|
|
SkDeviceTypes fDeviceType;
|
2012-11-02 18:11:49 +00:00
|
|
|
BBoxHierarchyType fBBoxHierarchyType;
|
2012-11-06 18:58:43 +00:00
|
|
|
int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid
|
2012-08-20 15:03:33 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContextFactory fGrContextFactory;
|
|
|
|
GrContext* fGrContext;
|
|
|
|
#endif
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() = 0;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
/**
|
|
|
|
* This class does not do any rendering, but its render function executes recording, which we want
|
|
|
|
* to time.
|
|
|
|
*/
|
|
|
|
class RecordPictureRenderer : public PictureRenderer {
|
2012-09-20 14:54:21 +00:00
|
|
|
virtual bool render(const SkString*) SK_OVERRIDE;
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
|
|
|
|
|
|
|
|
virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
|
2012-11-02 22:01:26 +00:00
|
|
|
|
2012-11-06 16:54:40 +00:00
|
|
|
protected:
|
|
|
|
virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
|
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
private:
|
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
2012-09-07 15:21:18 +00:00
|
|
|
};
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
class PipePictureRenderer : public PictureRenderer {
|
2012-08-01 17:53:29 +00:00
|
|
|
public:
|
2012-09-20 14:54:21 +00:00
|
|
|
virtual bool render(const SkString*) SK_OVERRIDE;
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
typedef PictureRenderer INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SimplePictureRenderer : public PictureRenderer {
|
2012-08-01 17:53:29 +00:00
|
|
|
public:
|
2012-11-02 18:11:49 +00:00
|
|
|
virtual void init(SkPicture* pict) SK_OVERRIDE;
|
|
|
|
|
2012-09-20 14:54:21 +00:00
|
|
|
virtual bool render(const SkString*) SK_OVERRIDE;
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
typedef PictureRenderer INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TiledPictureRenderer : public PictureRenderer {
|
|
|
|
public:
|
|
|
|
TiledPictureRenderer();
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void init(SkPicture* pict) SK_OVERRIDE;
|
2012-09-20 14:54:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders to tiles, rather than a single canvas. If a path is provided, a separate file is
|
|
|
|
* created for each tile, named "path0.png", "path1.png", etc.
|
|
|
|
* Multithreaded mode currently does not support writing to a file.
|
|
|
|
*/
|
|
|
|
virtual bool render(const SkString* path) SK_OVERRIDE;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
virtual void end() SK_OVERRIDE;
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2012-07-27 20:09:26 +00:00
|
|
|
void setTileWidth(int width) {
|
|
|
|
fTileWidth = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTileWidth() const {
|
|
|
|
return fTileWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTileHeight(int height) {
|
|
|
|
fTileHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTileHeight() const {
|
|
|
|
return fTileHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTileWidthPercentage(double percentage) {
|
|
|
|
fTileWidthPercentage = percentage;
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
double getTileWidthPercentage() const {
|
2012-07-27 20:09:26 +00:00
|
|
|
return fTileWidthPercentage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTileHeightPercentage(double percentage) {
|
|
|
|
fTileHeightPercentage = percentage;
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
double getTileHeightPercentage() const {
|
2012-07-27 20:09:26 +00:00
|
|
|
return fTileHeightPercentage;
|
|
|
|
}
|
|
|
|
|
2012-08-23 20:53:25 +00:00
|
|
|
void setTileMinPowerOf2Width(int width) {
|
|
|
|
SkASSERT(SkIsPow2(width) && width > 0);
|
|
|
|
if (!SkIsPow2(width) || width <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fTileMinPowerOf2Width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTileMinPowerOf2Width() const {
|
|
|
|
return fTileMinPowerOf2Width;
|
|
|
|
}
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
protected:
|
|
|
|
SkTDArray<SkRect> fTileRects;
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkCanvas* setupCanvas(int width, int height) SK_OVERRIDE;
|
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
private:
|
2012-09-20 14:42:33 +00:00
|
|
|
int fTileWidth;
|
|
|
|
int fTileHeight;
|
|
|
|
double fTileWidthPercentage;
|
|
|
|
double fTileHeightPercentage;
|
|
|
|
int fTileMinPowerOf2Width;
|
|
|
|
|
2012-08-07 17:11:33 +00:00
|
|
|
void setupTiles();
|
2012-08-23 20:53:25 +00:00
|
|
|
void setupPowerOf2Tiles();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
typedef PictureRenderer INHERITED;
|
2012-07-26 17:27:57 +00:00
|
|
|
};
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
class CloneData;
|
|
|
|
|
|
|
|
class MultiCorePictureRenderer : public TiledPictureRenderer {
|
|
|
|
public:
|
|
|
|
explicit MultiCorePictureRenderer(int threadCount);
|
|
|
|
|
|
|
|
~MultiCorePictureRenderer();
|
|
|
|
|
|
|
|
virtual void init(SkPicture* pict) SK_OVERRIDE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Behaves like TiledPictureRenderer::render(), only using multiple threads.
|
|
|
|
*/
|
|
|
|
virtual bool render(const SkString* path) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void end() SK_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
2012-11-02 22:01:26 +00:00
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-11-02 21:28:12 +00:00
|
|
|
const int fNumThreads;
|
|
|
|
SkTDArray<SkCanvas*> fCanvasPool;
|
|
|
|
SkThreadPool fThreadPool;
|
|
|
|
SkPicture* fPictureClones;
|
|
|
|
CloneData** fCloneData;
|
|
|
|
SkCountdown fCountdown;
|
|
|
|
|
|
|
|
typedef TiledPictureRenderer INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
/**
|
|
|
|
* This class does not do any rendering, but its render function executes turning an SkPictureRecord
|
|
|
|
* into an SkPicturePlayback, which we want to time.
|
|
|
|
*/
|
|
|
|
class PlaybackCreationRenderer : public PictureRenderer {
|
|
|
|
public:
|
|
|
|
virtual void setup() SK_OVERRIDE;
|
|
|
|
|
2012-09-20 14:54:21 +00:00
|
|
|
virtual bool render(const SkString*) SK_OVERRIDE;
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
virtual SkString getPerIterTimeFormat() SK_OVERRIDE { return SkString("%.4f"); }
|
|
|
|
|
|
|
|
virtual SkString getNormalTimeFormat() SK_OVERRIDE { return SkString("%6.4f"); }
|
|
|
|
|
|
|
|
private:
|
2012-11-02 18:11:49 +00:00
|
|
|
SkAutoTUnref<SkPicture> fReplayer;
|
2012-11-02 22:01:26 +00:00
|
|
|
|
|
|
|
virtual SkString getConfigNameInternal() SK_OVERRIDE;
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
typedef PictureRenderer INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PictureRenderer_DEFINED
|