OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 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 #include "gl/SkGLContextHelper.h" | 8 #include "gl/SkGLContextHelper.h" |
9 #include "GrGLUtil.h" | 9 #include "GrGLUtil.h" |
10 | 10 |
11 SkGLContextHelper::SkGLContextHelper() | 11 SkGLContextHelper::SkGLContextHelper() |
12 : fFBO(0) | 12 : fFBO(0) |
13 , fColorBufferID(0) | 13 , fColorBufferID(0) |
14 , fDepthStencilBufferID(0) | 14 , fDepthStencilBufferID(0) |
15 , fGL(NULL) { | 15 , fGL(NULL) { |
16 } | 16 } |
17 | 17 |
18 SkGLContextHelper::~SkGLContextHelper() { | 18 SkGLContextHelper::~SkGLContextHelper() { |
19 | 19 |
20 if (fGL) { | 20 if (fGL) { |
21 // TODO: determine why DeleteFramebuffers is generating a GL error in te
sts | 21 // TODO: determine why DeleteFramebuffers is generating a GL error in te
sts |
22 SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO)); | 22 SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO)); |
23 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fColorBufferID)); | 23 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fColorBufferID)); |
24 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID)); | 24 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID)); |
25 } | 25 } |
26 | 26 |
27 SkSafeUnref(fGL); | 27 SkSafeUnref(fGL); |
28 } | 28 } |
29 | 29 |
| 30 extern int gBindFrameBufferCount; |
| 31 |
30 bool SkGLContextHelper::init(GrGLStandard forcedGpuAPI, int width, | 32 bool SkGLContextHelper::init(GrGLStandard forcedGpuAPI, int width, |
31 int height) { | 33 int height) { |
32 if (fGL) { | 34 if (fGL) { |
33 fGL->unref(); | 35 fGL->unref(); |
34 this->destroyGLContext(); | 36 this->destroyGLContext(); |
35 } | 37 } |
36 | 38 |
37 fGL = this->createGLContext(forcedGpuAPI); | 39 fGL = this->createGLContext(forcedGpuAPI); |
38 if (fGL) { | 40 if (fGL) { |
39 const GrGLubyte* temp; | 41 const GrGLubyte* temp; |
40 | 42 |
41 if (!fGL->validate()) { | 43 if (!fGL->validate()) { |
42 fGL = NULL; | 44 fGL = NULL; |
43 this->destroyGLContext(); | 45 this->destroyGLContext(); |
44 return false; | 46 return false; |
45 } | 47 } |
46 | 48 |
47 SK_GL_RET(*this, temp, GetString(GR_GL_VERSION)); | 49 SK_GL_RET(*this, temp, GetString(GR_GL_VERSION)); |
48 const char* versionStr = reinterpret_cast<const char*>(temp); | 50 const char* versionStr = reinterpret_cast<const char*>(temp); |
49 GrGLVersion version = GrGLGetVersionFromString(versionStr); | 51 GrGLVersion version = GrGLGetVersionFromString(versionStr); |
50 | 52 |
51 // clear any existing GL erorrs | 53 // clear any existing GL erorrs |
52 GrGLenum error; | 54 GrGLenum error; |
53 do { | 55 do { |
54 SK_GL_RET(*this, error, GetError()); | 56 SK_GL_RET(*this, error, GetError()); |
55 } while (GR_GL_NO_ERROR != error); | 57 } while (GR_GL_NO_ERROR != error); |
56 | 58 |
57 SK_GL(*this, GenFramebuffers(1, &fFBO)); | 59 SK_GL(*this, GenFramebuffers(1, &fFBO)); |
| 60 gBindFrameBufferCount++; |
58 SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); | 61 SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); |
59 SK_GL(*this, GenRenderbuffers(1, &fColorBufferID)); | 62 SK_GL(*this, GenRenderbuffers(1, &fColorBufferID)); |
60 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID)); | 63 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID)); |
61 if (kGLES_GrGLStandard == this->gl()->fStandard) { | 64 if (kGLES_GrGLStandard == this->gl()->fStandard) { |
62 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, | 65 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, |
63 GR_GL_RGBA8, | 66 GR_GL_RGBA8, |
64 width, height)); | 67 width, height)); |
65 } else { | 68 } else { |
66 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, | 69 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, |
67 GR_GL_RGBA, | 70 GR_GL_RGBA, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 136 } |
134 } | 137 } |
135 return false; | 138 return false; |
136 } | 139 } |
137 | 140 |
138 void SkGLContextHelper::testAbandon() { | 141 void SkGLContextHelper::testAbandon() { |
139 if (NULL != fGL) { | 142 if (NULL != fGL) { |
140 fGL->abandon(); | 143 fGL->abandon(); |
141 } | 144 } |
142 } | 145 } |
OLD | NEW |