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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 if (!fCurIntf) { | 32 if (!fCurIntf) { |
33 return; | 33 return; |
34 } | 34 } |
35 // The call may come multiple times, for example after setSampleCount(). Th
e QGLContext will be | 35 // The call may come multiple times, for example after setSampleCount(). Th
e QGLContext will be |
36 // different, but we do not have a mechanism to catch the destroying of QGLC
ontext, so that | 36 // different, but we do not have a mechanism to catch the destroying of QGLC
ontext, so that |
37 // proper resource cleanup could be made. | 37 // proper resource cleanup could be made. |
38 if (fCurContext) { | 38 if (fCurContext) { |
39 fCurContext->abandonContext(); | 39 fCurContext->abandonContext(); |
40 } | 40 } |
41 fGpuDevice.reset(nullptr); | 41 |
42 fCanvas.reset(nullptr); | 42 fGpuSurface = nullptr; |
| 43 fCanvas = nullptr; |
43 | 44 |
44 fCurContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fC
urIntf.get())); | 45 fCurContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fC
urIntf.get())); |
45 } | 46 } |
46 | 47 |
47 void SkGLWidget::createRenderTarget() { | 48 void SkGLWidget::createRenderTarget() { |
48 if (!fCurContext) { | 49 if (!fCurContext) { |
49 return; | 50 return; |
50 } | 51 } |
51 | 52 |
52 glDisable(GL_SCISSOR_TEST); | 53 glDisable(GL_SCISSOR_TEST); |
53 glStencilMask(0xffffffff); | 54 glStencilMask(0xffffffff); |
54 glClearStencil(0); | 55 glClearStencil(0); |
55 glClear(GL_STENCIL_BUFFER_BIT); | 56 glClear(GL_STENCIL_BUFFER_BIT); |
56 fCurContext->resetContext(); | 57 fCurContext->resetContext(); |
57 | 58 |
58 fGpuDevice.reset(nullptr); | |
59 fCanvas.reset(nullptr); | |
60 | |
61 GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()
); | 59 GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()
); |
62 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 60 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
63 sk_sp<GrRenderTarget> curRenderTarget( | 61 |
64 fCurContext->textureProvider()->wrapBackendRenderTarget(desc)); | 62 fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext, desc, null
ptr); |
65 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 63 fCanvas = fGpuSurface->getCanvas(); |
66 fGpuDevice.reset(SkGpuDevice::Make(std::move(curRenderTarget), nullptr, &pro
ps, | |
67 SkGpuDevice::kUninit_InitContents).releas
e()); | |
68 fCanvas.reset(new SkCanvas(fGpuDevice)); | |
69 } | 64 } |
70 | 65 |
71 void SkGLWidget::resizeGL(int w, int h) { | 66 void SkGLWidget::resizeGL(int w, int h) { |
72 SkASSERT(w == this->width() && h == this->height()); | 67 SkASSERT(w == this->width() && h == this->height()); |
73 this->createRenderTarget(); | 68 this->createRenderTarget(); |
74 } | 69 } |
75 | 70 |
76 void SkGLWidget::paintGL() { | 71 void SkGLWidget::paintGL() { |
77 if (!this->isHidden() && fCanvas) { | 72 if (!this->isHidden() && fCanvas) { |
78 fCurContext->resetContext(); | 73 fCurContext->resetContext(); |
79 fDebugger->draw(fCanvas.get()); | 74 fDebugger->draw(fCanvas); |
80 // TODO(chudy): Implement an optional flush button in Gui. | 75 // TODO(chudy): Implement an optional flush button in Gui. |
81 fCanvas->flush(); | 76 fCanvas->flush(); |
82 Q_EMIT drawComplete(); | 77 Q_EMIT drawComplete(); |
83 } | 78 } |
84 } | 79 } |
85 | 80 |
86 GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) { | 81 GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) { |
87 GrBackendRenderTargetDesc desc; | 82 GrBackendRenderTargetDesc desc; |
88 desc.fWidth = SkScalarRoundToInt(this->width()); | 83 desc.fWidth = SkScalarRoundToInt(this->width()); |
89 desc.fHeight = SkScalarRoundToInt(this->height()); | 84 desc.fHeight = SkScalarRoundToInt(this->height()); |
90 desc.fConfig = kSkia8888_GrPixelConfig; | 85 desc.fConfig = kSkia8888_GrPixelConfig; |
91 GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); | 86 GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); |
92 GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); | 87 GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); |
93 GrGLint buffer; | 88 GrGLint buffer; |
94 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 89 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
95 desc.fRenderTargetHandle = buffer; | 90 desc.fRenderTargetHandle = buffer; |
96 | 91 |
97 return desc; | 92 return desc; |
98 } | 93 } |
99 | 94 |
100 #endif | 95 #endif |
OLD | NEW |