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
This commit is contained in:
scroggo@google.com 2013-02-08 19:38:21 +00:00
parent 6184c978b8
commit 0556ea0ede
5 changed files with 185 additions and 51 deletions

View File

@ -45,12 +45,6 @@ public:
PictureRenderer* setRenderer(PictureRenderer*); PictureRenderer* setRenderer(PictureRenderer*);
void setDeviceType(PictureRenderer::SkDeviceTypes deviceType) {
if (fRenderer != NULL) {
fRenderer->setDeviceType(deviceType);
}
}
void setLogPerIter(bool log) { fLogPerIter = log; } void setLogPerIter(bool log) { fLogPerIter = log; }
void setPrintMin(bool min) { fPrintMin = min; } void setPrintMin(bool min) { fPrintMin = min; }

View File

@ -107,13 +107,38 @@ SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
} }
break; break;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#if SK_ANGLE
case kAngle_DeviceType:
// fall through
#endif
case kGPU_DeviceType: { case kGPU_DeviceType: {
SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, SkAutoTUnref<GrRenderTarget> rt;
(fGrContext, SkBitmap::kARGB_8888_Config, bool grSuccess = false;
width, height))); 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())); canvas = SkNEW_ARGS(SkCanvas, (device.get()));
break;
} }
break;
#endif #endif
default: default:
SkASSERT(0); SkASSERT(0);
@ -175,19 +200,15 @@ void PictureRenderer::buildBBoxHierarchy() {
void PictureRenderer::resetState(bool callFinish) { void PictureRenderer::resetState(bool callFinish) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (this->isUsingGpuDevice()) { SkGLContext* glContext = this->getGLContext();
SkGLContext* glContext = fGrContextFactory.getGLContext( if (NULL == glContext) {
GrContextFactory::kNative_GLContextType); SkASSERT(kBitmap_DeviceType == fDeviceType);
return;
}
SkASSERT(glContext != NULL); fGrContext->flush();
if (NULL == glContext) { if (callFinish) {
return; SK_GL(*glContext, Finish());
}
fGrContext->flush();
if (callFinish) {
SK_GL(*glContext, Finish());
}
} }
#endif #endif
} }

View File

@ -39,9 +39,12 @@ class PictureRenderer : public SkRefCnt {
public: public:
enum SkDeviceTypes { enum SkDeviceTypes {
#if SK_ANGLE
kAngle_DeviceType,
#endif
kBitmap_DeviceType, kBitmap_DeviceType,
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
kGPU_DeviceType kGPU_DeviceType,
#endif #endif
}; };
@ -117,8 +120,44 @@ public:
*/ */
void resetState(bool callFinish); 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; 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) { void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
@ -156,26 +195,55 @@ public:
} else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) { } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
config.append("_grid"); config.append("_grid");
} }
switch (fDeviceType) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (this->isUsingGpuDevice()) { case kGPU_DeviceType:
config.append("_gpu"); config.append("_gpu");
} break;
#if SK_ANGLE
case kAngle_DeviceType:
config.append("_angle");
break;
#endif #endif
#endif
default:
// Assume that no extra info means bitmap.
break;
}
config.append(fDrawFiltersConfig.c_str()); config.append(fDrawFiltersConfig.c_str());
return config; return config;
} }
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
bool isUsingGpuDevice() { 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() { SkGLContext* getGLContext() {
if (this->isUsingGpuDevice()) { GrContextFactory::GLContextType glContextType
return fGrContextFactory.getGLContext(GrContextFactory::kNative_GLContextType); = GrContextFactory::kNull_GLContextType;
} else { switch(fDeviceType) {
return NULL; 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() { GrContext* getGrContext() {
@ -190,7 +258,7 @@ public:
, fGridWidth(0) , fGridWidth(0)
, fGridHeight(0) , fGridHeight(0)
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
, fGrContext(fGrContextFactory.get(GrContextFactory::kNative_GLContextType)) , fGrContext(NULL)
#endif #endif
, fScaleFactor(SK_Scalar1) , fScaleFactor(SK_Scalar1)
{ {
@ -198,6 +266,12 @@ public:
fViewport.set(0, 0); fViewport.set(0, 0);
} }
#if SK_SUPPORT_GPU
virtual ~PictureRenderer() {
SkSafeUnref(fGrContext);
}
#endif
protected: protected:
SkAutoTUnref<SkCanvas> fCanvas; SkAutoTUnref<SkCanvas> fCanvas;
SkPicture* fPicture; SkPicture* fPicture;
@ -207,11 +281,6 @@ protected:
SkString fDrawFiltersConfig; SkString fDrawFiltersConfig;
int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid int fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid
#if SK_SUPPORT_GPU
GrContextFactory fGrContextFactory;
GrContext* fGrContext;
#endif
void buildBBoxHierarchy(); void buildBBoxHierarchy();
/** /**
@ -239,6 +308,10 @@ protected:
private: private:
SkISize fViewport; SkISize fViewport;
SkScalar fScaleFactor; SkScalar fScaleFactor;
#if SK_SUPPORT_GPU
GrContextFactory fGrContextFactory;
GrContext* fGrContext;
#endif
virtual SkString getConfigNameInternal() = 0; virtual SkString getConfigNameInternal() = 0;

View File

@ -130,6 +130,9 @@ static void usage(const char* argv0) {
" [--device bitmap" " [--device bitmap"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
" | gpu" " | gpu"
#if SK_ANGLE
" | angle"
#endif
#endif #endif
"]\n" "]\n"
" [--filter [%s]:\n [%s]]\n" " [--filter [%s]:\n [%s]]\n"
@ -204,6 +207,10 @@ static void usage(const char* argv0) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
SkDebugf( SkDebugf(
" gpu, Render to the GPU.\n"); " gpu, Render to the GPU.\n");
#if SK_ANGLE
SkDebugf(
" angle, Render using Angle.\n");
#endif
#endif #endif
SkDebugf("\n"); SkDebugf("\n");
SkDebugf( SkDebugf(
@ -479,6 +486,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
else if (0 == strcmp(*argv, "gpu")) { else if (0 == strcmp(*argv, "gpu")) {
deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
} }
#endif
#if SK_ANGLE
else if (0 == strcmp(*argv, "angle")) {
deviceType = sk_tools::PictureRenderer::kAngle_DeviceType;
}
#endif #endif
else { else {
SkString err; SkString err;
@ -701,13 +713,21 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
} }
} }
if (numThreads > 1) { if (numThreads > 1) {
switch (deviceType) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) { case sk_tools::PictureRenderer::kGPU_DeviceType:
tiledRenderer->unref(); // fall through
gLogger.logError("GPU not compatible with multithreaded tiling.\n");
PRINT_USAGE_AND_EXIT;
}
#endif #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); renderer.reset(tiledRenderer);
if (usePipe) { if (usePipe) {
@ -740,9 +760,12 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
renderer->setGridSize(gridWidth, gridHeight); renderer->setGridSize(gridWidth, gridHeight);
renderer->setViewport(viewport); renderer->setViewport(viewport);
renderer->setScaleFactor(scaleFactor); renderer->setScaleFactor(scaleFactor);
if (!renderer->setDeviceType(deviceType)) {
gLogger.logError("Invalid deviceType.\n");
PRINT_USAGE_AND_EXIT;
}
benchmark->setRenderer(renderer); benchmark->setRenderer(renderer);
benchmark->setRepeats(repeats); benchmark->setRepeats(repeats);
benchmark->setDeviceType(deviceType);
benchmark->setLogger(&gLogger); benchmark->setLogger(&gLogger);
// Report current settings: // Report current settings:
gLogger.logProgress(commandLine); gLogger.logProgress(commandLine);

View File

@ -40,6 +40,9 @@ static void usage(const char* argv0) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
" | gpu" " | gpu"
#endif #endif
#if SK_ANGLE
" | angle"
#endif
"]" "]"
, argv0); , argv0);
SkDebugf("\n\n"); SkDebugf("\n\n");
@ -111,6 +114,10 @@ static void usage(const char* argv0) {
SkDebugf( SkDebugf(
" gpu, Render to the GPU.\n"); " gpu, Render to the GPU.\n");
#endif #endif
#if SK_ANGLE
SkDebugf(
" angle, Render using angle.\n");
#endif
} }
static void make_output_filepath(SkString* path, const SkString& dir, static void make_output_filepath(SkString* path, const SkString& dir,
@ -517,6 +524,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
else if (0 == strcmp(*argv, "gpu")) { else if (0 == strcmp(*argv, "gpu")) {
deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
} }
#endif
#if SK_ANGLE
else if (0 == strcmp(*argv, "angle")) {
deviceType = sk_tools::PictureRenderer::kAngle_DeviceType;
}
#endif #endif
else { else {
SkSafeUnref(renderer); SkSafeUnref(renderer);
@ -672,14 +684,22 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
} }
} }
if (numThreads > 1) { if (numThreads > 1) {
switch (deviceType) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) { case sk_tools::PictureRenderer::kGPU_DeviceType:
tiledRenderer->unref(); // fall through
SkDebugf("GPU not compatible with multithreaded tiling.\n");
usage(argv0);
exit(-1);
}
#endif #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; renderer = tiledRenderer;
if (usePipe) { if (usePipe) {
@ -713,7 +733,10 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
renderer->setGridSize(gridWidth, gridHeight); renderer->setGridSize(gridWidth, gridHeight);
renderer->setViewport(viewport); renderer->setViewport(viewport);
renderer->setScaleFactor(scaleFactor); renderer->setScaleFactor(scaleFactor);
renderer->setDeviceType(deviceType); if (!renderer->setDeviceType(deviceType)) {
SkDebugf("Invalid device type.\n");
exit(-1);
}
} }
int tool_main(int argc, char** argv); int tool_main(int argc, char** argv);