aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrBackendTextureImageGenerator.h
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 /src/gpu/GrBackendTextureImageGenerator.h
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 'src/gpu/GrBackendTextureImageGenerator.h')
-rw-r--r--src/gpu/GrBackendTextureImageGenerator.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gpu/GrBackendTextureImageGenerator.h b/src/gpu/GrBackendTextureImageGenerator.h
new file mode 100644
index 0000000000..2f35895b5b
--- /dev/null
+++ b/src/gpu/GrBackendTextureImageGenerator.h
@@ -0,0 +1,72 @@
+/*
+ * 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 GrBackendTextureImageGenerator_DEFINED
+#define GrBackendTextureImageGenerator_DEFINED
+
+#include "SkImageGenerator.h"
+
+#include "GrBackendSurface.h"
+#include "SkAtomics.h"
+
+class GrSemaphore;
+
+class GrBackendTextureImageGenerator : public SkImageGenerator {
+public:
+ static std::unique_ptr<SkImageGenerator> Make(sk_sp<GrTexture>, sk_sp<GrSemaphore>,
+ SkAlphaType, sk_sp<SkColorSpace>);
+
+ ~GrBackendTextureImageGenerator();
+
+protected:
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
+ int* ctableCount) override;
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts)
+ override;
+
+#if SK_SUPPORT_GPU
+ sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&,
+ const SkIPoint&) override;
+#endif
+
+private:
+ GrBackendTextureImageGenerator(const SkImageInfo& info, GrTexture*,
+ uint32_t owningContextID, sk_sp<GrSemaphore>,
+ const GrBackendTexture&);
+
+ static void ReleaseRefHelper_TextureReleaseProc(void* ctx);
+
+ class RefHelper : public SkNVRefCnt<RefHelper> {
+ public:
+ RefHelper(GrTexture* texture, uint32_t owningContextID)
+ : fOriginalTexture(texture)
+ , fOwningContextID(owningContextID)
+ , fBorrowedTexture(nullptr)
+ , fBorrowingContextID(SK_InvalidGenID) { }
+
+ ~RefHelper();
+
+ GrTexture* fOriginalTexture;
+ uint32_t fOwningContextID;
+
+ // There is never a ref associated with this pointer. We rely on our atomic bookkeeping
+ // with the context ID to know when this pointer is valid and safe to use. This lets us
+ // avoid releasing a ref from another thread, or get into races during context shutdown.
+ GrTexture* fBorrowedTexture;
+ SkAtomic<uint32_t> fBorrowingContextID;
+ };
+
+ RefHelper* fRefHelper;
+
+ sk_sp<GrSemaphore> fSemaphore;
+ uint32_t fLastBorrowingContextID;
+
+ GrBackendTexture fBackendTexture;
+ GrSurfaceOrigin fSurfaceOrigin;
+
+ typedef SkImageGenerator INHERITED;
+};
+#endif // GrBackendTextureImageGenerator_DEFINED