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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 SkGLWidget::~SkGLWidget() { | 23 SkGLWidget::~SkGLWidget() { |
24 SkSafeUnref(fCurIntf); | 24 SkSafeUnref(fCurIntf); |
25 SkSafeUnref(fCurContext); | 25 SkSafeUnref(fCurContext); |
26 SkSafeUnref(fGpuDevice); | 26 SkSafeUnref(fGpuDevice); |
27 SkSafeUnref(fCanvas); | 27 SkSafeUnref(fCanvas); |
28 } | 28 } |
29 | 29 |
30 void SkGLWidget::initializeGL() { | 30 void SkGLWidget::initializeGL() { |
31 fCurIntf = GrGLCreateNativeInterface(); | 31 fCurIntf = GrGLCreateNativeInterface(); |
| 32 if (!fCurIntf) { |
| 33 return; |
| 34 } |
32 fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIn
tf); | 35 fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIn
tf); |
33 GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()
); | 36 GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()
); |
34 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 37 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
35 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc)
; | 38 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc)
; |
36 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); | 39 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); |
37 fCanvas = new SkCanvas(fGpuDevice); | 40 fCanvas = new SkCanvas(fGpuDevice); |
38 curRenderTarget->unref(); | 41 curRenderTarget->unref(); |
39 | 42 |
40 glClearColor(1, 1, 1, 0); | 43 glClearColor(1, 1, 1, 0); |
41 glClearStencil(0); | 44 glClearStencil(0); |
42 glClear(GL_STENCIL_BUFFER_BIT); | 45 glClear(GL_STENCIL_BUFFER_BIT); |
43 } | 46 } |
44 | 47 |
45 void SkGLWidget::resizeGL(int w, int h) { | 48 void SkGLWidget::resizeGL(int w, int h) { |
46 GrBackendRenderTargetDesc desc = this->getDesc(w, h); | 49 if (fCurContext) { |
47 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 50 GrBackendRenderTargetDesc desc = this->getDesc(w, h); |
48 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(desc)
; | 51 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
49 SkSafeUnref(fGpuDevice); | 52 GrRenderTarget* curRenderTarget = fCurContext->wrapBackendRenderTarget(d
esc); |
50 SkSafeUnref(fCanvas); | 53 SkSafeUnref(fGpuDevice); |
51 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); | 54 SkSafeUnref(fCanvas); |
52 fCanvas = new SkCanvas(fGpuDevice); | 55 fGpuDevice = new SkGpuDevice(fCurContext, curRenderTarget); |
| 56 fCanvas = new SkCanvas(fGpuDevice); |
| 57 } |
53 fDebugger->resize(w, h); | 58 fDebugger->resize(w, h); |
54 draw(); | 59 draw(); |
55 } | 60 } |
56 | 61 |
57 void SkGLWidget::paintGL() { | 62 void SkGLWidget::paintGL() { |
58 if (!this->isHidden()) { | 63 if (!this->isHidden() && fCanvas) { |
59 fDebugger->draw(fCanvas); | 64 fDebugger->draw(fCanvas); |
60 // TODO(chudy): Implement an optional flush button in Gui. | 65 // TODO(chudy): Implement an optional flush button in Gui. |
61 fCanvas->flush(); | 66 fCanvas->flush(); |
62 emit drawComplete(); | 67 emit drawComplete(); |
63 } | 68 } |
64 } | 69 } |
65 | 70 |
66 GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) { | 71 GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) { |
67 GrBackendRenderTargetDesc desc; | 72 GrBackendRenderTargetDesc desc; |
68 desc.fWidth = SkScalarRound(this->width()); | 73 desc.fWidth = SkScalarRound(this->width()); |
69 desc.fHeight = SkScalarRound(this->height()); | 74 desc.fHeight = SkScalarRound(this->height()); |
70 desc.fConfig = kSkia8888_GrPixelConfig; | 75 desc.fConfig = kSkia8888_GrPixelConfig; |
71 GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); | 76 GR_GL_GetIntegerv(fCurIntf, GR_GL_SAMPLES, &desc.fSampleCnt); |
72 GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); | 77 GR_GL_GetIntegerv(fCurIntf, GR_GL_STENCIL_BITS, &desc.fStencilBits); |
73 GrGLint buffer; | 78 GrGLint buffer; |
74 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 79 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
75 desc.fRenderTargetHandle = buffer; | 80 desc.fRenderTargetHandle = buffer; |
76 | 81 |
77 return desc; | 82 return desc; |
78 } | 83 } |
79 | 84 |
80 #endif | 85 #endif |
OLD | NEW |