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_android::RasterWindowContext_android( |
| 19 void* platformData, const DisplayParams& params) { |
| 20 fDisplayParams = params; |
| 21 ContextPlatformData_android* androidPlatformData = |
| 22 reinterpret_cast<ContextPlatformData_android*>(platformData); |
| 23 fNativeWindow = androidPlatformData->fNativeWindow; |
| 24 fWidth = ANativeWindow_getWidth(fNativeWindow); |
| 25 fHeight = ANativeWindow_getHeight(fNativeWindow); |
| 26 int32_t format; |
| 27 switch(params.fColorType) { |
| 28 case kRGBA_8888_SkColorType: |
| 29 format = WINDOW_FORMAT_RGBA_8888; |
| 30 break; |
| 31 case kRGB_565_SkColorType: |
| 32 format = WINDOW_FORMAT_RGB_565; |
| 33 break; |
| 34 default: |
| 35 SkDEBUGFAIL("Unsupported Android color type"); |
| 36 } |
| 37 ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); |
| 38 } |
| 39 |
| 40 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { |
| 41 if (nullptr == fBackbufferSurface) { |
| 42 ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); |
| 43 const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4
; |
| 44 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |
| 45 fDisplayParams.fColorType, |
| 46 kOpaque_SkAlphaType, |
| 47 fDisplayParams.fProfileType); |
| 48 fBackbufferSurface = SkSurface::MakeRasterDirect(info, fBuffer.bits, fBu
ffer.stride * bytePerPixel, nullptr); |
| 49 } |
| 50 return fBackbufferSurface; |
| 51 } |
| 52 |
| 53 |
| 54 void RasterWindowContext_android::swapBuffers() { |
| 55 ANativeWindow_unlockAndPost(fNativeWindow); |
| 56 fBackbufferSurface.reset(nullptr); |
| 57 } |
| 58 |
| 59 } // namespace sk_app |
OLD | NEW |