-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathOpenGLWindowContext.cpp
More file actions
62 lines (48 loc) · 1.73 KB
/
OpenGLWindowContext.cpp
File metadata and controls
62 lines (48 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "OpenGLWindowContext.h"
#include "GrAHardwareBufferUtils.h"
#include "OpenGLContext.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
#include "src/gpu/ganesh/gl/GrGLDefines.h"
#pragma clang diagnostic pop
namespace RNSkia {
sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
assertThread("getSurface");
if (_skSurface == nullptr) {
_glContext->makeCurrent(_glSurface.get());
GLint stencil;
glGetIntegerv(GL_STENCIL_BITS, &stencil);
GLint samples;
glGetIntegerv(GL_SAMPLES, &samples);
auto colorType = kRGBA_8888_SkColorType;
auto maxSamples =
_directContext->maxSurfaceSampleCountForColorType(colorType);
if (samples > maxSamples) {
samples = maxSamples;
}
GrGLFramebufferInfo fbInfo;
fbInfo.fFBOID = 0;
fbInfo.fFormat = GR_GL_RGBA8;
// fbInfo.fProtected =
// skgpu::Protected(fDisplayParams.fCreateProtectedNativeBackend);
auto width = ANativeWindow_getWidth(_window);
auto height = ANativeWindow_getHeight(_window);
auto backendRT =
GrBackendRenderTargets::MakeGL(width, height, samples, stencil, fbInfo);
sk_sp<SkColorSpace> colorSpace(nullptr);
SkSurfaceProps surfaceProps(0, kRGB_H_SkPixelGeometry);
_skSurface = SkSurfaces::WrapBackendRenderTarget(
_directContext, backendRT, kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, colorSpace, &surfaceProps);
}
return _skSurface;
}
void OpenGLWindowContext::present() {
assertThread("present");
_glContext->makeCurrent(_glSurface.get());
_directContext->flushAndSubmit();
_glSurface->present();
}
} // namespace RNSkia