aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-04-18 15:52:36 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-18 20:33:58 +0000
commit9440345a81d6c2372ac0aed937080f3da67439dd (patch)
tree6db32e47129a4469dff10d0f980d29a4d04b07ef /include
parent4d8adbccc46b53e44000c433dabade338eb35c6f (diff)
Add backend safe classes for passing in external texture and render targets into gpu
This CL adds the GrBackend* classes as well as just updates the API for SkSurface and SkImage. The implementation on SkSurface/Image and the plumbing down into Ganesh will be in an additional CL. Besides the change to use the type safe classes, we also pull the SurfaceFlags, origin, samples, out of the descriptor and pass those in directly. Bug: skia: Change-Id: I9702981fe26c3d5d7d2cbcf6977ba569d356d854 Reviewed-on: https://skia-review.googlesource.com/13122 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkImage.h51
-rw-r--r--include/core/SkSurface.h24
-rw-r--r--include/gpu/GrBackendSurface.h114
3 files changed, 188 insertions, 1 deletions
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index ace4fe71eb..c52ad3d41e 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -25,6 +25,7 @@ class SkPicture;
class SkPixelSerializer;
class SkString;
class SkSurface;
+class GrBackendTexture;
class GrContext;
class GrContextThreadSafeProxy;
class GrTexture;
@@ -67,7 +68,7 @@ public:
* its pixel memory is shareable, it may be shared instead of copied.
*/
static sk_sp<SkImage> MakeFromBitmap(const SkBitmap&);
-
+
/**
* Construct a new SkImage based on the given ImageGenerator. Returns NULL on error.
* This function will always take ownership of the passed generator.
@@ -90,6 +91,9 @@ public:
* managing the lifetime of the underlying platform texture.
*
* Will return NULL if the specified descriptor is unsupported.
+ *
+ * It is preferred to use the new methods which take a GrBackendTexture instead of a
+ * GrBackendTextureDesc. This method will eventually be removed.
*/
static sk_sp<SkImage> MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc) {
return MakeFromTexture(ctx, desc, kPremul_SkAlphaType, nullptr, nullptr, nullptr);
@@ -108,6 +112,9 @@ public:
* no longer is holding a reference to it.
*
* Will return NULL if the specified descriptor is unsupported.
+ *
+ * It is preferred to use the new methods which take a GrBackendTexture instead of a
+ * GrBackendTextureDesc. This method will eventually be removed.
*/
static sk_sp<SkImage> MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at, TextureReleaseProc trp,
@@ -121,21 +128,63 @@ public:
* no longer is holding a reference to it.
*
* Will return NULL if the specified descriptor is unsupported.
+ *
+ * It is preferred to use the new methods which take a GrBackendTexture instead of a
+ * GrBackendTextureDesc. This method will eventually be removed.
*/
static sk_sp<SkImage> MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
sk_sp<SkColorSpace>, TextureReleaseProc, ReleaseContext);
/**
+ * Create a new image from the specified descriptor. Note - the caller is responsible for
+ * managing the lifetime of the underlying platform texture.
+ *
+ * Will return NULL if the specified backend texture is unsupported.
+ */
+ static sk_sp<SkImage> MakeFromTexture(GrContext* ctx,
+ const GrBackendTexture& tex, GrSurfaceOrigin origin,
+ SkAlphaType at, sk_sp<SkColorSpace> cs) {
+ return MakeFromTexture(ctx, tex, origin, at, cs, nullptr, nullptr);
+ }
+
+ /**
+ * Create a new image from the GrBackendTexture. The underlying platform texture must stay
+ * valid and unaltered until the specified release-proc is invoked, indicating that Skia
+ * no longer is holding a reference to it.
+ *
+ * Will return NULL if the specified backend texture is unsupported.
+ */
+ static sk_sp<SkImage> MakeFromTexture(GrContext*,
+ const GrBackendTexture&, GrSurfaceOrigin origin,
+ SkAlphaType, sk_sp<SkColorSpace>,
+ TextureReleaseProc, ReleaseContext);
+
+
+ /**
* Create a new image from the specified descriptor. Note - Skia will delete or recycle the
* texture when the image is released.
*
* Will return NULL if the specified descriptor is unsupported.
+ *
+ * It is preferred to use the new methods which take a GrBackendTexture instead of a
+ * GrBackendTextureDesc. This method will eventually be removed.
*/
static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType,
sk_sp<SkColorSpace> = nullptr);
/**
+ * Create a new image from the specified descriptor. Note - Skia will delete or recycle the
+ * texture when the image is released.
+ *
+ * Will return NULL if the specified backend texture is unsupported.
+ */
+ static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext*,
+ const GrBackendTexture&, GrSurfaceOrigin,
+ SkAlphaType = kPremul_SkAlphaType,
+ sk_sp<SkColorSpace> = nullptr);
+
+ /**
* Create a new image by copying the pixels from the specified y, u, v textures. The data
* from the textures is immediately ingested into the image and the textures can be modified or
* deleted after the function returns. The image will have the dimensions of the y texture.
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 0e2239a4ad..efa2428ccb 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -14,6 +14,7 @@
class SkCanvas;
class SkPaint;
+class GrBackendRenderTarget;
class GrContext;
class GrRenderTarget;
@@ -88,6 +89,16 @@ public:
sk_sp<SkColorSpace>, const SkSurfaceProps*);
/**
+ * Used to wrap a pre-existing backend 3D API texture as a SkSurface. Skia will not assume
+ * ownership of the texture and the client must ensure the texture is valid for the lifetime
+ * of the SkSurface. If sampleCnt > 0, then we will create an intermediate mssa surface which
+ * we will use for rendering. We then resolve into the passed in texture.
+ */
+ static sk_sp<SkSurface> MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
+ GrSurfaceOrigin origin, int sampleCnt,
+ sk_sp<SkColorSpace>, const SkSurfaceProps*);
+
+ /**
* Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia will not assume
* ownership of the render target and the client must ensure the render target is valid for the
* lifetime of the SkSurface.
@@ -97,6 +108,12 @@ public:
sk_sp<SkColorSpace>,
const SkSurfaceProps*);
+ static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*,
+ const GrBackendRenderTarget&,
+ GrSurfaceOrigin origin,
+ sk_sp<SkColorSpace>,
+ const SkSurfaceProps*);
+
/**
* Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will treat the texture as
* a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own
@@ -108,6 +125,13 @@ public:
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(
GrContext*, const GrBackendTextureDesc&, sk_sp<SkColorSpace>, const SkSurfaceProps*);
+ static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext*,
+ const GrBackendTexture&,
+ GrSurfaceOrigin origin,
+ int sampleCnt,
+ sk_sp<SkColorSpace>,
+ const SkSurfaceProps*);
+
/**
* Legacy versions of the above factories, without color space support. These create "legacy"
* surfaces that operate without gamma correction or color management.
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
new file mode 100644
index 0000000000..e588b8aa3a
--- /dev/null
+++ b/include/gpu/GrBackendSurface.h
@@ -0,0 +1,114 @@
+/*
+ * 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 GrBackendSurface_DEFINED
+#define GrBackendSurface_DEFINED
+
+#include "GrTypes.h"
+
+struct GrVkImageInfo;
+struct GrGLTextureInfo;
+
+class GrBackendTexture {
+public:
+ GrBackendTexture(int width,
+ int height,
+ GrVkImageInfo* vkInfo);
+
+ GrBackendTexture(int width,
+ int height,
+ GrPixelConfig config,
+ GrGLTextureInfo* glInfo);
+
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+ GrPixelConfig config() const { return fConfig; }
+ GrBackend backend() const {return fBackend; }
+
+ // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
+ // it returns nullptr.
+ GrVkImageInfo* getVkImageInfo();
+
+ // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise
+ // it returns nullptr.
+ GrGLTextureInfo* getGLTextureInfo();
+
+private:
+ // Temporary constructor which can be used to convert from a GrBackendTextureDesc.
+ GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend);
+
+ // Friending for access to above constructor taking a GrBackendTextureDesc
+ friend class SkImage;
+ friend class SkSurface;
+
+ int fWidth; //<! width in pixels
+ int fHeight; //<! height in pixels
+ GrPixelConfig fConfig;
+ GrBackend fBackend;
+
+ union {
+ GrVkImageInfo* fVkInfo;
+ GrGLTextureInfo* fGLInfo;
+ GrBackendObject fHandle;
+ };
+};
+
+class GrBackendRenderTarget {
+public:
+ GrBackendRenderTarget(int width,
+ int height,
+ int sampleCnt,
+ int stencilBits,
+ GrVkImageInfo* vkInfo);
+
+ GrBackendRenderTarget(int width,
+ int height,
+ int sampleCnt,
+ int stencilBits,
+ GrPixelConfig config,
+ GrGLTextureInfo* glInfo);
+
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+ int sampleCnt() const { return fSampleCnt; }
+ int stencilBits() const { return fStencilBits; }
+ GrPixelConfig config() const { return fConfig; }
+ GrBackend backend() const {return fBackend; }
+
+ // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
+ // it returns nullptr.
+ GrVkImageInfo* getVkImageInfo();
+
+ // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise
+ // it returns nullptr.
+ GrGLTextureInfo* getGLTextureInfo();
+
+private:
+ // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc.
+ GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, GrBackend backend);
+
+ // Friending for access to above constructor taking a GrBackendTextureDesc
+ friend class SkSurface;
+
+ int fWidth; //<! width in pixels
+ int fHeight; //<! height in pixels
+
+ int fSampleCnt;
+ int fStencilBits;
+ GrPixelConfig fConfig;
+
+ GrBackend fBackend;
+
+ union {
+ GrVkImageInfo* fVkInfo;
+ GrGLTextureInfo* fGLInfo;
+ GrBackendObject fHandle;
+ };
+};
+
+#endif
+