e3bd422faf
This reverts commit fdd77daedb
.
Reason for revert: Apparently I have a few more build files to update before this can land.
Original change's description:
> Plumb the use of GrBackendRenderTarget throughout Skia
>
> Bug: skia:
> Change-Id: Ib99a58d9552f5c7b8d77c09dcc72fa88326c26aa
> Reviewed-on: https://skia-review.googlesource.com/14148
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I984e1909870182474c4c3cce257f01b6a9d8581f
Reviewed-on: https://skia-review.googlesource.com/14531
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
112 lines
3.2 KiB
C++
112 lines
3.2 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 "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"
|
|
#include "SkMathPriv.h"
|
|
|
|
namespace sk_app {
|
|
|
|
GLWindowContext::GLWindowContext(const DisplayParams& params)
|
|
: WindowContext()
|
|
, fBackendContext(nullptr)
|
|
, fSurface(nullptr) {
|
|
fDisplayParams = params;
|
|
fDisplayParams.fMSAASampleCount = fDisplayParams.fMSAASampleCount ?
|
|
GrNextPow2(fDisplayParams.fMSAASampleCount) :
|
|
0;
|
|
}
|
|
|
|
void GLWindowContext::initializeContext() {
|
|
this->onInitializeContext();
|
|
SkASSERT(nullptr == fContext);
|
|
|
|
fBackendContext.reset(GrGLCreateNativeInterface());
|
|
fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendContext.get(),
|
|
fDisplayParams.fGrContextOptions);
|
|
if (!fContext && fDisplayParams.fMSAASampleCount) {
|
|
fDisplayParams.fMSAASampleCount /= 2;
|
|
this->initializeContext();
|
|
return;
|
|
}
|
|
|
|
if (fContext) {
|
|
// 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;
|
|
} else {
|
|
fPixelConfig = kUnknown_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
|