Revert "Revert "Plumb GrBackendTexture throughout skia.""

This reverts commit 7fa5c31c2c.

Reason for revert: Relanding this change now that other fixes have landed.

Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
> 
> This reverts commit 7da62b9059.
> 
> Reason for revert: fix android roll
> 
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> > 
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > 
> 
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> 
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
> 

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2017-04-20 16:41:55 +00:00 committed by Skia Commit-Bot
parent 774831a4e8
commit 7ef28f35a2
31 changed files with 574 additions and 376 deletions

View File

@ -11,6 +11,7 @@
#if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrContext.h"
#include "GrGpu.h"
#include "GrTest.h"
@ -107,13 +108,11 @@ protected:
GrGLTextureInfo info;
info.fID = id;
info.fTarget = TARGET;
GrBackendTextureDesc desc;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fWidth = width;
desc.fHeight = height;
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, desc)) {
GrBackendTexture rectangleTex(width, height, kRGBA_8888_GrPixelConfig, &info);
if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, rectangleTex,
kTopLeft_GrSurfaceOrigin)) {
return image;
}
GR_GL_CALL(gl, DeleteTextures(1, &id));

View File

@ -12,6 +12,7 @@
#include "SkImage.h"
#if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrExternalTextureData.h"
#endif
@ -68,16 +69,15 @@ public:
~SkCCIDBackendTexture() override {}
private:
SkCCIDBackendTexture(const GrBackendTextureDesc& desc,
SkCCIDBackendTexture(const GrBackendTexture& backendTex,
GrSurfaceOrigin origin,
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();
}
, fBackendTex(backendTex)
, fOrigin(origin)
, fTextureData(std::move(textureData)) {}
sk_sp<SkImage> makeImage(GrContext*) override;
@ -85,7 +85,8 @@ private:
// and some backend-specific info (to reconstruct the texture).
SkAlphaType fAlphaType;
sk_sp<SkColorSpace> fColorSpace;
GrBackendTextureDesc fDesc;
GrBackendTexture fBackendTex;
GrSurfaceOrigin fOrigin;
std::unique_ptr<GrExternalTextureData> fTextureData;
friend class SkCrossContextImageData;

View File

@ -15,14 +15,18 @@ struct GrGLTextureInfo;
class GrBackendTexture {
public:
// The passed in GrVkImageInfo must live until the GrBackendTexture is no longer used in
// creation of SkImages or SkSurfaces.
GrBackendTexture(int width,
int height,
GrVkImageInfo* vkInfo);
const GrVkImageInfo* vkInfo);
// The passed in GrGLTextureInfo must live until the GrBackendTexture is no longer used in
// creation of SkImages or SkSurfaces.
GrBackendTexture(int width,
int height,
GrPixelConfig config,
GrGLTextureInfo* glInfo);
const GrGLTextureInfo* glInfo);
int width() const { return fWidth; }
int height() const { return fHeight; }
@ -31,11 +35,11 @@ public:
// If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
// it returns nullptr.
GrVkImageInfo* getVkImageInfo();
const GrVkImageInfo* getVkImageInfo() const;
// If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise
// it returns nullptr.
GrGLTextureInfo* getGLTextureInfo();
const GrGLTextureInfo* getGLTextureInfo() const;
private:
// Temporary constructor which can be used to convert from a GrBackendTextureDesc.
@ -51,26 +55,30 @@ private:
GrBackend fBackend;
union {
GrVkImageInfo* fVkInfo;
GrGLTextureInfo* fGLInfo;
const GrVkImageInfo* fVkInfo;
const GrGLTextureInfo* fGLInfo;
GrBackendObject fHandle;
};
};
class GrBackendRenderTarget {
public:
// The passed in GrVkImageInfo must live until the GrBackendTexture is no longer used in
// creation of SkImages or SkSurfaces.
GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
GrVkImageInfo* vkInfo);
const GrVkImageInfo* vkInfo);
// The passed in GrGLTextureInfo must live until the GrBackendTexture is no longer used in
// creation of SkImages or SkSurfaces.
GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
GrPixelConfig config,
GrGLTextureInfo* glInfo);
const GrGLTextureInfo* glInfo);
int width() const { return fWidth; }
int height() const { return fHeight; }
@ -81,11 +89,11 @@ public:
// If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
// it returns nullptr.
GrVkImageInfo* getVkImageInfo();
const GrVkImageInfo* getVkImageInfo() const;
// If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise
// it returns nullptr.
GrGLTextureInfo* getGLTextureInfo();
const GrGLTextureInfo* getGLTextureInfo() const;
private:
// Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc.
@ -104,8 +112,8 @@ private:
GrBackend fBackend;
union {
GrVkImageInfo* fVkInfo;
GrGLTextureInfo* fGLInfo;
const GrVkImageInfo* fVkInfo;
const GrGLTextureInfo* fGLInfo;
GrBackendObject fHandle;
};
};

View File

@ -21,6 +21,7 @@ protected:
virtual GrBackendObject getBackendObject() const = 0;
virtual void attachToContext(GrContext*) = 0;
friend class SkCrossContextImageData;
friend class SkCCIDBackendTexture;
friend class SkImage;
};

View File

@ -13,6 +13,7 @@
#include "SkRect.h"
class GrBackendTexture;
class GrCaps;
class GrOpList;
class GrRenderTargetOpList;
@ -189,7 +190,7 @@ public:
const GrSurfaceDesc&, SkBudgeted,
const void* srcData, size_t rowBytes);
static sk_sp<GrSurfaceProxy> MakeWrappedBackend(GrContext*, GrBackendTextureDesc&);
static sk_sp<GrTextureProxy> MakeWrappedBackend(GrContext*, GrBackendTexture&, GrSurfaceOrigin);
const GrSurfaceDesc& desc() const { return fDesc; }

View File

@ -10,20 +10,27 @@
#ifdef SK_VULKAN
#include "vk/GrVkTypes.h"
#include "vk/GrVkUtil.h"
#endif
GrBackendTexture::GrBackendTexture(int width,
int height,
GrVkImageInfo* vkInfo)
const GrVkImageInfo* vkInfo)
: fWidth(width)
, fHeight(height)
, fConfig(GrVkFormatToPixelConfig(vkInfo->fFormat))
, fConfig(
#ifdef SK_VULKAN
GrVkFormatToPixelConfig(vkInfo->fFormat)
#else
kUnknown_GrPixelConfig
#endif
)
, fBackend(kVulkan_GrBackend)
, fVkInfo(vkInfo) {}
#endif // SK_VULKAN
GrBackendTexture::GrBackendTexture(int width,
int height,
GrPixelConfig config,
GrGLTextureInfo* glInfo)
const GrGLTextureInfo* glInfo)
: fWidth(width)
, fHeight(height)
, fConfig(config)
@ -43,14 +50,14 @@ GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend b
, fBackend(backend)
, fHandle(desc.fTextureHandle) {}
GrVkImageInfo* GrBackendTexture::getVkImageInfo() {
const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) {
return fVkInfo;
}
return nullptr;
}
GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() {
const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
if (kOpenGL_GrBackend == fBackend) {
return fGLInfo;
}
@ -59,27 +66,31 @@ GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() {
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef SK_VULKAN
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
GrVkImageInfo* vkInfo)
const GrVkImageInfo* vkInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(sampleCnt)
, fStencilBits(stencilBits)
, fConfig(GrVkFormatToPixelConfig(vkInfo->fFormat))
, fConfig(
#ifdef SK_VULKAN
GrVkFormatToPixelConfig(vkInfo->fFormat)
#else
kUnknown_GrPixelConfig
#endif
)
, fBackend(kVulkan_GrBackend)
, fVkInfo(vkInfo) {}
#endif // SK_VULKAN
GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
GrPixelConfig config,
GrGLTextureInfo* glInfo)
const GrGLTextureInfo* glInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(sampleCnt)
@ -104,14 +115,14 @@ GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& de
, fBackend(backend)
, fHandle(desc.fRenderTargetHandle) {}
GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() {
const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) {
return fVkInfo;
}
return nullptr;
}
GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() {
const GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() const {
if (kOpenGL_GrBackend == fBackend) {
return fGLInfo;
}

View File

@ -658,11 +658,15 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfac
return this->makeWrappedSurfaceContext(std::move(proxy), nullptr);
}
sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace) {
ASSERT_SINGLE_OWNER_PRIV
sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(desc));
sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(tex, origin,
flags, sampleCnt));
if (!surface) {
return nullptr;
}
@ -676,13 +680,16 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackend
}
sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext(
const GrBackendTextureDesc& desc,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
ASSERT_SINGLE_OWNER_PRIV
SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(desc));
static const GrBackendTextureFlags kForceRT = kRenderTarget_GrBackendTextureFlag;
sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(tex, origin, kForceRT,
sampleCnt));
if (!surface) {
return nullptr;
}
@ -718,13 +725,17 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetC
}
sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext(
const GrBackendTextureDesc& desc,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
ASSERT_SINGLE_OWNER_PRIV
SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget(desc));
sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget(
tex,
origin,
sampleCnt));
if (!surface) {
return nullptr;
}

View File

@ -38,11 +38,16 @@ public:
// TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove
// makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext
sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace);
sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
const GrBackendTextureDesc& desc,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr);
@ -52,7 +57,9 @@ public:
const SkSurfaceProps* = nullptr);
sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
const GrBackendTextureDesc& desc,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr);

View File

@ -8,6 +8,7 @@
#include "GrGpu.h"
#include "GrBackendSurface.h"
#include "GrBuffer.h"
#include "GrCaps.h"
#include "GrContext.h"
@ -192,21 +193,25 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget
return tex;
}
sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc,
sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
GrWrapOwnership ownership) {
this->handleDirtyContext();
if (!this->caps()->isConfigTexturable(desc.fConfig)) {
if (!this->caps()->isConfigTexturable(backendTex.config())) {
return nullptr;
}
if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) &&
!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
if ((flags & kRenderTarget_GrBackendTextureFlag) &&
!this->caps()->isConfigRenderable(backendTex.config(), sampleCnt > 0)) {
return nullptr;
}
int maxSize = this->caps()->maxTextureSize();
if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
if (backendTex.width() > maxSize || backendTex.height() > maxSize) {
return nullptr;
}
sk_sp<GrTexture> tex = this->onWrapBackendTexture(desc, ownership);
sk_sp<GrTexture> tex = this->onWrapBackendTexture(backendTex, origin, flags, sampleCnt,
ownership);
if (!tex) {
return nullptr;
}
@ -226,19 +231,18 @@ sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget
return this->onWrapBackendRenderTarget(desc);
}
sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) {
sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt) {
this->handleDirtyContext();
if (!(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
return nullptr;
}
if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
if (!this->caps()->isConfigRenderable(tex.config(), sampleCnt > 0)) {
return nullptr;
}
int maxSize = this->caps()->maxTextureSize();
if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
if (tex.width() > maxSize || tex.height() > maxSize) {
return nullptr;
}
return this->onWrapBackendTextureAsRenderTarget(desc);
return this->onWrapBackendTextureAsRenderTarget(tex, origin, sampleCnt);
}
GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType,

View File

@ -124,7 +124,8 @@ public:
/**
* Implements GrResourceProvider::wrapBackendTexture
*/
sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership);
sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
GrBackendTextureFlags, int sampleCnt, GrWrapOwnership);
/**
* Implements GrResourceProvider::wrapBackendRenderTarget
@ -134,7 +135,9 @@ public:
/**
* Implements GrResourceProvider::wrapBackendTextureAsRenderTarget
*/
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&);
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
int sampleCnt);
/**
* Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked.
@ -542,9 +545,15 @@ private:
SkBudgeted budgeted,
const SkTArray<GrMipLevel>& texels) = 0;
virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
GrSurfaceOrigin,
GrBackendTextureFlags,
int sampleCnt,
GrWrapOwnership) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
int sampleCnt)=0;
virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
const void* data) = 0;

View File

@ -240,13 +240,16 @@ GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
return nullptr;
}
sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTextureDesc& desc,
sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
GrWrapOwnership ownership) {
ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
return fGpu->wrapBackendTexture(desc, ownership);
return fGpu->wrapBackendTexture(tex, origin, flags, sampleCnt, ownership);
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
@ -466,12 +469,12 @@ GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget*
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget(
const GrBackendTextureDesc& desc)
const GrBackendTexture& tex, GrSurfaceOrigin origin, int sampleCnt)
{
if (this->isAbandoned()) {
return nullptr;
}
return this->gpu()->wrapBackendTextureAsRenderTarget(desc);
return this->gpu()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt);
}
sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore() {

View File

@ -85,7 +85,10 @@ public:
*
* @return GrTexture object or NULL on failure.
*/
sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc& desc,
sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
GrWrapOwnership = kBorrow_GrWrapOwnership);
/**
@ -199,7 +202,9 @@ public:
*
* @return GrRenderTarget object or NULL on failure.
*/
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc);
sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin origin,
int sampleCnt);
/**
* Assigns a unique key to a resource. If the key is associated with another resource that

View File

@ -222,9 +222,11 @@ sk_sp<GrTextureProxy> GrSurfaceProxy::MakeDeferred(GrResourceProvider* resourceP
return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, SkBackingFit::kExact, budgeted);
}
sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context,
GrBackendTextureDesc& desc) {
sk_sp<GrTexture> tex(context->resourceProvider()->wrapBackendTexture(desc));
sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context,
GrBackendTexture& backendTex,
GrSurfaceOrigin origin) {
sk_sp<GrTexture> tex(context->resourceProvider()->wrapBackendTexture(
backendTex, origin, kNone_GrBackendTextureFlag, 0));
return GrSurfaceProxy::MakeWrapped(std::move(tex));
}

View File

@ -8,6 +8,7 @@
#include "GrGLGpu.h"
#include "../private/GrGLSL.h"
#include "GrBackendSurface.h"
#include "GrFixedClip.h"
#include "GrGLBuffer.h"
#include "GrGLGpuCommandBuffer.h"
@ -511,15 +512,18 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget)
}
}
sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
GrWrapOwnership ownership) {
const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
const GrGLTextureInfo* info = backendTex.getGLTextureInfo();
if (!info || !info->fID) {
return nullptr;
}
// next line relies on GrBackendTextureDesc's flags matching GrTexture's
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
// next line relies on GrBackendTextureFlags matching GrTexture's
bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag);
SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported
GrGLTexture::IDDesc idDesc;
@ -543,7 +547,7 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
// Sample count is interpreted to mean the number of samples that Gr code should allocate
// for a render buffer that resolves to the texture. We don't support MSAA textures.
if (desc.fSampleCnt && !renderTarget) {
if (sampleCnt && !renderTarget) {
return nullptr;
}
@ -554,19 +558,19 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
}
GrSurfaceDesc surfDesc;
surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
surfDesc.fWidth = desc.fWidth;
surfDesc.fHeight = desc.fHeight;
surfDesc.fConfig = desc.fConfig;
surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
surfDesc.fFlags = (GrSurfaceFlags) flags;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
surfDesc.fConfig = backendTex.config();
surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount());
// FIXME: this should be calling resolve_origin(), but Chrome code is currently
// assuming the old behaviour, which is that backend textures are always
// BottomLeft, even for non-RT's. Once Chrome is fixed, change this to:
// glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
if (kDefault_GrSurfaceOrigin == origin) {
surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
} else {
surfDesc.fOrigin = desc.fOrigin;
surfDesc.fOrigin = origin;
}
if (renderTarget) {
@ -603,8 +607,10 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, wrapDesc.fStencilBits);
}
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc){
const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt) {
const GrGLTextureInfo* info = tex.getGLTextureInfo();
if (!info || !info->fID) {
return nullptr;
}
@ -621,19 +627,19 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBacken
}
GrSurfaceDesc surfDesc;
surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
surfDesc.fWidth = desc.fWidth;
surfDesc.fHeight = desc.fHeight;
surfDesc.fConfig = desc.fConfig;
surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
surfDesc.fWidth = tex.width();
surfDesc.fHeight = tex.height();
surfDesc.fConfig = tex.config();
surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount());
// FIXME: this should be calling resolve_origin(), but Chrome code is currently
// assuming the old behaviour, which is that backend textures are always
// BottomLeft, even for non-RT's. Once Chrome is fixed, change this to:
// glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
if (kDefault_GrSurfaceOrigin == origin) {
surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
} else {
surfDesc.fOrigin = desc.fOrigin;
surfDesc.fOrigin = origin;
}
GrGLRenderTarget::IDDesc rtIDDesc;

View File

@ -170,9 +170,16 @@ private:
GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
const void* data) override;
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
GrSurfaceOrigin,
GrBackendTextureFlags,
int sampleCnt,
GrWrapOwnership) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
int sampleCnt) override;
gr_instanced::InstancedRendering* onCreateInstancedRendering() override;

View File

@ -7,6 +7,7 @@
#include "GrVkGpu.h"
#include "GrBackendSurface.h"
#include "GrContextOptions.h"
#include "GrGeometryProcessor.h"
#include "GrGpuResourceCacheAccess.h"
@ -780,41 +781,39 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) {
}
}
sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
GrSurfaceOrigin origin,
GrBackendTextureFlags flags,
int sampleCnt,
GrWrapOwnership ownership) {
if (0 == desc.fTextureHandle) {
const GrVkImageInfo* info = backendTex.getVkImageInfo();
if (!info) {
return nullptr;
}
int maxSize = this->caps()->maxTextureSize();
if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
if (backendTex.width() > maxSize || backendTex.height() > maxSize) {
return nullptr;
}
const GrVkImageInfo* info = reinterpret_cast<const GrVkImageInfo*>(desc.fTextureHandle);
if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc.fMemory) {
return nullptr;
}
#ifdef SK_DEBUG
VkFormat format;
if (!GrPixelConfigToVkFormat(desc.fConfig, &format)) {
return nullptr;
}
SkASSERT(format == info->fFormat);
#endif
SkASSERT(backendTex.config() == GrVkFormatToPixelConfig(info->fFormat));
GrSurfaceDesc surfDesc;
// next line relies on GrBackendTextureDesc's flags matching GrTexture's
surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags;
surfDesc.fWidth = desc.fWidth;
surfDesc.fHeight = desc.fHeight;
surfDesc.fConfig = desc.fConfig;
surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
// next line relies on GrBackendTextureFlags matching GrTexture's
surfDesc.fFlags = (GrSurfaceFlags)flags;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
surfDesc.fConfig = backendTex.config();
surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount());
bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag);
SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported
// In GL, Chrome assumes all textures are BottomLeft
// In VK, we don't have this restriction
surfDesc.fOrigin = resolve_origin(desc.fOrigin);
surfDesc.fOrigin = resolve_origin(origin);
if (!renderTarget) {
return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info);
@ -848,23 +847,23 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
return tgt;
}
sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(
const GrBackendTextureDesc& wrapDesc){
sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt) {
const GrVkImageInfo* info =
reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fTextureHandle);
const GrVkImageInfo* info = tex.getVkImageInfo();
if (VK_NULL_HANDLE == info->fImage) {
return nullptr;
}
GrSurfaceDesc desc;
desc.fFlags = (GrSurfaceFlags) wrapDesc.fFlags;
desc.fConfig = wrapDesc.fConfig;
desc.fWidth = wrapDesc.fWidth;
desc.fHeight = wrapDesc.fHeight;
desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount());
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = tex.config();
desc.fWidth = tex.width();
desc.fHeight = tex.height();
desc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount());
desc.fOrigin = resolve_origin(wrapDesc.fOrigin);
desc.fOrigin = resolve_origin(origin);
sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info);
return tgt;

View File

@ -175,10 +175,16 @@ private:
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted,
const SkTArray<GrMipLevel>&) override { return NULL; }
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
GrSurfaceOrigin,
GrBackendTextureFlags,
int sampleCnt,
GrWrapOwnership) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
int sampleCnt) override;
GrBuffer* onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern,
const void* data) override;

View File

@ -10,6 +10,7 @@
#include <type_traits>
#include "SkAutoPixmapStorage.h"
#include "GrBackendSurface.h"
#include "GrBitmapTextureMaker.h"
#include "GrCaps.h"
#include "GrContext.h"
@ -252,16 +253,23 @@ sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
const GrBackendTexture& backendTex,
GrSurfaceOrigin origin,
SkAlphaType at, sk_sp<SkColorSpace> colorSpace,
GrWrapOwnership ownership,
SkImage::TextureReleaseProc releaseProc,
SkImage::ReleaseContext releaseCtx) {
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
if (backendTex.width() <= 0 || backendTex.height() <= 0) {
return nullptr;
}
sk_sp<GrTexture> tex = ctx->resourceProvider()->wrapBackendTexture(desc, ownership);
GrBackendTextureFlags flags = kNone_GrBackendTextureFlag;
sk_sp<GrTexture> tex = ctx->resourceProvider()->wrapBackendTexture(backendTex,
origin,
flags,
0,
ownership);
if (!tex) {
return nullptr;
}
@ -279,13 +287,19 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at, sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWrapOwnership,
SkASSERT(!(kRenderTarget_GrBackendTextureFlag & desc.fFlags));
GrBackendTexture tex(desc, ctx->contextPriv().getBackend());
return new_wrapped_texture_common(ctx, tex, desc.fOrigin, at, std::move(cs),
kBorrow_GrWrapOwnership,
releaseP, releaseC);
}
sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at, sk_sp<SkColorSpace> cs) {
return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kAdopt_GrWrapOwnership,
SkASSERT(!(kRenderTarget_GrBackendTextureFlag & desc.fFlags));
GrBackendTexture tex(desc, ctx->contextPriv().getBackend());
return new_wrapped_texture_common(ctx, tex, desc.fOrigin, at, std::move(cs),
kAdopt_GrWrapOwnership,
nullptr, nullptr);
}
@ -293,17 +307,30 @@ sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
const GrBackendTexture& tex, GrSurfaceOrigin origin,
SkAlphaType at, sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
// This function is not implemented yet
sk_throw();
return nullptr;
return new_wrapped_texture_common(ctx, tex, origin, at, std::move(cs), kBorrow_GrWrapOwnership,
releaseP, releaseC);
}
sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx,
const GrBackendTexture& tex, GrSurfaceOrigin origin,
SkAlphaType at, sk_sp<SkColorSpace> cs) {
// This function is not implemented yet
sk_throw();
return nullptr;
return new_wrapped_texture_common(ctx, tex, origin, at, std::move(cs), kAdopt_GrWrapOwnership,
nullptr, nullptr);
}
static GrBackendTexture make_backend_texture_from_handle(GrBackend backend,
int width, int height,
GrPixelConfig config,
GrBackendObject handle) {
if (kOpenGL_GrBackend == backend) {
GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
return GrBackendTexture(width, height, config, glInfo);
} else {
SkASSERT(kVulkan_GrBackend == backend);
GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
return GrBackendTexture(width, height, vkInfo);
}
}
static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpace colorSpace,
@ -324,38 +351,31 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
const GrPixelConfig kConfig = nv12 ? kRGBA_8888_GrPixelConfig : kAlpha_8_GrPixelConfig;
GrBackendTextureDesc yDesc;
yDesc.fConfig = kConfig;
yDesc.fOrigin = origin;
yDesc.fSampleCnt = 0;
yDesc.fTextureHandle = yuvTextureHandles[0];
yDesc.fWidth = yuvSizes[0].fWidth;
yDesc.fHeight = yuvSizes[0].fHeight;
GrBackend backend = ctx->contextPriv().getBackend();
GrBackendTexture yTex = make_backend_texture_from_handle(backend,
yuvSizes[0].fWidth,
yuvSizes[0].fHeight,
kConfig,
yuvTextureHandles[0]);
GrBackendTexture uTex = make_backend_texture_from_handle(backend,
yuvSizes[1].fWidth,
yuvSizes[1].fHeight,
kConfig,
yuvTextureHandles[1]);
GrBackendTextureDesc uDesc;
uDesc.fConfig = kConfig;
uDesc.fOrigin = origin;
uDesc.fSampleCnt = 0;
uDesc.fTextureHandle = yuvTextureHandles[1];
uDesc.fWidth = yuvSizes[1].fWidth;
uDesc.fHeight = yuvSizes[1].fHeight;
sk_sp<GrSurfaceProxy> yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yDesc);
sk_sp<GrSurfaceProxy> uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uDesc);
sk_sp<GrSurfaceProxy> vProxy;
sk_sp<GrTextureProxy> yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yTex, origin);
sk_sp<GrTextureProxy> uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uTex, origin);
sk_sp<GrTextureProxy> vProxy;
if (nv12) {
vProxy = uProxy;
} else {
GrBackendTextureDesc vDesc;
vDesc.fConfig = kConfig;
vDesc.fOrigin = origin;
vDesc.fSampleCnt = 0;
vDesc.fTextureHandle = yuvTextureHandles[2];
vDesc.fWidth = yuvSizes[2].fWidth;
vDesc.fHeight = yuvSizes[2].fHeight;
vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vDesc);
GrBackendTexture vTex = make_backend_texture_from_handle(backend,
yuvSizes[2].fWidth,
yuvSizes[2].fHeight,
kConfig,
yuvTextureHandles[2]);
vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vTex, origin);
}
if (!yProxy || !uProxy || !vProxy) {
return nullptr;
@ -380,9 +400,8 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
paint.addColorFragmentProcessor(
GrYUVEffect::MakeYUVToRGB(ctx->resourceProvider(),
sk_ref_sp(yProxy->asTextureProxy()),
sk_ref_sp(uProxy->asTextureProxy()),
sk_ref_sp(vProxy->asTextureProxy()), yuvSizes, colorSpace, nv12));
yProxy, uProxy, vProxy,
yuvSizes, colorSpace, nv12));
const SkRect rect = SkRect::MakeIWH(width, height);
@ -476,21 +495,21 @@ std::unique_ptr<SkCrossContextImageData> SkCrossContextImageData::MakeFromEncode
GrTexture* texture = as_IB(textureImage)->peekTexture();
SkASSERT(texture);
GrBackendTextureDesc desc;
desc.fFlags = kNone_GrBackendTextureFlag;
desc.fOrigin = texture->origin();
desc.fWidth = texture->width();
desc.fHeight = texture->height();
desc.fConfig = texture->config();
desc.fSampleCnt = 0;
context->contextPriv().prepareSurfaceForExternalIO(as_IB(textureImage)->peekProxy());
auto textureData = texture->texturePriv().detachBackendTexture();
SkASSERT(textureData);
GrBackend backend = context->contextPriv().getBackend();
GrBackendTexture backendTex = make_backend_texture_from_handle(backend,
texture->width(),
texture->height(),
texture->config(),
textureData->getBackendObject());
SkImageInfo info = as_IB(textureImage)->onImageInfo();
return std::unique_ptr<SkCrossContextImageData>(new SkCCIDBackendTexture(
desc, std::move(textureData), info.alphaType(), info.refColorSpace()));
backendTex, texture->origin(), std::move(textureData),
info.alphaType(), info.refColorSpace()));
}
sk_sp<SkImage> SkCCIDBackendTexture::makeImage(GrContext* context) {
@ -501,7 +520,7 @@ sk_sp<SkImage> SkCCIDBackendTexture::makeImage(GrContext* context) {
// This texture was created by Ganesh on another thread (see MakeFromEncoded, above).
// Thus, we can import it back into our cache and treat it as our own (again).
GrWrapOwnership ownership = kAdoptAndCache_GrWrapOwnership;
return new_wrapped_texture_common(context, fDesc, fAlphaType,
return new_wrapped_texture_common(context, fBackendTex, fOrigin, fAlphaType,
std::move(fColorSpace), ownership, nullptr, nullptr);
}

View File

@ -7,6 +7,7 @@
#include "SkSurface_Gpu.h"
#include "GrBackendSurface.h"
#include "GrContextPriv.h"
#include "GrRenderTargetContextPriv.h"
#include "GrResourceProvider.h"
@ -220,22 +221,32 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
if (!context) {
return nullptr;
}
if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
GrBackendTexture tex(desc, context->contextPriv().getBackend());
return MakeFromBackendTexture(context, tex, desc.fOrigin, desc.fSampleCnt, colorSpace, props);
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex,
GrSurfaceOrigin origin, int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!context) {
return nullptr;
}
if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) {
if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) {
return nullptr;
}
sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeBackendTextureRenderTargetContext(
desc,
tex,
origin,
sampleCnt,
std::move(colorSpace),
props));
if (!rtc) {
return nullptr;
}
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), desc.fWidth, desc.fHeight,
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(),
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
@ -243,14 +254,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
GrSurfaceOrigin origin, int sampleCnt,
sk_sp<SkColorSpace>, const SkSurfaceProps*) {
// This function is not implemented yet
sk_throw();
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
const GrBackendRenderTargetDesc& desc,
sk_sp<SkColorSpace> colorSpace,
@ -296,20 +299,36 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont
if (!context) {
return nullptr;
}
if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) {
GrBackendTexture tex(desc, context->contextPriv().getBackend());
return MakeFromBackendTextureAsRenderTarget(context, tex, desc.fOrigin, desc.fSampleCnt,
std::move(colorSpace), props);
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!context) {
return nullptr;
}
if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) {
return nullptr;
}
sk_sp<GrRenderTargetContext> rtc(
context->contextPriv().makeBackendTextureAsRenderTargetRenderTargetContext(
desc,
tex,
origin,
sampleCnt,
std::move(colorSpace),
props));
if (!rtc) {
return nullptr;
}
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), desc.fWidth, desc.fHeight,
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(),
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
@ -317,15 +336,4 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont
return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext*,
const GrBackendTexture&,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace>,
const SkSurfaceProps*) {
// This function is not implemented yet
sk_throw();
return nullptr;
}
#endif

View File

@ -21,6 +21,7 @@
#include "GrResourceProvider.h"
#include "GrSurfaceContext.h"
#include "GrSurfaceProxy.h"
#include "GrTest.h"
#include "GrTexture.h"
#endif
@ -99,16 +100,16 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
return nullptr;
}
GrBackendTextureDesc desc;
desc.fFlags = kRenderTarget_GrBackendTextureFlag;
desc.fOrigin = origin;
desc.fWidth = width;
desc.fHeight = height;
desc.fConfig = config;
desc.fSampleCnt = sampleCnt;
desc.fTextureHandle = (*backingSurface)->getTextureHandle();
GrBackendTexture backendTex =
GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
width,
height,
config,
(*backingSurface)->getTextureHandle());
sk_sp<SkSurface> surface =
SkSurface::MakeFromBackendTextureAsRenderTarget(context, desc, nullptr);
SkSurface::MakeFromBackendTextureAsRenderTarget(context, backendTex, origin,
sampleCnt, nullptr, nullptr);
return surface;
}
}

View File

@ -13,6 +13,7 @@
#include "GrContextFactory.h"
#include "GrShaderCaps.h"
#include "GrSurfaceContext.h"
#include "GrTest.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLUtil.h"
#include "gl/GLTestContext.h"
@ -129,14 +130,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
externalTexture.fID = glCtx0->eglImageToExternalTexture(image);
// Wrap this texture ID in a GrTexture
GrBackendTextureDesc externalDesc;
externalDesc.fConfig = kRGBA_8888_GrPixelConfig;
externalDesc.fWidth = kSize;
externalDesc.fHeight = kSize;
externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTexture);
GrBackendTexture backendTex(kSize, kSize, kRGBA_8888_GrPixelConfig, &externalTexture);
// TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test
// fails on the Nexus5. Why?
sk_sp<GrSurfaceContext> surfaceContext = context0->contextPriv().makeBackendSurfaceContext(
externalDesc, nullptr);
backendTex, kBottomLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, nullptr);
if (!surfaceContext) {
ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
@ -146,25 +145,21 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
// Should not be able to wrap as a RT
{
externalDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
sk_sp<GrSurfaceContext> temp = context0->contextPriv().makeBackendSurfaceContext(
externalDesc, nullptr);
backendTex, kBottomLeft_GrSurfaceOrigin, kRenderTarget_GrBackendTextureFlag, 0,
nullptr);
if (temp) {
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT.");
}
externalDesc.fFlags = kNone_GrBackendTextureFlag;
}
// Should not be able to wrap with a sample count
{
externalDesc.fSampleCnt = 4;
sk_sp<GrSurfaceContext> temp = context0->contextPriv().makeBackendSurfaceContext(
externalDesc, nullptr);
backendTex, kBottomLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 4, nullptr);
if (temp) {
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture with MSAA.");
}
externalDesc.fSampleCnt = 0;
}
test_read_pixels(reporter, surfaceContext.get(), pixels.get(), "EGLImageTest-read");

View File

@ -11,8 +11,10 @@
#include "GrContextFactory.h"
#include "GrContextOptions.h"
#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrResourceProvider.h"
#include "GrTest.h"
#include "GrXferProcessor.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "gl/GrGLCaps.h"
@ -1034,15 +1036,19 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
return;
}
GrBackendObject backendTex =
GrBackendObject backendTexHandle =
ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100, kRGBA_8888_GrPixelConfig);
GrBackendTextureDesc fakeDesc;
fakeDesc.fConfig = kRGBA_8888_GrPixelConfig;
fakeDesc.fWidth = fakeDesc.fHeight = 100;
fakeDesc.fTextureHandle = backendTex;
GrBackendTexture backendTex = GrTest::CreateBackendTexture(ctx->contextPriv().getBackend(),
100,
100,
kRGBA_8888_GrPixelConfig,
backendTexHandle);
GrXferProcessor::DstTexture fakeDstTexture;
fakeDstTexture.setTexture(
ctx->resourceProvider()->wrapBackendTexture(fakeDesc, kBorrow_GrWrapOwnership));
ctx->resourceProvider()->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag, 0,
kBorrow_GrWrapOwnership));
static const GrProcessorAnalysisColor colorInputs[] = {
GrProcessorAnalysisColor::Opaque::kNo, GrProcessorAnalysisColor::Opaque::kYes,
@ -1065,7 +1071,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
}
}
}
ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
}
#endif

View File

@ -10,9 +10,11 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrRenderTarget.h"
#include "GrResourceProvider.h"
#include "GrTest.h"
#include "GrTexture.h"
#include "GrSurfacePriv.h"
#include "Test.h"
@ -44,18 +46,18 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
GrBackendObject backendTexHandle = context->getGpu()->createTestingOnlyBackendTexture(
nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
256,
256,
kRGBA_8888_GrPixelConfig,
backendTexHandle);
GrBackendTextureDesc backendDesc;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
backendDesc.fWidth = 256;
backendDesc.fHeight = 256;
backendDesc.fSampleCnt = 0;
backendDesc.fTextureHandle = backendTex;
sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapBackendTexture(
backendDesc, kBorrow_GrWrapOwnership);
backendTex, kTopLeft_GrSurfaceOrigin, kRenderTarget_GrBackendTextureFlag, 0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
@ -65,7 +67,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
static_cast<GrSurface*>(texRT2->asTexture()));
context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
context->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
}
#endif

View File

@ -179,7 +179,9 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) {
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrResourceProvider.h"
#include "GrTest.h"
static sk_sp<GrTextureProxy> create_proxy(GrResourceProvider* resourceProvider) {
SkBitmap srcBM = create_bm();
@ -209,17 +211,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct
return;
}
GrBackendTextureDesc backendDesc;
backendDesc.fFlags = kNone_GrBackendTextureFlag;
backendDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fWidth = kFullSize;
backendDesc.fHeight = kFullSize;
backendDesc.fSampleCnt = 0;
backendDesc.fTextureHandle = tex->getTextureHandle();
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kFullSize,
kFullSize,
kRGBA_8888_GrPixelConfig,
tex->getTextureHandle());
GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin;
sk_sp<SkImage> srcImage(SkImage::MakeFromTexture(context,
backendDesc,
kPremul_SkAlphaType));
backendTex,
texOrigin,
kPremul_SkAlphaType, nullptr));
if (!srcImage) {
return;
}
@ -228,18 +229,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct
GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin);
// TODO: Make it so we can check this (see skbug.com/5019)
#if 0
if (readBackHandle != backendDesc.fTextureHandle) {
if (readBackHandle != tex->getTextureHandle()) {
ERRORF(reporter, "backend mismatch %d %d\n",
(int)readBackHandle, (int)backendDesc.fTextureHandle);
(int)readBackHandle, (int)tex->getTextureHandle());
}
REPORTER_ASSERT(reporter, readBackHandle == backendDesc.fTextureHandle);
REPORTER_ASSERT(reporter, readBackHandle == tex->getTextureHandle());
#else
REPORTER_ASSERT(reporter, SkToBool(readBackHandle));
#endif
if (readBackOrigin != backendDesc.fOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, backendDesc.fOrigin);
if (readBackOrigin != texOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin);
}
REPORTER_ASSERT(reporter, readBackOrigin == backendDesc.fOrigin);
REPORTER_ASSERT(reporter, readBackOrigin == texOrigin);
test_image_backed(reporter, srcImage);
}

View File

@ -32,7 +32,9 @@
#include "sk_tool_utils.h"
#if SK_SUPPORT_GPU
#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrTest.h"
#endif
using namespace sk_gpu_test;
@ -808,44 +810,48 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
const int kWidth = 10;
const int kHeight = 10;
std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
GrBackendTextureDesc backendDesc;
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
backendDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
backendDesc.fWidth = kWidth;
backendDesc.fHeight = kHeight;
backendDesc.fSampleCnt = 0;
backendDesc.fTextureHandle = ctxInfo.grContext()->getGpu()->createTestingOnlyBackendTexture(
pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true);
GrContext* ctx = ctxInfo.grContext();
GrBackendObject backendTexHandle =
ctxInfo.grContext()->getGpu()->createTestingOnlyBackendTexture(
pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true);
GrBackendTexture backendTex = GrTest::CreateBackendTexture(ctx->contextPriv().getBackend(),
kWidth,
kHeight,
kRGBA_8888_GrPixelConfig,
backendTexHandle);
TextureReleaseChecker releaseChecker;
GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin;
sk_sp<SkImage> refImg(
SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlphaType,
SkImage::MakeFromTexture(ctx, backendTex, texOrigin, kPremul_SkAlphaType, nullptr,
TextureReleaseChecker::Release, &releaseChecker));
GrSurfaceOrigin readBackOrigin;
GrBackendObject readBackHandle = refImg->getTextureHandle(false, &readBackOrigin);
// TODO: Make it so we can check this (see skbug.com/5019)
#if 0
if (*readBackHandle != *(backendDesc.fTextureHandle)) {
if (*readBackHandle != *(backendTexHandle)) {
ERRORF(reporter, "backend mismatch %d %d\n",
(int)readBackHandle, (int)backendDesc.fTextureHandle);
(int)readBackHandle, (int)backendTexHandle);
}
REPORTER_ASSERT(reporter, readBackHandle == backendDesc.fTextureHandle);
REPORTER_ASSERT(reporter, readBackHandle == backendTexHandle);
#else
REPORTER_ASSERT(reporter, SkToBool(readBackHandle));
#endif
if (readBackOrigin != backendDesc.fOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, backendDesc.fOrigin);
if (readBackOrigin != texOrigin) {
ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin);
}
REPORTER_ASSERT(reporter, readBackOrigin == backendDesc.fOrigin);
REPORTER_ASSERT(reporter, readBackOrigin == texOrigin);
// Now exercise the release proc
REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
refImg.reset(nullptr); // force a release of the image
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendDesc.fTextureHandle);
ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
}
static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, const SkImage* b) {

View File

@ -13,13 +13,14 @@
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrRenderTargetContext.h"
#include "GrTest.h"
#include "gl/GLTestContext.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLUtil.h"
// skbug.com/5932
static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* context,
sk_sp<GrSurfaceProxy> rectProxy, uint32_t expectedPixelValues[]) {
sk_sp<GrTextureProxy> rectProxy, uint32_t expectedPixelValues[]) {
sk_sp<GrRenderTargetContext> rtContext(
context->makeRenderTargetContext(SkBackingFit::kExact, rectProxy->width(),
rectProxy->height(), rectProxy->config(),
@ -30,7 +31,7 @@ static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* cont
rtContext->clear(nullptr, 0xDDCCBBAA, true);
sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(
context->resourceProvider(),
sk_ref_sp(rectProxy->asTextureProxy()),
rectProxy,
nullptr,
SkMatrix::I(), filter));
GrPaint paint;
@ -99,7 +100,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
}
}
for (int origin = 0; origin < 2; ++origin) {
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
bool useBLOrigin = kBottomLeft_GrSurfaceOrigin == origin;
GrGLuint rectTexID = glContext->createTextureRectangle(kWidth, kHeight, GR_GL_RGBA,
GR_GL_RGBA, GR_GL_UNSIGNED_BYTE,
pixels);
@ -116,25 +119,19 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
rectangleInfo.fID = rectTexID;
rectangleInfo.fTarget = GR_GL_TEXTURE_RECTANGLE;
GrBackendTextureDesc rectangleDesc;
rectangleDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
rectangleDesc.fConfig = kRGBA_8888_GrPixelConfig;
rectangleDesc.fWidth = kWidth;
rectangleDesc.fHeight = kHeight;
rectangleDesc.fOrigin = origin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
rectangleDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&rectangleInfo);
GrBackendTexture rectangleTex(kWidth, kHeight, kRGBA_8888_GrPixelConfig, &rectangleInfo);
GrColor refPixels[kWidth * kHeight];
bool flipRef = rectangleDesc.fOrigin == kBottomLeft_GrSurfaceOrigin;
for (int y = 0; y < kHeight; ++y) {
for (int x = 0; x < kWidth; ++x) {
int y0 = flipRef ? kHeight - y - 1 : y;
int y0 = useBLOrigin ? kHeight - y - 1 : y;
refPixels[y * kWidth + x] = pixels[y0 * kWidth + x];
}
}
sk_sp<GrSurfaceProxy> rectProxy = GrSurfaceProxy::MakeWrappedBackend(context,
rectangleDesc);
sk_sp<GrTextureProxy> rectProxy = GrSurfaceProxy::MakeWrappedBackend(context,
rectangleTex,
origin);
if (!rectProxy) {
ERRORF(reporter, "Error creating proxy for rectangle texture.");
GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));

View File

@ -11,6 +11,7 @@
#if SK_SUPPORT_GPU
#include <thread>
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrContextFactory.h"
#include "GrGpu.h"
#include "GrGpuResourceCacheAccess.h"
@ -218,22 +219,32 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI
context->resetContext();
GrBackendTextureDesc desc;
desc.fConfig = kBGRA_8888_GrPixelConfig;
desc.fWidth = kW;
desc.fHeight = kH;
desc.fTextureHandle = texHandles[0];
GrBackendTexture backendTex1 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kW,
kH,
kRGBA_8888_GrPixelConfig,
texHandles[0]);
sk_sp<GrTexture> borrowed(context->resourceProvider()->wrapBackendTexture(
desc, kBorrow_GrWrapOwnership));
backendTex1, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0,
kBorrow_GrWrapOwnership));
desc.fTextureHandle = texHandles[1];
GrBackendTexture backendTex2 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kW,
kH,
kRGBA_8888_GrPixelConfig,
texHandles[1]);
sk_sp<GrTexture> adopted(context->resourceProvider()->wrapBackendTexture(
desc, kAdopt_GrWrapOwnership));
backendTex2, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0,
kAdopt_GrWrapOwnership));
desc.fTextureHandle = texHandles[2];
GrBackendTexture backendTex3 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kW,
kH,
kRGBA_8888_GrPixelConfig,
texHandles[2]);
sk_sp<GrTexture> adoptedAndCached(context->resourceProvider()->wrapBackendTexture(
desc, kAdoptAndCache_GrWrapOwnership));
backendTex3, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0,
kAdoptAndCache_GrWrapOwnership));
REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr &&
adoptedAndCached != nullptr);

View File

@ -25,6 +25,7 @@
#include "GrRenderTargetContext.h"
#include "GrGpu.h"
#include "GrResourceProvider.h"
#include "GrTest.h"
#include <vector>
#endif
@ -587,20 +588,24 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture(
const int kHeight = 10;
std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
sk_memset32(pixels.get(), color, kWidth * kHeight);
GrBackendTextureDesc desc;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fWidth = kWidth;
desc.fHeight = kHeight;
desc.fFlags = kRenderTarget_GrBackendTextureFlag;
desc.fTextureHandle = context->getGpu()->createTestingOnlyBackendTexture(
GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture(
pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true);
desc.fSampleCnt = sampleCnt;
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr);
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kWidth,
kHeight,
kRGBA_8888_GrPixelConfig,
backendHandle);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(context, backendTex,
kDefault_GrSurfaceOrigin, sampleCnt,
nullptr, nullptr);
if (!surface) {
context->getGpu()->deleteTestingOnlyBackendTexture(desc.fTextureHandle);
context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle);
return nullptr;
}
*outTexture = desc.fTextureHandle;
*outTexture = backendHandle;
return surface;
}
@ -610,21 +615,23 @@ static sk_sp<SkSurface> create_gpu_surface_backend_texture_as_render_target(
const int kHeight = 10;
std::unique_ptr<uint32_t[]> pixels(new uint32_t[kWidth * kHeight]);
sk_memset32(pixels.get(), color, kWidth * kHeight);
GrBackendTextureDesc desc;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fWidth = kWidth;
desc.fHeight = kHeight;
desc.fFlags = kRenderTarget_GrBackendTextureFlag;
desc.fTextureHandle = context->getGpu()->createTestingOnlyBackendTexture(
GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture(
pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true);
desc.fSampleCnt = sampleCnt;
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(context, desc,
nullptr);
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kWidth,
kHeight,
kRGBA_8888_GrPixelConfig,
backendHandle);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
context, backendTex, kDefault_GrSurfaceOrigin, sampleCnt, nullptr, nullptr);
if (!surface) {
context->getGpu()->deleteTestingOnlyBackendTexture(desc.fTextureHandle);
context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle);
return nullptr;
}
*outTexture = desc.fTextureHandle;
*outTexture = backendHandle;
return surface;
}
@ -879,21 +886,26 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter,
std::vector<GrBackendObject> textureHandles;
auto wrappedSurfaceMaker = [context,&textureHandles](const SkImageInfo& info) {
GrBackendTextureDesc desc;
desc.fConfig = SkImageInfo2GrPixelConfig(info, *context->caps());
desc.fWidth = 10;
desc.fHeight = 10;
desc.fFlags = kRenderTarget_GrBackendTextureFlag;
desc.fTextureHandle = context->getGpu()->createTestingOnlyBackendTexture(
nullptr, desc.fWidth, desc.fHeight, desc.fConfig, true);
static const int kSize = 10;
GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *context->caps());
if (!desc.fTextureHandle) {
GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture(
nullptr, kSize, kSize, config, true);
if (!backendHandle) {
return sk_sp<SkSurface>(nullptr);
}
textureHandles.push_back(desc.fTextureHandle);
textureHandles.push_back(backendHandle);
return SkSurface::MakeFromBackendTexture(context, desc, sk_ref_sp(info.colorSpace()),
nullptr);
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
kSize,
kSize,
config,
backendHandle);
return SkSurface::MakeFromBackendTexture(context, backendTex,
kDefault_GrSurfaceOrigin, 0,
sk_ref_sp(info.colorSpace()), nullptr);
};
test_surface_creation_and_snapshot_with_color_space(reporter, "wrapped", f16Support,

View File

@ -31,37 +31,56 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig,
false);
const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj);
const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj);
// check basic borrowed creation
GrBackendTextureDesc desc;
desc.fConfig = kPixelConfig;
desc.fWidth = kW;
desc.fHeight = kH;
desc.fTextureHandle = backendObj;
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
GrBackendTexture backendTex = GrBackendTexture(kW, kH, imageInfo);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, tex);
// image is null
GrVkImageInfo backendCopy = *backendTex;
GrVkImageInfo backendCopy = *imageInfo;
backendCopy.fImage = VK_NULL_HANDLE;
desc.fTextureHandle = (GrBackendObject) &backendCopy;
tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
backendTex = GrBackendTexture(kW, kH, &backendCopy);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
0,
kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
// alloc is null
backendCopy.fImage = backendTex->fImage;
backendCopy.fImage = imageInfo->fImage;
backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 };
tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
0,
kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
// check adopt creation
backendCopy.fAlloc = backendTex->fAlloc;
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
backendCopy.fAlloc = imageInfo->fAlloc;
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
0,
kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, tex);
gpu->deleteTestingOnlyBackendTexture(backendObj, true);
@ -110,38 +129,56 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig,
true);
const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj);
const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj);
// check basic borrowed creation
GrBackendTextureDesc desc;
desc.fFlags = kRenderTarget_GrBackendTextureFlag;
desc.fConfig = kPixelConfig;
desc.fWidth = kW;
desc.fHeight = kH;
desc.fTextureHandle = backendObj;
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
GrBackendTexture backendTex = GrBackendTexture(kW, kH, imageInfo);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, tex);
// image is null
GrVkImageInfo backendCopy = *backendTex;
GrVkImageInfo backendCopy = *imageInfo;
backendCopy.fImage = VK_NULL_HANDLE;
desc.fTextureHandle = (GrBackendObject)&backendCopy;
tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
backendTex = GrBackendTexture(kW, kH, &backendCopy);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
0,
kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
// alloc is null
backendCopy.fImage = backendTex->fImage;
backendCopy.fImage = imageInfo->fImage;
backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 };
tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
0,
kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
0,
kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
// check adopt creation
backendCopy.fAlloc = backendTex->fAlloc;
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
backendCopy.fAlloc = imageInfo->fAlloc;
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
0,
kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, tex);
gpu->deleteTestingOnlyBackendTexture(backendObj, true);

View File

@ -7,6 +7,7 @@
#include "GrTest.h"
#include "GrBackendSurface.h"
#include "GrContextOptions.h"
#include "GrDrawOpAtlas.h"
#include "GrDrawingManager.h"
@ -54,6 +55,18 @@ void SetupAlwaysEvictAtlas(GrContext* context) {
context->setTextContextAtlasSizes_ForTesting(configs);
}
GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height,
GrPixelConfig config, GrBackendObject handle) {
if (kOpenGL_GrBackend == backend) {
GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
return GrBackendTexture(width, height, config, glInfo);
} else {
SkASSERT(kVulkan_GrBackend == backend);
GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
return GrBackendTexture(width, height, vkInfo);
}
}
};
bool GrSurfaceProxy::isWrapped_ForTesting() const {
@ -338,7 +351,11 @@ private:
return nullptr;
}
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override {
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
GrSurfaceOrigin,
GrBackendTextureFlags,
int sampleCnt,
GrWrapOwnership) override {
return nullptr;
}
@ -346,7 +363,9 @@ private:
return nullptr;
}
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
int sampleCnt) override {
return nullptr;
}

View File

@ -8,6 +8,7 @@
#ifndef GrTest_DEFINED
#define GrTest_DEFINED
#include "GrBackendSurface.h"
#include "GrContext.h"
namespace GrTest {
@ -16,6 +17,9 @@ namespace GrTest {
* constantly be evicting entries
*/
void SetupAlwaysEvictAtlas(GrContext*);
GrBackendTexture CreateBackendTexture(GrBackend, int width, int height,
GrPixelConfig, GrBackendObject);
};
#endif