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

Unified 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: Merge 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 side-by-side diff with in-line comments
Download patch
Index: tools/viewer/sk_app/android/RasterWindowContext_android.cpp
diff --git a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..306f291de8f80fadc10c5c2822a7b92b2b3096fa
--- /dev/null
+++ b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
@@ -0,0 +1,69 @@
+
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "RasterWindowContext_android.h"
+
+#include "SkSurface.h"
+#include "SkTypes.h"
+
+#include "Window_android.h"
+
+namespace sk_app {
+
+RasterWindowContext* RasterWindowContext::Create(void* platformData, const DisplayParams& params) {
+ RasterWindowContext* ctx = new RasterWindowContext_android(platformData, params);
+ if (!ctx->isValid()) {
+ delete ctx;
+ ctx = nullptr;
+ }
+ return ctx;
+}
+
+RasterWindowContext_android::RasterWindowContext_android(
+ void* platformData, const DisplayParams& params) {
+ fDisplayParams = params;
+ ContextPlatformData_android* androidPlatformData =
+ reinterpret_cast<ContextPlatformData_android*>(platformData);
+ fNativeWindow = androidPlatformData->fNativeWindow;
+ fWidth = ANativeWindow_getWidth(fNativeWindow);
+ fHeight = ANativeWindow_getHeight(fNativeWindow);
+ int32_t format;
+ switch(params.fColorType) {
+ case kRGBA_8888_SkColorType:
+ format = WINDOW_FORMAT_RGBA_8888;
+ break;
+ case kRGB_565_SkColorType:
+ format = WINDOW_FORMAT_RGB_565;
+ break;
+ default:
+ SkDEBUGFAIL("Unsupported Android color type");
+ }
+ ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format);
+}
+
+sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() {
+ if (nullptr == fBackbufferSurface) {
+ ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds);
+ const int bytePerPixel = fBuffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4;
+ SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
+ fDisplayParams.fColorType,
+ kOpaque_SkAlphaType,
+ fDisplayParams.fProfileType);
+ fBackbufferSurface = SkSurface::MakeRasterDirect(
+ info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr);
+ }
+ return fBackbufferSurface;
+}
+
+
+void RasterWindowContext_android::swapBuffers() {
+ ANativeWindow_unlockAndPost(fNativeWindow);
+ fBackbufferSurface.reset(nullptr);
+}
+
+} // namespace sk_app
« no previous file with comments | « tools/viewer/sk_app/android/RasterWindowContext_android.h ('k') | tools/viewer/sk_app/android/Window_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698