Basic error checking for debugger GL widget.

Currently the debugger segfaults if the GL context cannot be created.
This change allows the debugger to build with GL support, but still run if the
GL context cannot be created at runtime.

R=robertphillips@google.com

Review URL: https://codereview.chromium.org/18275002

git-svn-id: http://skia.googlecode.com/svn/trunk@9834 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bungeman@google.com 2013-07-01 13:54:10 +00:00
parent 637d24c18e
commit 0b4d6b289c

View File

@ -29,6 +29,9 @@ SkGLWidget::~SkGLWidget() {
void SkGLWidget::initializeGL() {
fCurIntf = GrGLCreateNativeInterface();
if (!fCurIntf) {
return;
}
fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf);
GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height());
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
@ -43,19 +46,21 @@ void SkGLWidget::initializeGL() {
}
void SkGLWidget::resizeGL(int w, int h) {
GrBackendRenderTargetDesc desc = this->getDesc(w, h);
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
SkSafeUnref(fGpuDevice);
SkSafeUnref(fCanvas);
fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget);
fCanvas = new SkCanvas(fGpuDevice);
if (fCurContext) {
GrBackendRenderTargetDesc desc = this->getDesc(w, h);
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
SkSafeUnref(fGpuDevice);
SkSafeUnref(fCanvas);
fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget);
fCanvas = new SkCanvas(fGpuDevice);
}
fDebugger->resize(w, h);
draw();
}
void SkGLWidget::paintGL() {
if (!this->isHidden()) {
if (!this->isHidden() && fCanvas) {
fDebugger->draw(fCanvas);
// TODO(chudy): Implement an optional flush button in Gui.
fCanvas->flush();