OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkGLWidget.h" | 10 #include "SkGLWidget.h" |
11 | 11 |
12 #if SK_SUPPORT_GPU | 12 #if SK_SUPPORT_GPU |
13 | 13 |
14 SkGLWidget::SkGLWidget(SkDebugger* debugger) : QGLWidget() { | 14 SkGLWidget::SkGLWidget(SkDebugger* debugger) : QGLWidget() { |
15 this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cc
cccc;}"); | |
16 fDebugger = debugger; | 15 fDebugger = debugger; |
17 fCurIntf = NULL; | 16 fCurIntf = NULL; |
18 fCurContext = NULL; | 17 fCurContext = NULL; |
19 fGpuDevice = NULL; | 18 fGpuDevice = NULL; |
20 fCanvas = NULL; | 19 fCanvas = NULL; |
21 } | 20 } |
22 | 21 |
23 SkGLWidget::~SkGLWidget() { | 22 SkGLWidget::~SkGLWidget() { |
24 SkSafeUnref(fCurIntf); | 23 SkSafeUnref(fCurIntf); |
25 SkSafeUnref(fCurContext); | 24 SkSafeUnref(fCurContext); |
26 SkSafeUnref(fGpuDevice); | 25 SkSafeUnref(fGpuDevice); |
27 SkSafeUnref(fCanvas); | 26 SkSafeUnref(fCanvas); |
28 } | 27 } |
29 | 28 |
30 void SkGLWidget::setSampleCount(int sampleCount) | 29 void SkGLWidget::setSampleCount(int sampleCount) |
31 { | 30 { |
32 QGLFormat currentFormat = format(); | 31 QGLFormat currentFormat = format(); |
33 currentFormat.setSampleBuffers(sampleCount > 0); | 32 currentFormat.setSampleBuffers(sampleCount > 0); |
34 currentFormat.setSamples(sampleCount); | 33 currentFormat.setSamples(sampleCount); |
35 setFormat(currentFormat); | 34 setFormat(currentFormat); |
36 } | 35 } |
37 | 36 |
38 void SkGLWidget::initializeGL() { | 37 void SkGLWidget::initializeGL() { |
39 fCurIntf = GrGLCreateNativeInterface(); | 38 fCurIntf = GrGLCreateNativeInterface(); |
40 if (!fCurIntf) { | 39 if (!fCurIntf) { |
41 return; | 40 return; |
42 } | 41 } |
| 42 glStencilMask(0xffffffff); |
| 43 glClearStencil(0); |
| 44 glClear(GL_STENCIL_BUFFER_BIT); |
| 45 |
43 fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIn
tf); | 46 fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIn
tf); |
44 GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()
); | 47 GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()
); |
45 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 48 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
46 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc)
; | 49 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc)
; |
47 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); | 50 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); |
48 fCanvas = new SkCanvas(fGpuDevice); | 51 fCanvas = new SkCanvas(fGpuDevice); |
49 curRenderTarget->unref(); | 52 curRenderTarget->unref(); |
50 | |
51 glClearColor(1, 1, 1, 0); | |
52 glClearStencil(0); | |
53 glClear(GL_STENCIL_BUFFER_BIT); | |
54 } | 53 } |
55 | 54 |
56 void SkGLWidget::resizeGL(int w, int h) { | 55 void SkGLWidget::resizeGL(int w, int h) { |
57 if (fCurContext) { | 56 if (fCurContext) { |
| 57 glDisable(GL_SCISSOR_TEST); |
| 58 glStencilMask(0xffffffff); |
| 59 glClearStencil(0); |
| 60 glClear(GL_STENCIL_BUFFER_BIT); |
| 61 fCurContext->resetContext(); |
| 62 |
58 GrBackendRenderTargetDesc desc = this->getDesc(w, h); | 63 GrBackendRenderTargetDesc desc = this->getDesc(w, h); |
59 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 64 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
60 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(d
esc); | 65 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(d
esc); |
61 SkSafeUnref(fGpuDevice); | 66 SkSafeUnref(fGpuDevice); |
62 SkSafeUnref(fCanvas); | 67 SkSafeUnref(fCanvas); |
63 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); | 68 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); |
64 fCanvas = new SkCanvas(fGpuDevice); | 69 fCanvas = new SkCanvas(fGpuDevice); |
65 } | 70 } |
66 fDebugger->resize(w, h); | 71 fDebugger->resize(w, h); |
67 draw(); | 72 draw(); |
(...skipping 16 matching lines...) Expand all Loading... |
84 GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); | 89 GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); |
85 GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); | 90 GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); |
86 GrGLint buffer; | 91 GrGLint buffer; |
87 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 92 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
88 desc.fRenderTargetHandle = buffer; | 93 desc.fRenderTargetHandle = buffer; |
89 | 94 |
90 return desc; | 95 return desc; |
91 } | 96 } |
92 | 97 |
93 #endif | 98 #endif |
OLD | NEW |