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

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

Issue 2050613003: Support resize in Android Viewer App (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Nits 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
1 1
2 /* 2 /*
3 * Copyright 2016 Google Inc. 3 * Copyright 2016 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "RasterWindowContext_android.h" 9 #include "RasterWindowContext_android.h"
10 10
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 RasterWindowContext_android::RasterWindowContext_android( 27 RasterWindowContext_android::RasterWindowContext_android(
28 void* platformData, const DisplayParams& params) { 28 void* platformData, const DisplayParams& params) {
29 fDisplayParams = params; 29 fDisplayParams = params;
30 ContextPlatformData_android* androidPlatformData = 30 ContextPlatformData_android* androidPlatformData =
31 reinterpret_cast<ContextPlatformData_android*>(platformData); 31 reinterpret_cast<ContextPlatformData_android*>(platformData);
32 fNativeWindow = androidPlatformData->fNativeWindow; 32 fNativeWindow = androidPlatformData->fNativeWindow;
33 fWidth = ANativeWindow_getWidth(fNativeWindow); 33 fWidth = ANativeWindow_getWidth(fNativeWindow);
34 fHeight = ANativeWindow_getHeight(fNativeWindow); 34 fHeight = ANativeWindow_getHeight(fNativeWindow);
35 this->setBuffersGeometry();
36 }
37
38 void RasterWindowContext_android::setBuffersGeometry() {
35 int32_t format; 39 int32_t format;
36 switch(params.fColorType) { 40 switch(fDisplayParams.fColorType) {
37 case kRGBA_8888_SkColorType: 41 case kRGBA_8888_SkColorType:
38 format = WINDOW_FORMAT_RGBA_8888; 42 format = WINDOW_FORMAT_RGBA_8888;
39 break; 43 break;
40 case kRGB_565_SkColorType: 44 case kRGB_565_SkColorType:
41 format = WINDOW_FORMAT_RGB_565; 45 format = WINDOW_FORMAT_RGB_565;
42 break; 46 break;
43 default: 47 default:
44 SkDEBUGFAIL("Unsupported Android color type"); 48 SkDEBUGFAIL("Unsupported Android color type");
45 } 49 }
46 ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format); 50 ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format);
47 } 51 }
48 52
53 void RasterWindowContext_android::setDisplayParams(const DisplayParams& params) {
54 fDisplayParams = params;
55 this->setBuffersGeometry();
56 }
57
58 void RasterWindowContext_android::resize(uint32_t w, uint32_t h) {
59 fWidth = w;
60 fHeight = h;
61 this->setBuffersGeometry();
62 }
63
49 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() { 64 sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() {
50 if (nullptr == fBackbufferSurface) { 65 if (nullptr == fBackbufferSurface) {
51 ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds); 66 ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds);
52 const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4 ; 67 const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4 ;
53 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, 68 SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
54 fDisplayParams.fColorType, 69 fDisplayParams.fColorType,
55 kOpaque_SkAlphaType, 70 kOpaque_SkAlphaType,
56 fDisplayParams.fProfileType); 71 fDisplayParams.fProfileType);
57 fBackbufferSurface = SkSurface::MakeRasterDirect( 72 fBackbufferSurface = SkSurface::MakeRasterDirect(
58 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); 73 info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr);
59 } 74 }
60 return fBackbufferSurface; 75 return fBackbufferSurface;
61 } 76 }
62 77
63 78
64 void RasterWindowContext_android::swapBuffers() { 79 void RasterWindowContext_android::swapBuffers() {
65 ANativeWindow_unlockAndPost(fNativeWindow); 80 ANativeWindow_unlockAndPost(fNativeWindow);
66 fBackbufferSurface.reset(nullptr); 81 fBackbufferSurface.reset(nullptr);
67 } 82 }
68 83
69 } // namespace sk_app 84 } // namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/android/RasterWindowContext_android.h ('k') | tools/viewer/sk_app/android/surface_glue_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698