2012-07-26 19:38:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2012-08-07 16:12:23 +00:00
|
|
|
SkGLWidget::SkGLWidget(SkDebugger* debugger) : QGLWidget() {
|
2012-07-26 19:38:22 +00:00
|
|
|
this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}");
|
2012-08-07 16:12:23 +00:00
|
|
|
fDebugger = debugger;
|
2012-07-31 12:49:52 +00:00
|
|
|
fCurIntf = NULL;
|
|
|
|
fCurContext = NULL;
|
|
|
|
fGpuDevice = NULL;
|
2012-08-01 15:57:52 +00:00
|
|
|
fCanvas = NULL;
|
2012-07-26 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkGLWidget::~SkGLWidget() {
|
|
|
|
SkSafeUnref(fCurIntf);
|
|
|
|
SkSafeUnref(fCurContext);
|
|
|
|
SkSafeUnref(fGpuDevice);
|
2012-08-01 15:57:52 +00:00
|
|
|
SkSafeUnref(fCanvas);
|
2012-07-26 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkGLWidget::initializeGL() {
|
|
|
|
fCurIntf = GrGLCreateNativeInterface();
|
|
|
|
fCurContext = GrContext::Create(kOpenGL_Shaders_GrEngine, (GrPlatform3DContext) fCurIntf);
|
|
|
|
GrRenderTarget* curRenderTarget = fCurContext->createPlatformRenderTarget(getDesc(this->width(), this->height()));
|
|
|
|
fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget);
|
2012-08-01 15:57:52 +00:00
|
|
|
fCanvas = new SkCanvas(fGpuDevice);
|
2012-07-26 19:38:22 +00:00
|
|
|
curRenderTarget->unref();
|
|
|
|
|
|
|
|
glClearColor(1, 1, 1, 0);
|
|
|
|
glClearStencil(0);
|
|
|
|
glClear(GL_STENCIL_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkGLWidget::resizeGL(int w, int h) {
|
|
|
|
GrRenderTarget* curRenderTarget = fCurContext->createPlatformRenderTarget(getDesc(w,h));
|
|
|
|
SkSafeUnref(fGpuDevice);
|
2012-08-01 15:57:52 +00:00
|
|
|
SkSafeUnref(fCanvas);
|
2012-07-26 19:38:22 +00:00
|
|
|
fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget);
|
2012-08-01 15:57:52 +00:00
|
|
|
fCanvas = new SkCanvas(fGpuDevice);
|
2012-08-07 16:12:23 +00:00
|
|
|
fDebugger->resize(w, h);
|
|
|
|
draw();
|
2012-07-26 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkGLWidget::paintGL() {
|
2012-08-07 16:12:23 +00:00
|
|
|
if (!this->isHidden()) {
|
|
|
|
fDebugger->draw(fCanvas);
|
|
|
|
// TODO(chudy): Implement an optional flush button in Gui.
|
|
|
|
fCanvas->flush();
|
|
|
|
emit drawComplete();
|
|
|
|
}
|
2012-07-26 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GrPlatformRenderTargetDesc SkGLWidget::getDesc(int w, int h) {
|
|
|
|
GrPlatformRenderTargetDesc 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;
|
|
|
|
}
|