aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkCrossContextImageData.h
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-02-28 10:02:49 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-28 20:59:57 +0000
commit2c2bc11aea4dfcd7ee2f5859838a2aa0a56939e0 (patch)
tree733d0feaee5fa7695cb1b33a5d9ab5d8a1b2a39e /include/core/SkCrossContextImageData.h
parent585dba831c83447861c1977c2e4896d65d449858 (diff)
Add GrExternalTextureData and SkCrossContextImageData
GrExternalTextureData is an API for exporting the backend-specific information about a texture in a type-safe way, and without pointing into the GrTexture. The new detachBackendTexture API lets us release ownership of a texture to the client. SkCrossContextImageData is the public API that lets clients upload textures on one thread/GrContext, then safely transfer ownership to another thread and GrContext for rendering. Only GL is implemented/supported right now. Vulkan support requires that we add thread-safe memory pools, or otherwise transfer the actual memory block containing the texture to the new context. Re-land of https://skia-review.googlesource.com/c/8529/ BUG=skia: Change-Id: I48ebd57d1ea0cfd3a1db10c475f2903afb821966 Reviewed-on: https://skia-review.googlesource.com/8960 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'include/core/SkCrossContextImageData.h')
-rw-r--r--include/core/SkCrossContextImageData.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/core/SkCrossContextImageData.h b/include/core/SkCrossContextImageData.h
new file mode 100644
index 0000000000..bbee6e742b
--- /dev/null
+++ b/include/core/SkCrossContextImageData.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkCrossContextImageData_DEFINED
+#define SkCrossContextImageData_DEFINED
+
+#include "SkImage.h"
+
+#if SK_SUPPORT_GPU
+#include "GrExternalTextureData.h"
+#endif
+
+class SK_API SkCrossContextImageData : SkNoncopyable {
+public:
+ /**
+ * Decodes and uploads the encoded data to a texture using the supplied GrContext, then
+ * returns an instance of SkCrossContextImageData that can be used to transport that texture
+ * to a different GrContext, across thread boundaries. The GrContext used here, and the one
+ * used to reconstruct the texture-backed image later must be in the same GL share group,
+ * or otherwise be able to share resources. After calling this, you *must* construct exactly
+ * one SkImage from the returned value, using SkImage::MakeFromCrossContextImageData.
+ *
+ * The texture will be decoded and uploaded to be suitable for use with surfaces that have the
+ * supplied destination color space. The color space of the texture itself will be determined
+ * from the encoded data.
+ */
+ static std::unique_ptr<SkCrossContextImageData> MakeFromEncoded(
+ GrContext*, sk_sp<SkData>, SkColorSpace* dstColorSpace);
+
+private:
+ SkCrossContextImageData(sk_sp<SkImage> image) : fImage(std::move(image)) {
+ SkASSERT(!fImage->isTextureBacked());
+ }
+
+#if SK_SUPPORT_GPU
+ SkCrossContextImageData(const GrBackendTextureDesc& desc,
+ std::unique_ptr<GrExternalTextureData> textureData,
+ SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace)
+ : fAlphaType(alphaType)
+ , fColorSpace(std::move(colorSpace))
+ , fDesc(desc)
+ , fTextureData(std::move(textureData)) {
+ // Point our texture desc at our copy of the backend information
+ fDesc.fTextureHandle = fTextureData->getBackendObject();
+ }
+#endif
+
+ // For non-GPU backed images
+ sk_sp<SkImage> fImage;
+
+#if SK_SUPPORT_GPU
+ // GPU-backed images store some generic information (needed to reconstruct the SkImage),
+ // and some backend-specific info (to reconstruct the texture).
+ SkAlphaType fAlphaType;
+ sk_sp<SkColorSpace> fColorSpace;
+ GrBackendTextureDesc fDesc;
+ std::unique_ptr<GrExternalTextureData> fTextureData;
+#endif
+
+ friend class SkImage;
+};
+
+#endif