008b9d80ab
Adds a bitfield to GrContextOptions that masks out path renderers. Adds commandline flags support to set this bitfield in tools apps. Removes GrGLInterfaceRemoveNVPR since we can now accomplish the same thing in the context options. BUG=skia: Change-Id: Icf2a4df36374b3ba2f69ebf0db56e8aedd6cf65f Reviewed-on: https://skia-review.googlesource.com/8786 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
|
|
/*
|
|
* Copyright 2015 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "GrContext.h"
|
|
#include "SkCommonFlagsPathRenderer.h"
|
|
#include "SkSurface.h"
|
|
#include "GLWindowContext.h"
|
|
|
|
#include "gl/GrGLDefines.h"
|
|
|
|
#include "gl/GrGLUtil.h"
|
|
#include "GrRenderTarget.h"
|
|
#include "GrContext.h"
|
|
|
|
#include "SkCanvas.h"
|
|
#include "SkImage_Base.h"
|
|
|
|
namespace sk_app {
|
|
|
|
GLWindowContext::GLWindowContext(const DisplayParams& params)
|
|
: WindowContext()
|
|
, fBackendContext(nullptr)
|
|
, fSurface(nullptr) {
|
|
fDisplayParams = params;
|
|
}
|
|
|
|
void GLWindowContext::initializeContext() {
|
|
this->onInitializeContext();
|
|
SkASSERT(nullptr == fContext);
|
|
|
|
GrContextOptions ctxOptions;
|
|
ctxOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
|
|
fBackendContext.reset(GrGLCreateNativeInterface());
|
|
fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendContext.get(),
|
|
ctxOptions);
|
|
|
|
// We may not have real sRGB support (ANGLE, in particular), so check for
|
|
// that, and fall back to L32:
|
|
fPixelConfig = fContext->caps()->srgbSupport() && fDisplayParams.fColorSpace
|
|
? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
|
|
}
|
|
|
|
void GLWindowContext::destroyContext() {
|
|
fSurface.reset(nullptr);
|
|
|
|
if (fContext) {
|
|
// in case we have outstanding refs to this guy (lua?)
|
|
fContext->abandonContext();
|
|
fContext->unref();
|
|
fContext = nullptr;
|
|
}
|
|
|
|
fBackendContext.reset(nullptr);
|
|
|
|
this->onDestroyContext();
|
|
}
|
|
|
|
sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
|
|
if (nullptr == fSurface) {
|
|
if (fContext) {
|
|
GrBackendRenderTargetDesc desc;
|
|
desc.fWidth = this->fWidth;
|
|
desc.fHeight = this->fHeight;
|
|
desc.fConfig = fPixelConfig;
|
|
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
|
desc.fSampleCnt = fSampleCount;
|
|
desc.fStencilBits = fStencilBits;
|
|
GrGLint buffer;
|
|
GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer));
|
|
desc.fRenderTargetHandle = buffer;
|
|
|
|
fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, desc,
|
|
fDisplayParams.fColorSpace,
|
|
&fSurfaceProps);
|
|
}
|
|
}
|
|
|
|
return fSurface;
|
|
}
|
|
|
|
void GLWindowContext::swapBuffers() {
|
|
this->onSwapBuffers();
|
|
}
|
|
|
|
void GLWindowContext::resize(int w, int h) {
|
|
this->destroyContext();
|
|
this->initializeContext();
|
|
}
|
|
|
|
void GLWindowContext::setDisplayParams(const DisplayParams& params) {
|
|
this->destroyContext();
|
|
fDisplayParams = params;
|
|
this->initializeContext();
|
|
}
|
|
|
|
} //namespace sk_app
|