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..3c0188f11b5439498a7da0f937570b43dcfede83 |
--- /dev/null |
+++ b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp |
@@ -0,0 +1,53 @@ |
+ |
+/* |
+ * 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_android::RasterWindowContext_android( |
+ void* platformData, const DisplayParams& params) |
+ : RasterWindowContext(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); |
+} |
+ |
+void RasterWindowContext_android::onSwapBuffers(sk_sp<SkImage> image) { |
+ SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, |
+ fDisplayParams.fColorType, |
+ kOpaque_SkAlphaType, |
+ fDisplayParams.fProfileType); |
+ ANativeWindow_Buffer buffer; |
+ ARect bounds; |
+ ANativeWindow_lock(fNativeWindow, &buffer, &bounds); |
+ const int bytePerPixel = buffer.format == WINDOW_FORMAT_RGB_565 ? 2 : 4; |
+ image->readPixels(this->getImageInfo(), buffer.bits, buffer.stride * bytePerPixel, 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.
|
+ ANativeWindow_unlockAndPost(fNativeWindow); |
+} |
+ |
+} // namespace sk_app |