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

Side by Side Diff: tools/viewer/sk_app/win/GLWindowContext_win.cpp

Issue 1990893002: Revert of Add OpenGL context to Viewer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 "GLWindowContext_win.h"
10
11 #include <GL/gl.h>
12
13 // windows stuff
14 #include "win/SkWGL.h"
15 #include "Window_win.h"
16
17 namespace sk_app {
18
19 // platform-dependent create
20 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams & params) {
21 GLWindowContext_win* ctx = new GLWindowContext_win(platformData, params);
22 if (!ctx->isValid()) {
23 delete ctx;
24 return nullptr;
25 }
26 return ctx;
27 }
28
29 GLWindowContext_win::GLWindowContext_win(void* platformData, const DisplayParams & params)
30 : GLWindowContext(platformData, params)
31 , fHWND(0)
32 , fHGLRC(NULL) {
33
34 // any config code here (particularly for msaa)?
35
36 this->initializeContext(platformData, params);
37 }
38
39 GLWindowContext_win::~GLWindowContext_win() {
40 this->destroyContext();
41 }
42
43 void GLWindowContext_win::onInitializeContext(void* platformData, const DisplayP arams& params) {
44
45 ContextPlatformData_win* winPlatformData =
46 reinterpret_cast<ContextPlatformData_win*>(platformData);
47
48 if (winPlatformData) {
49 fHWND = winPlatformData->fHWnd;
50 }
51 HDC dc = GetDC(fHWND);
52
53 fHGLRC = SkCreateWGLContext(dc, params.fMSAASampleCount, params.fDeepColor,
54 kGLPreferCompatibilityProfile_SkWGLContextReques t);
55 if (NULL == fHGLRC) {
56 return;
57 }
58
59 if (wglMakeCurrent(dc, fHGLRC)) {
60 glClearStencil(0);
61 glClearColor(0, 0, 0, 0);
62 glStencilMask(0xffffffff);
63 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
64
65 // use DescribePixelFormat to get the stencil and color bit depth.
66 int pixelFormat = GetPixelFormat(dc);
67 PIXELFORMATDESCRIPTOR pfd;
68 DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd);
69 fStencilBits = pfd.cStencilBits;
70 // pfd.cColorBits includes alpha, so it will be 32 in 8/8/8/8 and 10/10/ 10/2
71 fColorBits = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;
72
73 // Get sample count if the MSAA WGL extension is present
74 SkWGLExtensions extensions;
75 if (extensions.hasExtension(dc, "WGL_ARB_multisample")) {
76 static const int kSampleCountAttr = SK_WGL_SAMPLES;
77 extensions.getPixelFormatAttribiv(dc,
78 pixelFormat,
79 0,
80 1,
81 &kSampleCountAttr,
82 &fSampleCount);
83 } else {
84 fSampleCount = 0;
85 }
86
87 RECT rect;
88 GetClientRect(fHWND, &rect);
89 fWidth = rect.right - rect.left;
90 fHeight = rect.bottom - rect.top;
91 glViewport(0, 0, fWidth, fHeight);
92 }
93 }
94
95
96 void GLWindowContext_win::onDestroyContext() {
97 wglMakeCurrent(wglGetCurrentDC(), NULL);
98 wglDeleteContext(fHGLRC);
99 fHGLRC = NULL;
100 }
101
102
103 void GLWindowContext_win::onSwapBuffers() {
104 HDC dc = GetDC((HWND)fHWND);
105 SwapBuffers(dc);
106 ReleaseDC((HWND)fHWND, dc);
107 }
108
109
110 } //namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/win/GLWindowContext_win.h ('k') | tools/viewer/sk_app/win/VulkanWindowContext_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698