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

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: RasterDirect 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 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698