aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/crosscontextimage.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-05-08 15:16:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-08 19:56:27 +0000
commit83b1b3db36e8622f4bbc8c391d5c714e258d1e03 (patch)
tree95c4bf6e53bc73f90373fa06dbf6afa8298420e5 /gm/crosscontextimage.cpp
parentaef837a542cd91fba46bc0b3d4571a598710b90e (diff)
Added SkImage::MakeCrossContextFromEncoded
Designed for Flutter's threading architecture, with an eye to being useful to other clients. Under the hood, uses a new image generator class to lazily wrap a texture for multiple GrContexts. Bug: skia: Change-Id: I6c37b12c8ab5bce94b91190e5f0beb91d31ae81b Reviewed-on: https://skia-review.googlesource.com/14180 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm/crosscontextimage.cpp')
-rw-r--r--gm/crosscontextimage.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/gm/crosscontextimage.cpp b/gm/crosscontextimage.cpp
new file mode 100644
index 0000000000..cf973dbe61
--- /dev/null
+++ b/gm/crosscontextimage.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "Resources.h"
+
+#if SK_SUPPORT_GPU
+#include "GrContext.h"
+#include "SkImage.h"
+
+DEF_SIMPLE_GM(cross_context_image, canvas, 512 + 512 + 30, 512 + 128 + 30) {
+ GrContext* context = canvas->getGrContext();
+ if (!context) {
+ skiagm::GM::DrawGpuOnlyMessage(canvas);
+ return;
+ }
+
+ sk_sp<SkData> encodedData = GetResourceAsData("mandrill_512.png");
+
+ sk_sp<SkImage> encodedImage = SkImage::MakeFromEncoded(encodedData);
+ canvas->drawImage(encodedImage, 10, 10);
+
+ sk_sp<SkImage> crossContextImage = SkImage::MakeCrossContextFromEncoded(
+ context, encodedData, false, canvas->imageInfo().colorSpace());
+ canvas->drawImage(crossContextImage, 512 + 30, 10);
+
+ SkIRect subset = SkIRect::MakeXYWH(256 - 64, 256 - 64, 128, 128);
+ sk_sp<SkImage> encodedSubset = encodedImage->makeSubset(subset);
+ sk_sp<SkImage> crossContextSubset = crossContextImage->makeSubset(subset);
+
+ canvas->drawImage(encodedSubset, 10, 512 + 30);
+ canvas->drawImage(crossContextSubset, 512 + 30, 512 + 30);
+}
+
+#endif