| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
| 11 #include "GLWindowContext.h" | 11 #include "GLWindowContext.h" |
| 12 | 12 |
| 13 #include "gl/GrGLDefines.h" | 13 #include "gl/GrGLDefines.h" |
| 14 | 14 |
| 15 #include "gl/GrGLUtil.h" | 15 #include "gl/GrGLUtil.h" |
| 16 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 | 18 |
| 19 #include "SkCanvas.h" | 19 #include "SkCanvas.h" |
| 20 #include "SkImage_Base.h" | 20 #include "SkImage_Base.h" |
| 21 | 21 |
| 22 namespace sk_app { | 22 namespace sk_app { |
| 23 | 23 |
| 24 GLWindowContext::GLWindowContext(const DisplayParams& params) | 24 GLWindowContext::GLWindowContext(const DisplayParams& params) |
| 25 : WindowContext() | 25 : WindowContext() |
| 26 , fBackendContext(nullptr) | 26 , fBackendContext(nullptr) |
| 27 , fRenderTarget(nullptr) | |
| 28 , fSurface(nullptr) { | 27 , fSurface(nullptr) { |
| 29 fDisplayParams = params; | 28 fDisplayParams = params; |
| 30 } | 29 } |
| 31 | 30 |
| 32 void GLWindowContext::initializeContext() { | 31 void GLWindowContext::initializeContext() { |
| 33 this->onInitializeContext(); | 32 this->onInitializeContext(); |
| 34 SkAutoTUnref<const GrGLInterface> glInterface; | 33 SkAutoTUnref<const GrGLInterface> glInterface; |
| 35 glInterface.reset(GrGLCreateNativeInterface()); | 34 glInterface.reset(GrGLCreateNativeInterface()); |
| 36 fBackendContext.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); | 35 fBackendContext.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); |
| 37 | 36 |
| 38 SkASSERT(nullptr == fContext); | 37 SkASSERT(nullptr == fContext); |
| 39 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendCo
ntext.get()); | 38 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendCo
ntext.get()); |
| 40 | 39 |
| 41 // We may not have real sRGB support (ANGLE, in particular), so check for | 40 // We may not have real sRGB support (ANGLE, in particular), so check for |
| 42 // that, and fall back to L32: | 41 // that, and fall back to L32: |
| 43 // | 42 // |
| 44 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversi
on on write, | 43 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversi
on on write, |
| 45 // so pretend that it's non-sRGB 8888: | 44 // so pretend that it's non-sRGB 8888: |
| 46 fPixelConfig = fContext->caps()->srgbSupport() && | 45 fPixelConfig = fContext->caps()->srgbSupport() && |
| 47 SkColorAndColorSpaceAreGammaCorrect(fDisplayParams.fColorType
, | 46 SkColorAndColorSpaceAreGammaCorrect(fDisplayParams.fColorType
, |
| 48 fDisplayParams.fColorSpac
e.get()) && | 47 fDisplayParams.fColorSpac
e.get()) && |
| 49 (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888
_GrPixelConfig; | 48 (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888
_GrPixelConfig; |
| 50 } | 49 } |
| 51 | 50 |
| 52 void GLWindowContext::destroyContext() { | 51 void GLWindowContext::destroyContext() { |
| 53 fSurface.reset(nullptr); | 52 fSurface.reset(nullptr); |
| 54 fRenderTarget.reset(nullptr); | |
| 55 | 53 |
| 56 if (fContext) { | 54 if (fContext) { |
| 57 // in case we have outstanding refs to this guy (lua?) | 55 // in case we have outstanding refs to this guy (lua?) |
| 58 fContext->abandonContext(); | 56 fContext->abandonContext(); |
| 59 fContext->unref(); | 57 fContext->unref(); |
| 60 fContext = nullptr; | 58 fContext = nullptr; |
| 61 } | 59 } |
| 62 | 60 |
| 63 fBackendContext.reset(nullptr); | 61 fBackendContext.reset(nullptr); |
| 64 | 62 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 this->initializeContext(); | 95 this->initializeContext(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 void GLWindowContext::setDisplayParams(const DisplayParams& params) { | 98 void GLWindowContext::setDisplayParams(const DisplayParams& params) { |
| 101 this->destroyContext(); | 99 this->destroyContext(); |
| 102 fDisplayParams = params; | 100 fDisplayParams = params; |
| 103 this->initializeContext(); | 101 this->initializeContext(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 } //namespace sk_app | 104 } //namespace sk_app |
| OLD | NEW |