aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-08 19:38:21 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-08 19:38:21 +0000
commit0556ea0ede7066b9b3ed9f03f5a6eb72cd718897 (patch)
tree8afc8bdd79e7fda177938ad1084b02813371a670 /tools
parent6184c978b827c7350f085d0ba65cf03cd04eb85b (diff)
Add support for using ANGLE in bench_pictures.
BUG=https://code.google.com/p/skia/issues/detail?id=1012 Other cleanups: Remove setDeviceType from PictureBenchmark, since it is unnecessary. Dereference PictureRenderer::fGrContext when done with it. Make PictureRenderer::fGrContext and PictureRenderer::fGrContextFactory private, since they are not used by subclasses. Review URL: https://codereview.appspot.com/7314063 git-svn-id: http://skia.googlecode.com/svn/trunk@7677 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r--tools/PictureBenchmark.h6
-rw-r--r--tools/PictureRenderer.cpp53
-rw-r--r--tools/PictureRenderer.h105
-rw-r--r--tools/bench_pictures_main.cpp35
-rw-r--r--tools/render_pictures_main.cpp37
5 files changed, 185 insertions, 51 deletions
diff --git a/tools/PictureBenchmark.h b/tools/PictureBenchmark.h
index 01b4e1d886..b2764e0f79 100644
--- a/tools/PictureBenchmark.h
+++ b/tools/PictureBenchmark.h
@@ -45,12 +45,6 @@ public:
PictureRenderer* setRenderer(PictureRenderer*);
- void setDeviceType(PictureRenderer::SkDeviceTypes deviceType) {
- if (fRenderer != NULL) {
- fRenderer->setDeviceType(deviceType);
- }
- }
-
void setLogPerIter(bool log) { fLogPerIter = log; }
void setPrintMin(bool min) { fPrintMin = min; }
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index e2dd5f82c1..16768c79e2 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -107,13 +107,38 @@ SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
}
break;
#if SK_SUPPORT_GPU
+#if SK_ANGLE
+ case kAngle_DeviceType:
+ // fall through
+#endif
case kGPU_DeviceType: {
- SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice,
- (fGrContext, SkBitmap::kARGB_8888_Config,
- width, height)));
+ SkAutoTUnref<GrRenderTarget> rt;
+ bool grSuccess = false;
+ if (fGrContext) {
+ // create a render target to back the device
+ GrTextureDesc desc;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fFlags = kRenderTarget_GrTextureFlagBit;
+ desc.fWidth = width;
+ desc.fHeight = height;
+ desc.fSampleCnt = 0;
+ GrTexture* tex = fGrContext->createUncachedTexture(desc, NULL, 0);
+ if (tex) {
+ rt.reset(tex->asRenderTarget());
+ rt.get()->ref();
+ tex->unref();
+ grSuccess = NULL != rt.get();
+ }
+ }
+ if (!grSuccess) {
+ SkASSERT(0);
+ return NULL;
+ }
+
+ SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (fGrContext, rt)));
canvas = SkNEW_ARGS(SkCanvas, (device.get()));
+ break;
}
- break;
#endif
default:
SkASSERT(0);
@@ -175,19 +200,15 @@ void PictureRenderer::buildBBoxHierarchy() {
void PictureRenderer::resetState(bool callFinish) {
#if SK_SUPPORT_GPU
- if (this->isUsingGpuDevice()) {
- SkGLContext* glContext = fGrContextFactory.getGLContext(
- GrContextFactory::kNative_GLContextType);
-
- SkASSERT(glContext != NULL);
- if (NULL == glContext) {
- return;
- }
+ SkGLContext* glContext = this->getGLContext();
+ if (NULL == glContext) {
+ SkASSERT(kBitmap_DeviceType == fDeviceType);
+ return;
+ }
- fGrContext->flush();
- if (callFinish) {
- SK_GL(*glContext, Finish());
- }
+ fGrContext->flush();
+ if (callFinish) {
+ SK_GL(*glContext, Finish());
}
#endif
}
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;
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index b485aff21b..579830d639 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -130,6 +130,9 @@ static void usage(const char* argv0) {
" [--device bitmap"
#if SK_SUPPORT_GPU
" | gpu"
+#if SK_ANGLE
+" | angle"
+#endif
#endif
"]\n"
" [--filter [%s]:\n [%s]]\n"
@@ -204,6 +207,10 @@ static void usage(const char* argv0) {
#if SK_SUPPORT_GPU
SkDebugf(
" gpu, Render to the GPU.\n");
+#if SK_ANGLE
+ SkDebugf(
+" angle, Render using Angle.\n");
+#endif
#endif
SkDebugf("\n");
SkDebugf(
@@ -480,6 +487,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
}
#endif
+#if SK_ANGLE
+ else if (0 == strcmp(*argv, "angle")) {
+ deviceType = sk_tools::PictureRenderer::kAngle_DeviceType;
+ }
+#endif
else {
SkString err;
err.printf("%s is not a valid mode for --device\n", *argv);
@@ -701,13 +713,21 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
}
}
if (numThreads > 1) {
+ switch (deviceType) {
#if SK_SUPPORT_GPU
- if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
- tiledRenderer->unref();
- gLogger.logError("GPU not compatible with multithreaded tiling.\n");
- PRINT_USAGE_AND_EXIT;
- }
+ case sk_tools::PictureRenderer::kGPU_DeviceType:
+ // fall through
+#endif
+#if SK_ANGLE
+ case sk_tools::PictureRenderer::kAngle_DeviceType:
#endif
+ tiledRenderer->unref();
+ gLogger.logError("GPU not compatible with multithreaded tiling.\n");
+ PRINT_USAGE_AND_EXIT;
+ break;
+ default:
+ break;
+ }
}
renderer.reset(tiledRenderer);
if (usePipe) {
@@ -740,9 +760,12 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
renderer->setGridSize(gridWidth, gridHeight);
renderer->setViewport(viewport);
renderer->setScaleFactor(scaleFactor);
+ if (!renderer->setDeviceType(deviceType)) {
+ gLogger.logError("Invalid deviceType.\n");
+ PRINT_USAGE_AND_EXIT;
+ }
benchmark->setRenderer(renderer);
benchmark->setRepeats(repeats);
- benchmark->setDeviceType(deviceType);
benchmark->setLogger(&gLogger);
// Report current settings:
gLogger.logProgress(commandLine);
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index a459bf20a9..3ab5628e6c 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -40,6 +40,9 @@ static void usage(const char* argv0) {
#if SK_SUPPORT_GPU
" | gpu"
#endif
+#if SK_ANGLE
+" | angle"
+#endif
"]"
, argv0);
SkDebugf("\n\n");
@@ -111,6 +114,10 @@ static void usage(const char* argv0) {
SkDebugf(
" gpu, Render to the GPU.\n");
#endif
+#if SK_ANGLE
+ SkDebugf(
+" angle, Render using angle.\n");
+#endif
}
static void make_output_filepath(SkString* path, const SkString& dir,
@@ -518,6 +525,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
}
#endif
+#if SK_ANGLE
+ else if (0 == strcmp(*argv, "angle")) {
+ deviceType = sk_tools::PictureRenderer::kAngle_DeviceType;
+ }
+#endif
else {
SkSafeUnref(renderer);
SkDebugf("%s is not a valid mode for --device\n", *argv);
@@ -672,14 +684,22 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
}
}
if (numThreads > 1) {
+ switch (deviceType) {
#if SK_SUPPORT_GPU
- if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
- tiledRenderer->unref();
- SkDebugf("GPU not compatible with multithreaded tiling.\n");
- usage(argv0);
- exit(-1);
- }
+ case sk_tools::PictureRenderer::kGPU_DeviceType:
+ // fall through
+#endif
+#if SK_ANGLE
+ case sk_tools::PictureRenderer::kAngle_DeviceType:
#endif
+ tiledRenderer->unref();
+ SkDebugf("GPU not compatible with multithreaded tiling.\n");
+ usage(argv0);
+ exit(-1);
+ break;
+ default:
+ break;
+ }
}
renderer = tiledRenderer;
if (usePipe) {
@@ -713,7 +733,10 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
renderer->setGridSize(gridWidth, gridHeight);
renderer->setViewport(viewport);
renderer->setScaleFactor(scaleFactor);
- renderer->setDeviceType(deviceType);
+ if (!renderer->setDeviceType(deviceType)) {
+ SkDebugf("Invalid device type.\n");
+ exit(-1);
+ }
}
int tool_main(int argc, char** argv);