aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-27 20:44:19 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-27 20:44:19 +0000
commit74913722bfe5e4b6810545891958e3d8e9c63791 (patch)
treec4f68f38b2fb4bd104d2d619f735033024598770 /samplecode
parent9381363050ec9d3e724076a8e9152bfa9a8de1d1 (diff)
Add NULL GL context implementation. Use in bench (-nullgl) and SampleApp (backspace key)
Review URL: http://codereview.appspot.com/5303080/ git-svn-id: http://skia.googlecode.com/svn/trunk@2545 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleApp.cpp88
-rw-r--r--samplecode/SampleApp.h7
2 files changed, 77 insertions, 18 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 441d2fa396..b0d471ded3 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -82,26 +82,40 @@ public:
fGrRenderTarget = NULL;
fGrContext = NULL;
fGL = NULL;
+ fNullGrContext = NULL;
+ fNullGrRenderTarget = NULL;
}
virtual ~DefaultDeviceManager() {
SkSafeUnref(fGrRenderTarget);
SkSafeUnref(fGrContext);
SkSafeUnref(fGL);
+ SkSafeUnref(fNullGrContext);
+ SkSafeUnref(fNullGrRenderTarget);
}
virtual void init(SampleWindow* win) {
- win->attachGL();
- if (NULL == fGrContext) {
- fGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, NULL);
+ if (!win->attachGL()) {
+ SkDebugf("Failed to initialize GL");
}
if (NULL == fGL) {
- fGL = GrGLDefaultInterface();
+ fGL = GrGLCreateNativeInterface();
+ GrAssert(NULL == fGrContext);
+ fGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine,
+ (GrPlatform3DContext) fGL);
}
if (NULL == fGrContext || NULL == fGL) {
+ SkSafeUnref(fGrContext);
+ SkSafeUnref(fGL);
SkDebugf("Failed to setup 3D");
win->detachGL();
}
+ if (NULL == fNullGrContext) {
+ const GrGLInterface* nullGL = GrGLCreateNullInterface();
+ fNullGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine,
+ (GrPlatform3DContext) nullGL);
+ nullGL->unref();
+ }
}
virtual bool supportsDeviceType(SampleWindow::DeviceType dType) {
@@ -111,6 +125,8 @@ public:
return true;
case kGPU_DeviceType:
return NULL != fGrContext && NULL != fGrRenderTarget;
+ case kNullGPU_DeviceType:
+ return NULL != fNullGrContext && NULL != fNullGrRenderTarget;
default:
return false;
}
@@ -119,13 +135,23 @@ public:
virtual bool prepareCanvas(SampleWindow::DeviceType dType,
SkCanvas* canvas,
SampleWindow* win) {
- if (kGPU_DeviceType == dType) {
- if (fGrContext) {
- canvas->setDevice(new SkGpuDevice(fGrContext,
- fGrRenderTarget))->unref();
- } else {
- return false;
- }
+ switch (dType) {
+ case kGPU_DeviceType:
+ if (fGrContext) {
+ canvas->setDevice(new SkGpuDevice(fGrContext,
+ fGrRenderTarget))->unref();
+ } else {
+ return false;
+ }
+ break;
+ case kNullGPU_DeviceType:
+ if (fNullGrContext) {
+ canvas->setDevice(new SkGpuDevice(fNullGrContext,
+ fNullGrRenderTarget))->unref();
+ } else {
+ return false;
+ }
+ break;
}
return true;
}
@@ -136,7 +162,11 @@ public:
if (fGrContext) {
// in case we have queued drawing calls
fGrContext->flush();
- if (dType != kGPU_DeviceType) {
+ if (NULL != fNullGrContext) {
+ fNullGrContext->flush();
+ }
+ if (dType != kGPU_DeviceType &&
+ dType != kNullGPU_DeviceType) {
// need to send the raster bits to the (gpu) window
fGrContext->setRenderTarget(fGrRenderTarget);
const SkBitmap& bm = win->getBitmap();
@@ -168,15 +198,34 @@ public:
fGrRenderTarget = static_cast<GrRenderTarget*>(
fGrContext->createPlatformSurface(desc));
}
+ if (NULL != fNullGrContext) {
+ GrPlatformSurfaceDesc desc;
+ desc.reset();
+ desc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType;
+ desc.fWidth = SkScalarRound(win->width());
+ desc.fHeight = SkScalarRound(win->height());
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ desc.fStencilBits = 8;
+ desc.fSampleCnt = 0;
+ desc.fPlatformRenderTarget = 0;
+ fNullGrRenderTarget = static_cast<GrRenderTarget*>(
+ fNullGrContext->createPlatformSurface(desc));
+ }
}
- virtual GrContext* getGrContext() {
- return fGrContext;
+ virtual GrContext* getGrContext(SampleWindow::DeviceType dType) {
+ if (kNullGPU_DeviceType == dType) {
+ return fNullGrContext;
+ } else {
+ return fGrContext;
+ }
}
private:
GrContext* fGrContext;
const GrGLInterface* fGL;
GrRenderTarget* fGrRenderTarget;
+ GrContext* fNullGrContext;
+ GrRenderTarget* fNullGrRenderTarget;
};
///////////////
@@ -410,6 +459,7 @@ static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
static const SampleWindow::DeviceType gCT[] = {
SampleWindow::kPicture_DeviceType,
SampleWindow::kGPU_DeviceType,
+ SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal cycling
SampleWindow::kRaster_DeviceType
};
return gCT[ct];
@@ -1340,6 +1390,13 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
this->inval(NULL);
this->updateTitle();
return true;
+ case '\\':
+ if (fDevManager->supportsDeviceType(kNullGPU_DeviceType)) {
+ fDeviceType= kNullGPU_DeviceType;
+ this->inval(NULL);
+ this->updateTitle();
+ }
+ return true;
case 's':
fScale = !fScale;
this->inval(NULL);
@@ -1550,7 +1607,8 @@ static const char* configToString(SkBitmap::Config c) {
static const char* gDeviceTypePrefix[] = {
"raster: ",
"picture: ",
- "opengl: "
+ "opengl: ",
+ "null-gl: "
};
static const char* trystate_str(SkOSMenu::TriState state,
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 1d7e66b98b..dba022abc4 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -35,7 +35,8 @@ public:
enum DeviceType {
kRaster_DeviceType,
kPicture_DeviceType,
- kGPU_DeviceType
+ kGPU_DeviceType,
+ kNullGPU_DeviceType
};
/**
* SampleApp ports can subclass this manager class if they want to:
@@ -70,7 +71,7 @@ public:
virtual void windowSizeChanged(SampleWindow* win) = 0;
// return the GrContext backing gpu devices
- virtual GrContext* getGrContext() = 0;
+ virtual GrContext* getGrContext(DeviceType dType) = 0;
};
SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
@@ -84,7 +85,7 @@ public:
void toggleFPS();
void showOverview();
- GrContext* getGrContext() const { return fDevManager->getGrContext(); }
+ GrContext* getGrContext() const { return fDevManager->getGrContext(fDeviceType); }
void setZoomCenter(float x, float y);
void changeZoomLevel(float delta);