diff options
author | 2017-11-21 13:18:02 -0500 | |
---|---|---|
committer | 2017-11-21 18:37:19 +0000 | |
commit | eff04b5ec287e0fee0d44207c10d2d11f7eade8a (patch) | |
tree | ea2cf00ea329c81611536aaa9a9f1eca47c67e9a /tools/sk_app/mac/GLWindowContext_mac.cpp | |
parent | 2aa09dbe8aced37aa6bb285e62df45deb0e81650 (diff) |
Remove SampleApp and convert HelloWorld to sk_app
There is still a large amount of views code that could be trimmed down,
but which is used to implement samples (in viewer). Seemed simpler to
remove some of this code in pieces.
Bug: skia:
Change-Id: Ia3415060d03c8de604a154e3dc38379b754daab6
Reviewed-on: https://skia-review.googlesource.com/72801
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tools/sk_app/mac/GLWindowContext_mac.cpp')
-rw-r--r-- | tools/sk_app/mac/GLWindowContext_mac.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tools/sk_app/mac/GLWindowContext_mac.cpp b/tools/sk_app/mac/GLWindowContext_mac.cpp new file mode 100644 index 0000000000..7f09d54522 --- /dev/null +++ b/tools/sk_app/mac/GLWindowContext_mac.cpp @@ -0,0 +1,109 @@ + +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <OpenGL/gl.h> +#include "../GLWindowContext.h" +#include "SDL.h" +#include "WindowContextFactory_mac.h" +#include "gl/GrGLInterface.h" + +using sk_app::DisplayParams; +using sk_app::window_context_factory::MacWindowInfo; +using sk_app::GLWindowContext; + +namespace { + +class GLWindowContext_mac : public GLWindowContext { +public: + GLWindowContext_mac(const MacWindowInfo&, const DisplayParams&); + + ~GLWindowContext_mac() override; + + void onSwapBuffers() override; + + sk_sp<const GrGLInterface> onInitializeContext() override; + void onDestroyContext() override; + +private: + SDL_Window* fWindow; + SDL_GLContext fGLContext; + + typedef GLWindowContext INHERITED; +}; + +GLWindowContext_mac::GLWindowContext_mac(const MacWindowInfo& info, const DisplayParams& params) + : INHERITED(params) + , fWindow(info.fWindow) + , fGLContext(nullptr) { + + // any config code here (particularly for msaa)? + + this->initializeContext(); +} + +GLWindowContext_mac::~GLWindowContext_mac() { + this->destroyContext(); +} + +sk_sp<const GrGLInterface> GLWindowContext_mac::onInitializeContext() { + SkASSERT(fWindow); + + fGLContext = SDL_GL_CreateContext(fWindow); + if (!fGLContext) { + SkDebugf("%s\n", SDL_GetError()); + return nullptr; + } + + if (0 == SDL_GL_MakeCurrent(fWindow, fGLContext)) { + glClearStencil(0); + glClearColor(0, 0, 0, 0); + glStencilMask(0xffffffff); + glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + + SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &fStencilBits); + SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fSampleCount); + + SDL_GetWindowSize(fWindow, &fWidth, &fHeight); + glViewport(0, 0, fWidth, fHeight); + } else { + SkDebugf("MakeCurrent failed: %s\n", SDL_GetError()); + } + return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface()); +} + +void GLWindowContext_mac::onDestroyContext() { + if (!fWindow || !fGLContext) { + return; + } + SDL_GL_DeleteContext(fGLContext); + fGLContext = nullptr; +} + + +void GLWindowContext_mac::onSwapBuffers() { + if (fWindow && fGLContext) { + SDL_GL_SwapWindow(fWindow); + } +} + +} // anonymous namespace + +namespace sk_app { +namespace window_context_factory { + +WindowContext* NewGLForMac(const MacWindowInfo& info, const DisplayParams& params) { + WindowContext* ctx = new GLWindowContext_mac(info, params); + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; +} + +} // namespace window_context_factory +} // namespace sk_app |