OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright 2016 Google Inc. |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
| 7 */ |
| 8 |
| 9 #include "RasterWindowContext_android.h" |
| 10 |
| 11 #include "SkSurface.h" |
| 12 #include "SkTypes.h" |
| 13 |
| 14 #include "Window_android.h" |
| 15 |
| 16 namespace sk_app { |
| 17 |
| 18 RasterWindowContext* RasterWindowContext::Create(void* platformData, const Displ
ayParams& params) { |
| 19 RasterWindowContext* ctx = new RasterWindowContext_android(platformData, par
ams); |
| 20 if (!ctx->isValid()) { |
| 21 delete ctx; |
| 22 ctx = nullptr; |
| 23 } |
| 24 return ctx; |
| 25 } |
| 26 |
| 27 RasterWindowContext_android::RasterWindowContext_android( |
| 28 void* platformData, const DisplayParams& params) { |
| 29 fDisplayParams = params; |
| 30 ContextPlatformData_android* androidPlatformData = |
| 31 reinterpret_cast<ContextPlatformData_android*>(platformData); |
| 32 fNativeWindow = androidPlatformData->fNativeWindow; |
| 33 fWidth = ANativeWindow_getWidth(fNativeWindow); |
| 34 fHeight = ANativeWindow_getHeight(fNativeWindow); |
| 35 int32_t format; |
| 36 switch(params.fColorType) { |
| 37 case kRGBA_8888_SkColorType: |
| 38 format = WINDOW_FORMAT_RGBA_8888; |
| 39 break; |
| 40 case kRGB_565_SkColorType: |
| 41 format = WINDOW_FORMAT_RGB_565; |
| 42 break; |
| 43 default: |
| 44 SkDEBUGFAIL("Unsupported Android color type"); |
| 45 } |
| 46 ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); |
| 47 } |
| 48 |
| 49 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { |
| 50 if (nullptr == fBackbufferSurface) { |
| 51 ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); |
| 52 const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4
; |
| 53 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |
| 54 fDisplayParams.fColorType, |
| 55 kOpaque_SkAlphaType, |
| 56 fDisplayParams.fProfileType); |
| 57 fBackbufferSurface = SkSurface::MakeRasterDirect( |
| 58 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); |
| 59 } |
| 60 return fBackbufferSurface; |
| 61 } |
| 62 |
| 63 |
| 64 void RasterWindowContext_android::swapBuffers() { |
| 65 ANativeWindow_unlockAndPost(fNativeWindow); |
| 66 fBackbufferSurface.reset(nullptr); |
| 67 } |
| 68 |
| 69 } // namespace sk_app |
OLD | NEW |