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

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: Rebase to ToT 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
« no previous file with comments | « tools/viewer/sk_app/GLWindowContext.h ('k') | tools/viewer/sk_app/VulkanWindowContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // We may not have real sRGB support (ANGLE, in particular), so check for
45 // that, and fall back to L32:
46 //
47 // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversi on on write,
48 // so pretend that it's non-sRGB 8888:
49 fPixelConfig = fContext->caps()->srgbSupport() &&
50 SkColorAndProfileAreGammaCorrect(fDisplayParams.fColorType,
51 fDisplayParams.fProfileType) &&
52 (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888 _GrPixelConfig;
53 }
54
55 void GLWindowContext::destroyContext() {
56 fSurface.reset(nullptr);
57 fRenderTarget.reset(nullptr);
58
59 if (fContext) {
60 // in case we have outstanding refs to this guy (lua?)
61 fContext->abandonContext();
62 fContext->unref();
63 fContext = nullptr;
64 }
65
66 fBackendContext.reset(nullptr);
67
68 this->onDestroyContext();
69 }
70
71 sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
72 if (nullptr == fSurface) {
73 fActualColorBits = SkTMax(fColorBits, 24);
74
75 if (fContext) {
76 GrBackendRenderTargetDesc desc;
77 desc.fWidth = this->fWidth;
78 desc.fHeight = this->fHeight;
79 desc.fConfig = fPixelConfig;
80 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
81 desc.fSampleCnt = fSampleCount;
82 desc.fStencilBits = fStencilBits;
83 GrGLint buffer;
84 GR_GL_CALL(fBackendContext, GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, & buffer));
85 desc.fRenderTargetHandle = buffer;
86 fRenderTarget.reset(fContext->textureProvider()->wrapBackendRenderTa rget(desc));
87
88 fSurface = this->createRenderSurface(fRenderTarget, fActualColorBits );
89 }
90 }
91
92 return fSurface;
93 }
94
95 void GLWindowContext::swapBuffers() {
96 this->presentRenderSurface(fSurface, fRenderTarget, fActualColorBits);
97 this->onSwapBuffers();
98 }
99
100 void GLWindowContext::resize(uint32_t w, uint32_t h) {
101 this->destroyContext();
102
103 this->initializeContext(nullptr, fDisplayParams);
104 }
105
106 void GLWindowContext::setDisplayParams(const DisplayParams& params) {
107 this->destroyContext();
108
109 this->initializeContext(nullptr, params);
110 }
111
112 } //namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/GLWindowContext.h ('k') | tools/viewer/sk_app/VulkanWindowContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698