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*);
void setDeviceType(PictureRenderer::SkDeviceTypes deviceType) {
if (fRenderer != NULL) {
fRenderer->setDeviceType(deviceType);
}
}
void setLogPerIter(bool log) { fLogPerIter = log; }
void setPrintMin(bool min) { fPrintMin = min; }

View File

@ -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);
SkGLContext* glContext = this->getGLContext();
if (NULL == glContext) {
SkASSERT(kBitmap_DeviceType == fDeviceType);
return;
}
SkASSERT(glContext != NULL);
if (NULL == glContext) {
return;
}
fGrContext->flush();
if (callFinish) {
SK_GL(*glContext, Finish());
}
fGrContext->flush();
if (callFinish) {
SK_GL(*glContext, Finish());
}
#endif
}

View File

@ -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;

View File

@ -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(
@ -479,6 +486,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
else if (0 == strcmp(*argv, "gpu")) {
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;
@ -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);

View File

@ -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,
@ -517,6 +524,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
else if (0 == strcmp(*argv, "gpu")) {
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);
@ -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);