aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/PictureRenderer.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/PictureRenderer.h')
-rw-r--r--tools/PictureRenderer.h105
1 files changed, 89 insertions, 16 deletions
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index df38faa3de..b4b28f0f2f 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -39,9 +39,12 @@ class PictureRenderer : public SkRefCnt {
public:
enum SkDeviceTypes {
+#if SK_ANGLE
+ kAngle_DeviceType,
+#endif
kBitmap_DeviceType,
#if SK_SUPPORT_GPU
- kGPU_DeviceType
+ kGPU_DeviceType,
#endif
};
@@ -117,8 +120,44 @@ public:
*/
void resetState(bool callFinish);
- void setDeviceType(SkDeviceTypes deviceType) {
+ /**
+ * Set the backend type. Returns true on success and false on failure.
+ */
+ bool setDeviceType(SkDeviceTypes deviceType) {
fDeviceType = deviceType;
+#if SK_SUPPORT_GPU
+ // In case this function is called more than once
+ SkSafeUnref(fGrContext);
+ fGrContext = NULL;
+ // Set to Native so it will have an initial value.
+ GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType;
+#endif
+ switch(deviceType) {
+ case kBitmap_DeviceType:
+ return true;
+#if SK_SUPPORT_GPU
+ case kGPU_DeviceType:
+ // Already set to GrContextFactory::kNative_GLContextType, above.
+ break;
+#if SK_ANGLE
+ case kAngle_DeviceType:
+ glContextType = GrContextFactory::kANGLE_GLContextType;
+ break;
+#endif
+#endif
+ default:
+ // Invalid device type.
+ return false;
+ }
+#if SK_SUPPORT_GPU
+ fGrContext = fGrContextFactory.get(glContextType);
+ if (NULL == fGrContext) {
+ return false;
+ } else {
+ fGrContext->ref();
+ return true;
+ }
+#endif
}
void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
@@ -156,26 +195,55 @@ public:
} else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
config.append("_grid");
}
+ switch (fDeviceType) {
#if SK_SUPPORT_GPU
- if (this->isUsingGpuDevice()) {
- config.append("_gpu");
- }
+ case kGPU_DeviceType:
+ config.append("_gpu");
+ break;
+#if SK_ANGLE
+ case kAngle_DeviceType:
+ config.append("_angle");
+ break;
+#endif
#endif
+ default:
+ // Assume that no extra info means bitmap.
+ break;
+ }
config.append(fDrawFiltersConfig.c_str());
return config;
}
#if SK_SUPPORT_GPU
bool isUsingGpuDevice() {
- return kGPU_DeviceType == fDeviceType;
+ switch (fDeviceType) {
+ case kGPU_DeviceType:
+ // fall through
+#if SK_ANGLE
+ case kAngle_DeviceType:
+#endif
+ return true;
+ default:
+ return false;
+ }
}
SkGLContext* getGLContext() {
- if (this->isUsingGpuDevice()) {
- return fGrContextFactory.getGLContext(GrContextFactory::kNative_GLContextType);
- } else {
- return NULL;
+ GrContextFactory::GLContextType glContextType
+ = GrContextFactory::kNull_GLContextType;
+ switch(fDeviceType) {
+ case kGPU_DeviceType:
+ glContextType = GrContextFactory::kNative_GLContextType;
+ break;
+#if SK_ANGLE
+ case kAngle_DeviceType:
+ glContextType = GrContextFactory::kANGLE_GLContextType;
+ break;
+#endif
+ default:
+ return NULL;
}
+ return fGrContextFactory.getGLContext(glContextType);
}
GrContext* getGrContext() {
@@ -190,7 +258,7 @@ public:
, fGridWidth(0)
, fGridHeight(0)
#if SK_SUPPORT_GPU
- , fGrContext(fGrContextFactory.get(GrContextFactory::kNative_GLContextType))
+ , fGrContext(NULL)
#endif
, fScaleFactor(SK_Scalar1)
{
@@ -198,6 +266,12 @@ public:
fViewport.set(0, 0);
}
+#if SK_SUPPORT_GPU
+ virtual ~PictureRenderer() {
+ SkSafeUnref(fGrContext);
+ }
+#endif
+
protected:
SkAutoTUnref<SkCanvas> fCanvas;
SkPicture* fPicture;
@@ -207,11 +281,6 @@ protected:
SkString fDrawFiltersConfig;
int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid
-#if SK_SUPPORT_GPU
- GrContextFactory fGrContextFactory;
- GrContext* fGrContext;
-#endif
-
void buildBBoxHierarchy();
/**
@@ -239,6 +308,10 @@ protected:
private:
SkISize fViewport;
SkScalar fScaleFactor;
+#if SK_SUPPORT_GPU
+ GrContextFactory fGrContextFactory;
+ GrContext* fGrContext;
+#endif
virtual SkString getConfigNameInternal() = 0;