kPDF_Backend,
};
+class GLHelper {
+public:
+ GLHelper() {
+ }
+
+ bool init(SkGLContext* glCtx, int width, int height) {
+ GrContext* grCtx;
+ GrRenderTarget* rt;
+ if (glCtx->init(width, height)) {
+ GrPlatform3DContext ctx =
+ reinterpret_cast<GrPlatform3DContext>(glCtx->gl());
+ grCtx = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
+ if (NULL != grCtx) {
+ GrPlatformRenderTargetDesc desc;
+ desc.fConfig = kSkia8888_PM_GrPixelConfig;
+ desc.fWidth = width;
+ desc.fHeight = height;
+ desc.fStencilBits = 8;
+ desc.fRenderTargetHandle = glCtx->getFBOID();
+ rt = grCtx->createPlatformRenderTarget(desc);
+ if (NULL == rt) {
+ grCtx->unref();
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ glCtx->ref();
+ fGLContext.reset(glCtx);
+ fGrContext.reset(grCtx);
+ fRenderTarget.reset(rt);
+ return true;
+ }
+
+ bool isValid() {
+ return NULL != fGLContext.get();
+ }
+
+ SkGLContext* glContext() {
+ return fGLContext.get();
+ }
+
+ GrRenderTarget* renderTarget() {
+ return fRenderTarget.get();
+ }
+
+ GrContext* grContext() {
+ return fGrContext.get();
+ }
+private:
+ SkAutoTUnref<SkGLContext> fGLContext;
+ SkAutoTUnref<GrContext> fGrContext;
+ SkAutoTUnref<GrRenderTarget> fRenderTarget;
+};
+
+static GLHelper gRealGLHelper;
+static GLHelper gNullGLHelper;
+
static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size,
- Backend backend, GrContext* context,
- GrRenderTarget* rt) {
+ Backend backend, GLHelper* glHelper) {
SkDevice* device = NULL;
SkBitmap bitmap;
bitmap.setConfig(config, size.fX, size.fY);
device = new SkDevice(bitmap);
break;
case kGPU_Backend:
- device = new SkGpuDevice(context, rt);
-// device->clear(0xFFFFFFFF);
+ device = new SkGpuDevice(glHelper->grContext(),
+ glHelper->renderTarget());
break;
case kPDF_Backend:
default:
SkBitmap::Config fConfig;
const char* fName;
Backend fBackend;
+ GLHelper* fGLHelper;
} gConfigs[] = {
- { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend },
- { SkBitmap::kRGB_565_Config, "565", kRaster_Backend },
- { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend },
+ { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend, NULL },
+ { SkBitmap::kRGB_565_Config, "565", kRaster_Backend, NULL },
+ { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend, &gRealGLHelper },
+ { SkBitmap::kARGB_8888_Config, "NULLGPU", kGPU_Backend, &gNullGLHelper },
};
static int findConfig(const char config[]) {
bool doClip = false;
bool hasStrokeWidth = false;
float strokeWidth;
- bool useNullGL = false;
SkTDArray<const char*> fMatches;
SkString outDir;
SkBitmap::Config outConfig = SkBitmap::kNo_Config;
+ GLHelper* glHelper;
const char* configName = "";
Backend backend = kRaster_Backend; // for warning
int configCount = SK_ARRAY_COUNT(gConfigs);
outConfig = gConfigs[index].fConfig;
configName = gConfigs[index].fName;
backend = gConfigs[index].fBackend;
+ glHelper = gConfigs[index].fGLHelper;
configCount = 1;
} else {
SkString str;
log_error("incomplete '-Dfoo bar' definition\n");
return -1;
}
- } else if (strcmp(*argv, "-nullgl") == 0) {
- useNullGL = true;
} else {
SkString str;
str.printf("unrecognized arg %s\n", *argv);
str.append("\n");
log_progress(str);
}
-
- GrContext* context = NULL;
- GrRenderTarget* rt = NULL;
+
//Don't do GL when fixed.
- SkAutoTUnref<SkGLContext> glctx;
#if !defined(SK_SCALAR_IS_FIXED)
- if (useNullGL) {
- glctx.reset(new SkNullGLContext);
- } else {
- glctx.reset(new SkNativeGLContext);
- }
int contextWidth = 1024;
int contextHeight = 1024;
determine_gpu_context_size(defineDict, &contextWidth, &contextHeight);
- if (glctx.get()->init(contextWidth, contextHeight)) {
- GrPlatform3DContext ctx =
- reinterpret_cast<GrPlatform3DContext>(glctx.get()->gl());
- context = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
- if (NULL != context) {
- GrPlatformRenderTargetDesc desc;
- desc.fConfig = kSkia8888_PM_GrPixelConfig;
- desc.fWidth = contextWidth;
- desc.fHeight = contextHeight;
- desc.fStencilBits = 8;
- desc.fRenderTargetHandle = glctx.get()->getFBOID();
- rt = context->createPlatformRenderTarget(desc);
- if (NULL == rt) {
- context->unref();
- context = NULL;
- }
- }
- }
+ SkAutoTUnref<SkGLContext> realGLCtx(new SkNativeGLContext);
+ SkAutoTUnref<SkGLContext> nullGLCtx(new SkNullGLContext);
+ gRealGLHelper.init(realGLCtx.get(), contextWidth, contextHeight);
+ gNullGLHelper.init(nullGLCtx.get(), contextWidth, contextHeight);
#endif
- BenchTimer timer = BenchTimer(context ? glctx.get() : NULL);
+ BenchTimer timer = BenchTimer(gRealGLHelper.glContext());
Iter iter(&defineDict);
SkBenchmark* bench;
outConfig = gConfigs[configIndex].fConfig;
configName = gConfigs[configIndex].fName;
backend = gConfigs[configIndex].fBackend;
+ glHelper = gConfigs[configIndex].fGLHelper;
}
-
- if (kGPU_Backend == backend && NULL == context) {
+
+ if (kGPU_Backend == backend &&
+ (NULL == glHelper || !glHelper->isValid())) {
continue;
}
- SkDevice* device = make_device(outConfig, dim,
- backend, context, rt);
+ SkDevice* device = make_device(outConfig, dim, backend, glHelper);
SkCanvas canvas(device);
device->unref();
if (doRotate) {
performRotate(&canvas, dim.fX, dim.fY);
}
-
- bool gpu = kGPU_Backend == backend && context;
+
//warm up caches if needed
if (repeatDraw > 1) {
SkAutoCanvasRestore acr(&canvas, true);
bench->draw(&canvas);
-#if !defined(SK_SCALAR_IS_FIXED)
- if (gpu) {
- context->flush();
- SK_GL(*glctx.get(), Finish());
+ if (glHelper) {
+ glHelper->grContext()->flush();
+ SK_GL(*glHelper->glContext(), Finish());
}
-#endif
}
timer.start();
for (int i = 0; i < repeatDraw; i++) {
SkAutoCanvasRestore acr(&canvas, true);
bench->draw(&canvas);
- if (gpu) {
- context->flush();
+ if (glHelper) {
+ glHelper->grContext()->flush();
}
}
- #if !defined(SK_SCALAR_IS_FIXED)
- if (gpu) {
- SK_GL(*glctx.get(), Finish());
+ if (glHelper) {
+ SK_GL(*glHelper->glContext(), Finish());
}
- #endif
timer.end();
if (repeatDraw > 1) {
if (timerCpu) {
str.appendf(" cmsecs = %6.2f", timer.fCpu / repeatDraw);
}
- if (timerGpu && gpu && timer.fGpu > 0) {
+ if (timerGpu && glHelper && timer.fGpu > 0) {
str.appendf(" gmsecs = %6.2f", timer.fGpu / repeatDraw);
}
log_progress(str);
log_progress("\n");
}
- SkSafeUnref(context);
- SkSafeUnref(rt);
-
return 0;
}