aboutsummaryrefslogtreecommitdiffhomepage
path: root/example
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-12-19 13:15:02 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-19 18:41:36 +0000
commitfaa095e9842b924c20de84dce1bcc1adad7fe2e4 (patch)
tree9651cd2720ae39bad1c364338540902b7910655c /example
parent040238bded7b932b916c84912cbaec1207aa29c0 (diff)
Update SkSurface MakeFromBackend* factories to take an SkColorType.
Bug: skia: Change-Id: Ib1b03b1181ec937843eac2e8d8cb03ebe53e32c1 Reviewed-on: https://skia-review.googlesource.com/86760 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'example')
-rw-r--r--example/SkiaSDLExample.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp
index 3e23e576ed..32c59f347c 100644
--- a/example/SkiaSDLExample.cpp
+++ b/example/SkiaSDLExample.cpp
@@ -180,6 +180,11 @@ int main(int argc, char** argv) {
return success;
}
+ uint32_t windowFormat = SDL_GetWindowPixelFormat(window);
+ int contextType;
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &contextType);
+
+
int dw, dh;
SDL_GL_GetDrawableSize(window, &dw, &dh);
@@ -201,8 +206,23 @@ int main(int argc, char** argv) {
GR_GL_GetIntegerv(interface.get(), GR_GL_FRAMEBUFFER_BINDING, &buffer);
GrGLFramebufferInfo info;
info.fFBOID = (GrGLuint) buffer;
- GrBackendRenderTarget target(dw, dh, kMsaaSampleCount, kStencilBits,
- kSkia8888_GrPixelConfig, info);
+ SkColorType colorType;
+
+ if (SDL_PIXELFORMAT_RGBA8888 == windowFormat) {
+ info.fFormat = GR_GL_RGBA8;
+ colorType = kRGBA_8888_SkColorType;
+ } else {
+ SkASSERT(SDL_PIXELFORMAT_BGRA8888);
+ colorType = kBGRA_8888_SkColorType;
+ if (SDL_GL_CONTEXT_PROFILE_ES == contextType) {
+ info.fFormat = GR_GL_BGRA8;
+ } else {
+ // We assume the internal format is RGBA8 on desktop GL
+ info.fFormat = GR_GL_RGBA8;
+ }
+ }
+
+ GrBackendRenderTarget target(dw, dh, kMsaaSampleCount, kStencilBits, info);
// setup SkSurface
// To use distance field text, use commented out SkSurfaceProps instead
@@ -212,7 +232,7 @@ int main(int argc, char** argv) {
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(grContext.get(), target,
kBottomLeft_GrSurfaceOrigin,
- nullptr, &props));
+ colorType, nullptr, &props));
SkCanvas* canvas = surface->getCanvas();
canvas->scale((float)dw/dm.w, (float)dh/dm.h);