Chromium Code Reviews| 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 : RasterWindowContext(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 void RasterWindowContext_android::onSwapBuffers(sk_sp<SkImage> image) { | |
| 41 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, | |
| 42 fDisplayParams.fColorType, | |
| 43 kOpaque_SkAlphaType, | |
| 44 fDisplayParams.fProfileType); | |
| 45 ANativeWindow_Buffer buffer; | |
| 46 ARect bounds; | |
| 47 ANativeWindow_lock(fNativeWindow, &buffer, &bounds); | |
| 48 const int bytePerPixel = buffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4; | |
| 49 image->readPixels(this->getImageInfo(), buffer.bits, buffer.stride * bytePer Pixel, 0, 0); | |
|
djsollen
2016/06/07 16:05:30
we should not do a pixel copy on every frame. The
liyuqian
2016/06/07 19:19:57
Done.
| |
| 50 ANativeWindow_unlockAndPost(fNativeWindow); | |
| 51 } | |
| 52 | |
| 53 } // namespace sk_app | |
| OLD | NEW |