aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/GrProxyProvider.cpp46
-rw-r--r--src/gpu/GrProxyProvider.h12
2 files changed, 58 insertions, 0 deletions
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 7e9c251d33..c492062196 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -17,6 +17,9 @@
#include "GrTextureProxyCacheAccess.h"
#include "GrTextureRenderTargetProxy.h"
#include "../private/GrSingleOwner.h"
+#include "SkGr.h"
+#include "SkImage.h"
+#include "SkImage_Base.h"
#include "SkMipMap.h"
#define ASSERT_SINGLE_OWNER \
@@ -186,6 +189,49 @@ sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(const GrSurfaceDesc& d
return this->createProxy(desc, SkBackingFit::kExact, budgeted);
}
+sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(sk_sp<SkImage> srcImage,
+ GrSurfaceFlags flags,
+ GrSurfaceOrigin origin,
+ int sampleCnt,
+ SkBudgeted budgeted) {
+ ASSERT_SINGLE_OWNER
+ SkASSERT(srcImage);
+
+ if (this->isAbandoned()) {
+ return nullptr;
+ }
+
+ GrSurfaceDesc desc;
+ desc.fWidth = srcImage->width();
+ desc.fHeight = srcImage->height();
+ desc.fFlags = flags;
+ desc.fOrigin = origin;
+ desc.fSampleCnt = sampleCnt;
+ desc.fConfig = SkImageInfo2GrPixelConfig(as_IB(srcImage)->onImageInfo(), *this->caps());
+
+ sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
+ [desc, budgeted, srcImage]
+ (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
+ if (!resourceProvider) {
+ return sk_sp<GrTexture>();
+ }
+ SkPixmap pixMap;
+ SkAssertResult(srcImage->peekPixels(&pixMap));
+ GrMipLevel mipLevel = { pixMap.addr(), pixMap.rowBytes() };
+
+ return resourceProvider->createTexture(desc, budgeted, mipLevel);
+ }, desc, GrMipMapped::kNo, SkBackingFit::kExact, budgeted);
+
+ if (fResourceProvider) {
+ // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
+ // we're better off instantiating the proxy immediately here.
+ if (!proxy->priv().doLazyInstantiation(fResourceProvider)) {
+ return nullptr;
+ }
+ }
+ return proxy;
+}
+
sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(
const GrSurfaceDesc& desc, SkBudgeted budgeted,
const GrMipLevel texels[], int mipLevelCount,
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 8ddd61ce7c..0ac7d4994b 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -18,6 +18,7 @@ class GrCaps;
class GrResourceProvider;
class GrSingleOwner;
class GrBackendRenderTarget;
+class SkImage;
/*
* A factory for creating GrSurfaceProxy-derived objects.
@@ -75,6 +76,17 @@ public:
const void* srcData, size_t rowBytes);
/*
+ * Create an un-mipmapped texture proxy with data. The SkImage must be a raster backend image.
+ * Since the SkImage is ref counted, we simply take a ref on it to keep the data alive until we
+ * actually upload the data to the gpu.
+ */
+ sk_sp<GrTextureProxy> createTextureProxy(sk_sp<SkImage> srcImage,
+ GrSurfaceFlags flags,
+ GrSurfaceOrigin origin,
+ int sampleCnt,
+ SkBudgeted budgeted);
+
+ /*
* Create a mipmapped texture proxy with data.
*
* @param desc Description of the texture properties.