Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: tools/viewer/sk_app/android/RasterWindowContext_android.cpp

Issue 2041193004: Implement Raster Backend on Android Viewer App (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: line100 Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698