skia2/debugger/QT/SkGLWidget.cpp
bsalomon@google.com 16e3ddea6a Platform/Engine -> Backend
createPlatform -> wrapBackend

R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6785044

git-svn-id: http://skia.googlecode.com/svn/trunk@6123 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-10-25 18:43:28 +00:00

75 lines
2.2 KiB
C++

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkGLWidget.h"
SkGLWidget::SkGLWidget(SkDebugger* debugger) : QGLWidget() {
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
fDebugger = debugger;
fCurIntf = NULL;
fCurContext = NULL;
fGpuDevice = NULL;
fCanvas = NULL;
}
SkGLWidget::~SkGLWidget() {
SkSafeUnref(fCurIntf);
SkSafeUnref(fCurContext);
SkSafeUnref(fGpuDevice);
SkSafeUnref(fCanvas);
}
void SkGLWidget::initializeGL() {
fCurIntf = GrGLCreateNativeInterface();
fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf);
GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height());
GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget);
fCanvas = new SkCanvas(fGpuDevice);
curRenderTarget->unref();
glClearColor(1, 1, 1, 0);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
}
void SkGLWidget::resizeGL(int w, int h) {
GrBackendRenderTargetDesc desc = this->getDesc(w, h);
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()) {
fDebugger->draw(fCanvas);
// TODO(chudy): Implement an optional flush button in Gui.
fCanvas->flush();
emit drawComplete();
}
}
GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) {
GrBackendRenderTargetDesc desc;
desc.fWidth = SkScalarRound(this->width());
desc.fHeight = SkScalarRound(this->height());
desc.fConfig = kSkia8888_PM_GrPixelConfig;
GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt);
GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits);
GrGLint buffer;
GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer);
desc.fRenderTargetHandle = buffer;
return desc;
}