aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer/sk_app/win/GLWindowContext_win.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-07-26 12:02:50 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-26 12:02:51 -0700
commitd1bdd1fcbd308afb9903f39d231742f5c951cf07 (patch)
tree786715537d870e3ff8bc3686ea40b83b62c43d6b /tools/viewer/sk_app/win/GLWindowContext_win.cpp
parent1ed2ae45f59c2864ea05838b4da2750b85472824 (diff)
Use Windowing system-specific WindowContext factories.
Diffstat (limited to 'tools/viewer/sk_app/win/GLWindowContext_win.cpp')
-rw-r--r--tools/viewer/sk_app/win/GLWindowContext_win.cpp71
1 files changed, 44 insertions, 27 deletions
diff --git a/tools/viewer/sk_app/win/GLWindowContext_win.cpp b/tools/viewer/sk_app/win/GLWindowContext_win.cpp
index 0694db308f..eca8829d3d 100644
--- a/tools/viewer/sk_app/win/GLWindowContext_win.cpp
+++ b/tools/viewer/sk_app/win/GLWindowContext_win.cpp
@@ -6,51 +6,53 @@
* found in the LICENSE file.
*/
-#include "GLWindowContext_win.h"
-
+#include "WindowContextFactory_win.h"
#include <GL/gl.h>
// windows stuff
#include "win/SkWGL.h"
-#include "Window_win.h"
-namespace sk_app {
+#include "../GLWindowContext.h"
-// platform-dependent create
-GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams& params) {
- GLWindowContext_win* ctx = new GLWindowContext_win(platformData, params);
- if (!ctx->isValid()) {
- delete ctx;
- return nullptr;
- }
- return ctx;
-}
+using sk_app::GLWindowContext;
+using sk_app::DisplayParams;
+
+namespace {
+
+class GLWindowContext_win : public GLWindowContext {
+public:
+ GLWindowContext_win(HWND, const DisplayParams&);
+ ~GLWindowContext_win() override;
+
+protected:
+ void onSwapBuffers() override;
+
+ void onInitializeContext() override;
+ void onDestroyContext() override;
+
+private:
+ HWND fHWND;
+ HGLRC fHGLRC;
+};
-GLWindowContext_win::GLWindowContext_win(void* platformData, const DisplayParams& params)
- : GLWindowContext(platformData, params)
- , fHWND(0)
+GLWindowContext_win::GLWindowContext_win(HWND wnd, const DisplayParams& params)
+ : GLWindowContext(params)
+ , fHWND(wnd)
, fHGLRC(NULL) {
// any config code here (particularly for msaa)?
- this->initializeContext(platformData, params);
+ this->initializeContext();
}
GLWindowContext_win::~GLWindowContext_win() {
this->destroyContext();
}
-void GLWindowContext_win::onInitializeContext(void* platformData, const DisplayParams& params) {
-
- ContextPlatformData_win* winPlatformData =
- reinterpret_cast<ContextPlatformData_win*>(platformData);
-
- if (winPlatformData) {
- fHWND = winPlatformData->fHWnd;
- }
+void GLWindowContext_win::onInitializeContext() {
HDC dc = GetDC(fHWND);
- fHGLRC = SkCreateWGLContext(dc, params.fMSAASampleCount, params.fDeepColor,
+ fHGLRC = SkCreateWGLContext(dc, fDisplayParams.fMSAASampleCount, fDisplayParams.fDeepColor,
kGLPreferCompatibilityProfile_SkWGLContextRequest);
if (NULL == fHGLRC) {
return;
@@ -107,4 +109,19 @@ void GLWindowContext_win::onSwapBuffers() {
}
-} //namespace sk_app
+} // anonymous namespace
+
+namespace sk_app {
+namespace window_context_factory {
+
+WindowContext* NewGLForWin(HWND wnd, const DisplayParams& params) {
+ GLWindowContext_win* ctx = new GLWindowContext_win(wnd, params);
+ if (!ctx->isValid()) {
+ delete ctx;
+ return nullptr;
+ }
+ return ctx;
+}
+
+} // namespace window_context_factory
+} // namespace sk_app