2016-05-20 13:01:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/core/SkMathPriv.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
|
|
|
#include "src/gpu/gl/GrGLUtil.h"
|
|
|
|
#include "src/image/SkImage_Base.h"
|
|
|
|
#include "tools/sk_app/GLWindowContext.h"
|
2016-05-20 13:01:06 +00:00
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
GLWindowContext::GLWindowContext(const DisplayParams& params)
|
2017-05-02 20:15:53 +00:00
|
|
|
: WindowContext(params)
|
2016-05-20 13:01:06 +00:00
|
|
|
, fBackendContext(nullptr)
|
|
|
|
, fSurface(nullptr) {
|
2018-02-03 01:32:49 +00:00
|
|
|
fDisplayParams.fMSAASampleCount = GrNextPow2(fDisplayParams.fMSAASampleCount);
|
2016-07-26 19:02:50 +00:00
|
|
|
}
|
2016-05-20 13:01:06 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
void GLWindowContext::initializeContext() {
|
2017-07-25 14:05:01 +00:00
|
|
|
SkASSERT(!fContext);
|
2017-02-22 19:00:42 +00:00
|
|
|
|
2017-08-17 18:37:06 +00:00
|
|
|
fBackendContext = this->onInitializeContext();
|
2017-12-07 17:33:05 +00:00
|
|
|
fContext = GrContext::MakeGL(fBackendContext, fDisplayParams.fGrContextOptions);
|
2018-02-03 01:32:49 +00:00
|
|
|
if (!fContext && fDisplayParams.fMSAASampleCount > 1) {
|
2017-02-24 23:04:47 +00:00
|
|
|
fDisplayParams.fMSAASampleCount /= 2;
|
|
|
|
this->initializeContext();
|
|
|
|
return;
|
|
|
|
}
|
2016-05-20 13:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindowContext::destroyContext() {
|
|
|
|
fSurface.reset(nullptr);
|
|
|
|
|
|
|
|
if (fContext) {
|
|
|
|
// in case we have outstanding refs to this guy (lua?)
|
|
|
|
fContext->abandonContext();
|
2017-07-25 14:05:01 +00:00
|
|
|
fContext.reset();
|
2016-05-20 13:01:06 +00:00
|
|
|
}
|
2017-05-01 13:50:58 +00:00
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
fBackendContext.reset(nullptr);
|
|
|
|
|
|
|
|
this->onDestroyContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
|
|
|
|
if (nullptr == fSurface) {
|
|
|
|
if (fContext) {
|
|
|
|
GrGLint buffer;
|
2018-07-09 14:23:19 +00:00
|
|
|
GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer));
|
|
|
|
|
|
|
|
GrGLFramebufferInfo fbInfo;
|
2017-05-01 13:50:58 +00:00
|
|
|
fbInfo.fFBOID = buffer;
|
2018-07-09 14:23:19 +00:00
|
|
|
fbInfo.fFormat = GR_GL_RGBA8;
|
2017-05-01 13:50:58 +00:00
|
|
|
|
|
|
|
GrBackendRenderTarget backendRT(fWidth,
|
|
|
|
fHeight,
|
|
|
|
fSampleCount,
|
|
|
|
fStencilBits,
|
|
|
|
fbInfo);
|
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
fSurface = SkSurface::MakeFromBackendRenderTarget(fContext.get(), backendRT,
|
2017-05-01 13:50:58 +00:00
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
2017-12-19 18:15:02 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
2017-02-08 15:47:28 +00:00
|
|
|
fDisplayParams.fColorSpace,
|
2018-04-13 18:30:23 +00:00
|
|
|
&fDisplayParams.fSurfaceProps);
|
2016-05-20 13:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindowContext::swapBuffers() {
|
|
|
|
this->onSwapBuffers();
|
|
|
|
}
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
void GLWindowContext::resize(int w, int h) {
|
2016-05-20 13:01:06 +00:00
|
|
|
this->destroyContext();
|
2016-07-26 19:02:50 +00:00
|
|
|
this->initializeContext();
|
2016-05-20 13:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindowContext::setDisplayParams(const DisplayParams& params) {
|
2016-07-26 19:02:50 +00:00
|
|
|
fDisplayParams = params;
|
2019-07-11 20:23:49 +00:00
|
|
|
this->destroyContext();
|
2016-07-26 19:02:50 +00:00
|
|
|
this->initializeContext();
|
2016-05-20 13:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace sk_app
|