Add createTextureProxy function to ProxyProvider that takes an SkImage
Bug: skia: Change-Id: I46c66dc5b58839596c639b130f19a57cb85529d6 Reviewed-on: https://skia-review.googlesource.com/99700 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
26a8d90d3c
commit
9d86f1d11d
@ -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,
|
||||
|
@ -18,6 +18,7 @@ class GrCaps;
|
||||
class GrResourceProvider;
|
||||
class GrSingleOwner;
|
||||
class GrBackendRenderTarget;
|
||||
class SkImage;
|
||||
|
||||
/*
|
||||
* A factory for creating GrSurfaceProxy-derived objects.
|
||||
@ -74,6 +75,17 @@ public:
|
||||
sk_sp<GrTextureProxy> createTextureProxy(const GrSurfaceDesc&, SkBudgeted,
|
||||
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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user