skia2/tools/sk_app/ios/GLWindowContext_ios.cpp
Brian Salomon 18c52a7b52 Revert "Revert "Revert "Redefine the meaning of sample counts in GPU backend."""
This reverts commit d0d7270fcc.

Revert "More sample count cleanup:"

This reverts commit d653cac70e.

Revert "Add new GrContext queries for imagability, surfacability, and max sample count of color types"

This reverts commit 85ae7159c9.


Need to understand NVPR perf changes before relanding

Change-Id: I0db075fb42438ef2a1f9885df184dce52892ac4b
Reviewed-on: https://skia-review.googlesource.com/102780
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2018-02-02 12:19:52 +00:00

110 lines
2.6 KiB
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <OpenGLES/ES2/gl.h>
#include "../GLWindowContext.h"
#include "SDL.h"
#include "WindowContextFactory_ios.h"
#include "gl/GrGLInterface.h"
using sk_app::DisplayParams;
using sk_app::window_context_factory::IOSWindowInfo;
using sk_app::GLWindowContext;
namespace {
class GLWindowContext_ios : public GLWindowContext {
public:
GLWindowContext_ios(const IOSWindowInfo&, const DisplayParams&);
~GLWindowContext_ios() override;
void onSwapBuffers() override;
sk_sp<const GrGLInterface> onInitializeContext() override;
void onDestroyContext() override;
private:
SDL_Window* fWindow;
SDL_GLContext fGLContext;
typedef GLWindowContext INHERITED;
};
GLWindowContext_ios::GLWindowContext_ios(const IOSWindowInfo& info, const DisplayParams& params)
: INHERITED(params)
, fWindow(info.fWindow)
, fGLContext(nullptr) {
// any config code here (particularly for msaa)?
this->initializeContext();
}
GLWindowContext_ios::~GLWindowContext_ios() {
this->destroyContext();
}
sk_sp<const GrGLInterface> GLWindowContext_ios::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_GL_GetDrawableSize(fWindow, &fWidth, &fHeight);
glViewport(0, 0, fWidth, fHeight);
} else {
SkDebugf("MakeCurrent failed: %s\n", SDL_GetError());
}
return GrGLMakeNativeInterface();
}
void GLWindowContext_ios::onDestroyContext() {
if (!fWindow || !fGLContext) {
return;
}
SDL_GL_DeleteContext(fGLContext);
fGLContext = nullptr;
}
void GLWindowContext_ios::onSwapBuffers() {
if (fWindow && fGLContext) {
SDL_GL_SwapWindow(fWindow);
}
}
} // anonymous namespace
namespace sk_app {
namespace window_context_factory {
WindowContext* NewGLForIOS(const IOSWindowInfo& info, const DisplayParams& params) {
WindowContext* ctx = new GLWindowContext_ios(info, params);
if (!ctx->isValid()) {
delete ctx;
return nullptr;
}
return ctx;
}
} // namespace window_context_factory
} // namespace sk_app