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>
diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp
index 3e23e57..32c59f3 100644
--- a/example/SkiaSDLExample.cpp
+++ b/example/SkiaSDLExample.cpp
@@ -180,6 +180,11 @@
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 @@
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 @@
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);