Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: tools/viewer/sk_app/GLWindowContext.cpp

Issue 1978573003: Add OpenGL context to Viewer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2015 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "GrContext.h"
10 #include "SkSurface.h"
11 #include "GLWindowContext.h"
12
13 #include "gl/GrGLDefines.h"
14
15 #include "gl/GrGLUtil.h"
16 #include "GrRenderTarget.h"
17 #include "GrContext.h"
18
19 #include "SkCanvas.h"
20 #include "SkImage_Base.h"
21
22 namespace sk_app {
23
24 GLWindowContext::GLWindowContext(void* platformData, const DisplayParams& params )
25 : WindowContext()
26 , fBackendContext(nullptr)
27 , fRenderTarget(nullptr)
28 , fSurface(nullptr) {
29 }
30
31 void GLWindowContext::initializeContext(void* platformData, const DisplayParams& params) {
32
33 this->onInitializeContext(platformData, params);
34
35 fDisplayParams = params;
36
37 SkAutoTUnref<const GrGLInterface> glInterface;
38 glInterface.reset(GrGLCreateNativeInterface());
39 fBackendContext.reset(GrGLInterfaceRemoveNVPR(glInterface.get()));
40
41 SkASSERT(nullptr == fContext);
42 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendCo ntext.get());
43
44 fPixelConfig = fContext->caps()->srgbSupport() &&
45 SkColorAndProfileAreGammaCorrect(fDisplayParams.fColorType,
46 fDisplayParams.fProfileType) &&
47 (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888 _GrPixelConfig;
48 }
49
50 void GLWindowContext::destroyContext() {
51 fSurface.reset(nullptr);
52 fRenderTarget.reset(nullptr);
53
54 if (fContext) {
55 // in case we have outstanding refs to this guy (lua?)
56 fContext->abandonContext();
57 fContext->unref();
58 fContext = nullptr;
59 }
60
61 fBackendContext.reset(nullptr);
62
63 this->onDestroyContext();
64 }
65
66 sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
67 if (nullptr == fSurface) {
68 fActualColorBits = SkTMax(fColorBits, 24);
69
70 // TODO: Query the actual framebuffer for sRGB capable. However, to
Brian Osman 2016/05/17 17:32:11 This entire comment belongs up around line 44 now
jvanverth1 2016/05/17 17:59:50 Done.
71 // preserve old (fake-linear) behavior, we don't do this. Instead, rely
72 // on the flag (currently driven via 'C' mode in SampleApp).
73 //
74 // Also, we may not have real sRGB support (ANGLE, in particular), so ch eck for
75 // that, and fall back to L32:
76 //
77 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conv ersion on write,
78 // so pretend that it's non-sRGB 8888:
79 if (fContext) {
80 GrBackendRenderTargetDesc desc;
81 desc.fWidth = this->fWidth;
82 desc.fHeight = this->fHeight;
83 desc.fConfig = fPixelConfig;
84 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
85 desc.fSampleCnt = fSampleCount;
86 desc.fStencilBits = fStencilBits;
87 GrGLint buffer;
88 GR_GL_CALL(fBackendContext, GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, & buffer));
89 desc.fRenderTargetHandle = buffer;
90 fRenderTarget.reset(fContext->textureProvider()->wrapBackendRenderTa rget(desc));
91
92 fSurface = this->createRenderSurface(fRenderTarget, fActualColorBits );
93 }
94 }
95
96 return fSurface;
97 }
98
99 void GLWindowContext::swapBuffers() {
100 this->presentRenderSurface(fSurface, fRenderTarget, fActualColorBits);
101 this->onSwapBuffers();
102 }
103
104 void GLWindowContext::resize(uint32_t w, uint32_t h) {
105 this->destroyContext();
106
107 this->initializeContext(nullptr, fDisplayParams);
108 }
109
110 void GLWindowContext::setDisplayParams(const DisplayParams& params) {
111 this->destroyContext();
112
113 this->initializeContext(nullptr, params);
114 }
115
116 } //namespace sk_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698