18c52a7b52
This reverts commitd0d7270fcc
. Revert "More sample count cleanup:" This reverts commitd653cac70e
. Revert "Add new GrContext queries for imagability, surfacability, and max sample count of color types" This reverts commit85ae7159c9
. 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>
102 lines
3.0 KiB
C++
102 lines
3.0 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 "GrBackendSurface.h"
|
|
#include "GrContext.h"
|
|
#include "GLWindowContext.h"
|
|
|
|
#include "gl/GrGLDefines.h"
|
|
#include "gl/GrGLUtil.h"
|
|
|
|
#include "SkCanvas.h"
|
|
#include "SkImage_Base.h"
|
|
#include "SkMathPriv.h"
|
|
#include "SkSurface.h"
|
|
|
|
namespace sk_app {
|
|
|
|
GLWindowContext::GLWindowContext(const DisplayParams& params)
|
|
: WindowContext(params)
|
|
, fBackendContext(nullptr)
|
|
, fSurface(nullptr) {
|
|
fDisplayParams.fMSAASampleCount = fDisplayParams.fMSAASampleCount ?
|
|
GrNextPow2(fDisplayParams.fMSAASampleCount) :
|
|
0;
|
|
}
|
|
|
|
void GLWindowContext::initializeContext() {
|
|
SkASSERT(!fContext);
|
|
|
|
fBackendContext = this->onInitializeContext();
|
|
fContext = GrContext::MakeGL(fBackendContext, fDisplayParams.fGrContextOptions);
|
|
if (!fContext && fDisplayParams.fMSAASampleCount) {
|
|
fDisplayParams.fMSAASampleCount /= 2;
|
|
this->initializeContext();
|
|
return;
|
|
}
|
|
}
|
|
|
|
void GLWindowContext::destroyContext() {
|
|
fSurface.reset(nullptr);
|
|
|
|
if (fContext) {
|
|
// in case we have outstanding refs to this guy (lua?)
|
|
fContext->abandonContext();
|
|
fContext.reset();
|
|
}
|
|
|
|
fBackendContext.reset(nullptr);
|
|
|
|
this->onDestroyContext();
|
|
}
|
|
|
|
sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
|
|
if (nullptr == fSurface) {
|
|
if (fContext) {
|
|
GrGLFramebufferInfo fbInfo;
|
|
GrGLint buffer;
|
|
GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING,
|
|
&buffer));
|
|
fbInfo.fFBOID = buffer;
|
|
fbInfo.fFormat = fContext->caps()->srgbSupport() && fDisplayParams.fColorSpace
|
|
? GR_GL_SRGB8_ALPHA8 : GR_GL_RGBA8;
|
|
|
|
GrBackendRenderTarget backendRT(fWidth,
|
|
fHeight,
|
|
fSampleCount,
|
|
fStencilBits,
|
|
fbInfo);
|
|
|
|
fSurface = SkSurface::MakeFromBackendRenderTarget(fContext.get(), backendRT,
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
kRGBA_8888_SkColorType,
|
|
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
|