Plumb the use of GrBackendRenderTarget throughout Skia

Bug: skia:
Change-Id: Ib99a58d9552f5c7b8d77c09dcc72fa88326c26aa
Reviewed-on: https://skia-review.googlesource.com/14148
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2017-04-26 12:19:14 -04:00 committed by Skia Commit-Bot
parent a41d48b739
commit fdd77daedb
22 changed files with 179 additions and 154 deletions

View File

@ -6,6 +6,7 @@
* *
*/ */
#include "GrBackendSurface.h"
#include "GrContext.h" #include "GrContext.h"
#include "SDL.h" #include "SDL.h"
#include "SkCanvas.h" #include "SkCanvas.h"
@ -192,16 +193,12 @@ int main(int argc, char** argv) {
// Wrap the frame buffer object attached to the screen in a Skia render target so Skia can // Wrap the frame buffer object attached to the screen in a Skia render target so Skia can
// render to it // render to it
GrBackendRenderTargetDesc desc; GrGLFrameBufferInfo fbInfo;
desc.fWidth = dm.w;
desc.fHeight = dm.h;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt = kMsaaSampleCount;
desc.fStencilBits = kStencilBits;
GrGLint buffer; GrGLint buffer;
GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
desc.fRenderTargetHandle = buffer; fbInfo.fFBOID = buffer;
GrBackendRenderTarget backendRT(dm.w, dm.h, kMsaaSampleCount, kStencilBits,
kSkia8888_GrPixelConfig, fbInfo);
// setup SkSurface // setup SkSurface
// To use distance field text, use commented out SkSurfaceProps instead // To use distance field text, use commented out SkSurfaceProps instead
@ -209,7 +206,10 @@ int main(int argc, char** argv) {
// SkSurfaceProps::kLegacyFontHost_InitType); // SkSurfaceProps::kLegacyFontHost_InitType);
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(grContext, desc, &props)); sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(grContext,
backendRT,
kBottomLeft_GrSurfaceOrigin,
&props));
SkCanvas* canvas = surface->getCanvas(); SkCanvas* canvas = surface->getCanvas();

View File

@ -9,9 +9,8 @@
#define GrBackendSurface_DEFINED #define GrBackendSurface_DEFINED
#include "GrTypes.h" #include "GrTypes.h"
#include "gl/GrGLTypes.h"
struct GrVkImageInfo; #include "vk/GrVkTypes.h"
struct GrGLTextureInfo;
class GrBackendTexture { class GrBackendTexture {
public: public:
@ -63,22 +62,18 @@ private:
class GrBackendRenderTarget { class GrBackendRenderTarget {
public: public:
// The passed in GrVkImageInfo must live until the GrBackendTexture is no longer used in
// creation of SkImages or SkSurfaces.
GrBackendRenderTarget(int width, GrBackendRenderTarget(int width,
int height, int height,
int sampleCnt, int sampleCnt,
int stencilBits, int stencilBits,
const 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, GrBackendRenderTarget(int width,
int height, int height,
int sampleCnt, int sampleCnt,
int stencilBits, int stencilBits,
GrPixelConfig config, GrPixelConfig config,
const GrGLTextureInfo* glInfo); const GrGLFramebufferInfo& glInfo);
int width() const { return fWidth; } int width() const { return fWidth; }
int height() const { return fHeight; } int height() const { return fHeight; }
@ -88,12 +83,12 @@ public:
GrBackend backend() const {return fBackend; } GrBackend backend() const {return fBackend; }
// If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
// it returns nullptr. // it returns nullptr
const GrVkImageInfo* getVkImageInfo() const; const GrVkImageInfo* getVkImageInfo() const;
// If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise // If the backend API is GL, this returns a pointer to the GrGLFramebufferInfo struct. Otherwise
// it returns nullptr. // it returns nullptr.
const GrGLTextureInfo* getGLTextureInfo() const; const GrGLFramebufferInfo* getGLFramebufferInfo() const;
private: private:
// Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc. // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc.
@ -112,9 +107,8 @@ private:
GrBackend fBackend; GrBackend fBackend;
union { union {
const GrVkImageInfo* fVkInfo; GrVkImageInfo fVkInfo;
const GrGLTextureInfo* fGLInfo; GrGLFramebufferInfo fGLInfo;
GrBackendObject fHandle;
}; };
}; };

View File

@ -135,4 +135,10 @@ protected:
GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLTextureInfo*)); GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLTextureInfo*));
struct GrGLFramebufferInfo {
GrGLuint fFBOID;
};
GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLFramebufferInfo*));
#endif #endif

View File

@ -9,6 +9,8 @@
#ifndef GrVkDefines_DEFINED #ifndef GrVkDefines_DEFINED
#define GrVkDefines_DEFINED #define GrVkDefines_DEFINED
#ifdef SK_VULKAN
#if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_WIN32) #if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_WIN32)
# if !defined(VK_USE_PLATFORM_WIN32_KHR) # if !defined(VK_USE_PLATFORM_WIN32_KHR)
# define VK_USE_PLATFORM_WIN32_KHR # define VK_USE_PLATFORM_WIN32_KHR
@ -29,8 +31,6 @@
# endif # endif
#endif #endif
#if defined(Bool) || defined(Status) || defined(True) || defined(False)
# pragma error "Macros unexpectedly defined."
#endif #endif
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>

View File

@ -70,14 +70,14 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height, int height,
int sampleCnt, int sampleCnt,
int stencilBits, int stencilBits,
const GrVkImageInfo* vkInfo) const GrVkImageInfo& vkInfo)
: fWidth(width) : fWidth(width)
, fHeight(height) , fHeight(height)
, fSampleCnt(sampleCnt) , fSampleCnt(sampleCnt)
, fStencilBits(stencilBits) , fStencilBits(stencilBits)
, fConfig( , fConfig(
#ifdef SK_VULKAN #ifdef SK_VULKAN
GrVkFormatToPixelConfig(vkInfo->fFormat) GrVkFormatToPixelConfig(vkInfo.fFormat)
#else #else
kUnknown_GrPixelConfig kUnknown_GrPixelConfig
#endif #endif
@ -90,7 +90,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
int sampleCnt, int sampleCnt,
int stencilBits, int stencilBits,
GrPixelConfig config, GrPixelConfig config,
const GrGLTextureInfo* glInfo) const GrGLFramebufferInfo& glInfo)
: fWidth(width) : fWidth(width)
, fHeight(height) , fHeight(height)
, fSampleCnt(sampleCnt) , fSampleCnt(sampleCnt)
@ -105,26 +105,33 @@ GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& de
, fHeight(desc.fHeight) , fHeight(desc.fHeight)
, fSampleCnt(desc.fSampleCnt) , fSampleCnt(desc.fSampleCnt)
, fStencilBits(desc.fStencilBits) , fStencilBits(desc.fStencilBits)
, fConfig(kVulkan_GrBackend == backend , fConfig(desc.fConfig)
, fBackend(backend) {
if (kOpenGL_GrBackend == backend) {
fGLInfo = *reinterpret_cast<const GrGLFramebufferInfo*>(desc.fRenderTargetHandle);
} else {
SkASSERT(kVulkan_GrBackend == backend);
#ifdef SK_VULKAN #ifdef SK_VULKAN
? GrVkFormatToPixelConfig(((GrVkImageInfo*)desc.fRenderTargetHandle)->fFormat) const GrVkImageInfo* vkInfo =
reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle);
fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
fVkInfo = *vkInfo;
#else #else
? kUnknown_GrPixelConfig fConfig = kUnknown_GrPixelConfig;
#endif #endif
: desc.fConfig) }
, fBackend(backend) }
, fHandle(desc.fRenderTargetHandle) {}
const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) { if (kVulkan_GrBackend == fBackend) {
return fVkInfo; return &fVkInfo;
} }
return nullptr; return nullptr;
} }
const GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() const { const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
if (kOpenGL_GrBackend == fBackend) { if (kOpenGL_GrBackend == fBackend) {
return fGLInfo; return &fGLInfo;
} }
return nullptr; return nullptr;
} }

View File

@ -702,12 +702,14 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContex
} }
sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext( sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext(
const GrBackendRenderTargetDesc& desc, const GrBackendRenderTarget& backendRT,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) { const SkSurfaceProps* surfaceProps) {
ASSERT_SINGLE_OWNER_PRIV ASSERT_SINGLE_OWNER_PRIV
sk_sp<GrRenderTarget> rt(fContext->resourceProvider()->wrapBackendRenderTarget(desc)); sk_sp<GrRenderTarget> rt(fContext->resourceProvider()->wrapBackendRenderTarget(backendRT,
origin));
if (!rt) { if (!rt) {
return nullptr; return nullptr;
} }

View File

@ -11,6 +11,7 @@
#include "GrContext.h" #include "GrContext.h"
#include "GrSurfaceContext.h" #include "GrSurfaceContext.h"
class GrBackendRenderTarget;
class GrSemaphore; class GrSemaphore;
class GrSurfaceProxy; class GrSurfaceProxy;
class GrPreFlushCallbackObject; class GrPreFlushCallbackObject;
@ -52,7 +53,8 @@ public:
const SkSurfaceProps* = nullptr); const SkSurfaceProps* = nullptr);
sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext( sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
const GrBackendRenderTargetDesc& desc, const GrBackendRenderTarget&,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr); const SkSurfaceProps* = nullptr);

View File

@ -223,12 +223,13 @@ sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
return tex; return tex;
} }
sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { GrSurfaceOrigin origin) {
if (!this->caps()->isConfigRenderable(backendRT.config(), backendRT.sampleCnt() > 0)) {
return nullptr; return nullptr;
} }
this->handleDirtyContext(); this->handleDirtyContext();
return this->onWrapBackendRenderTarget(desc); return this->onWrapBackendRenderTarget(backendRT, origin);
} }
sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,

View File

@ -20,6 +20,7 @@
#include "SkTArray.h" #include "SkTArray.h"
#include <map> #include <map>
class GrBackendRenderTarget;
class GrBuffer; class GrBuffer;
class GrContext; class GrContext;
struct GrContextOptions; struct GrContextOptions;
@ -135,7 +136,7 @@ public:
/** /**
* Implements GrResourceProvider::wrapBackendRenderTarget * Implements GrResourceProvider::wrapBackendRenderTarget
*/ */
sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc&); sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin);
/** /**
* Implements GrResourceProvider::wrapBackendTextureAsRenderTarget * Implements GrResourceProvider::wrapBackendTextureAsRenderTarget
@ -556,7 +557,8 @@ private:
GrBackendTextureFlags, GrBackendTextureFlags,
int sampleCnt, int sampleCnt,
GrWrapOwnership) = 0; GrWrapOwnership) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0; virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
GrSurfaceOrigin) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin, GrSurfaceOrigin,
int sampleCnt)=0; int sampleCnt)=0;

View File

@ -254,10 +254,10 @@ sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture&
} }
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget( sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
const GrBackendRenderTargetDesc& desc) const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin)
{ {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc); return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT, origin);
} }
void GrResourceProvider::assignUniqueKeyToResource(const GrUniqueKey& key, void GrResourceProvider::assignUniqueKeyToResource(const GrUniqueKey& key,

View File

@ -12,6 +12,7 @@
#include "GrGpu.h" #include "GrGpu.h"
#include "GrPathRange.h" #include "GrPathRange.h"
class GrBackendRenderTarget;
class GrPath; class GrPath;
class GrRenderTarget; class GrRenderTarget;
class GrSingleOwner; class GrSingleOwner;
@ -100,7 +101,7 @@ public:
* *
* @return GrRenderTarget object or NULL on failure. * @return GrRenderTarget object or NULL on failure.
*/ */
sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc); sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin);
static const int kMinScratchTextureSize; static const int kMinScratchTextureSize;

View File

@ -504,17 +504,6 @@ void GrGLGpu::onResetContext(uint32_t resetBits) {
} }
} }
static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) {
// By default, GrRenderTargets are GL's normal orientation so that they
// can be drawn to by the outside world without the client having
// to render upside down.
if (kDefault_GrSurfaceOrigin == origin) {
return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
} else {
return origin;
}
}
sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
GrBackendTextureFlags flags, GrBackendTextureFlags flags,
@ -591,23 +580,30 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe
} }
} }
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc){ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
GrSurfaceOrigin origin) {
const GrGLFramebufferInfo* info = backendRT.getGLFramebufferInfo();
if (!info) {
return nullptr;
}
GrGLRenderTarget::IDDesc idDesc; GrGLRenderTarget::IDDesc idDesc;
idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); idDesc.fRTFBOID = info->fFBOID;
idDesc.fMSColorRenderbufferID = 0; idDesc.fMSColorRenderbufferID = 0;
idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed; idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
idDesc.fIsMixedSampled = false; idDesc.fIsMixedSampled = false;
GrSurfaceDesc desc; GrSurfaceDesc desc;
desc.fConfig = wrapDesc.fConfig; desc.fConfig = backendRT.config();
desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag;
desc.fWidth = wrapDesc.fWidth; desc.fWidth = backendRT.width();
desc.fHeight = wrapDesc.fHeight; desc.fHeight = backendRT.height();
desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()); desc.fSampleCnt = SkTMin(backendRT.sampleCnt(), this->caps()->maxSampleCount());
desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); SkASSERT(kDefault_GrSurfaceOrigin != origin);
desc.fOrigin = origin;
return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, wrapDesc.fStencilBits); return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, backendRT.stencilBits());
} }
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,

View File

@ -176,7 +176,8 @@ private:
GrBackendTextureFlags, GrBackendTextureFlags,
int sampleCnt, int sampleCnt,
GrWrapOwnership) override; GrWrapOwnership) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
GrSurfaceOrigin origin) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin, GrSurfaceOrigin,
int sampleCnt) override; int sampleCnt) override;

View File

@ -815,32 +815,36 @@ sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTe
return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, info); return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, info);
} }
sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc){ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
GrSurfaceOrigin origin){
// Currently the Vulkan backend does not support wrapping of msaa render targets directly. In // Currently the Vulkan backend does not support wrapping of msaa render targets directly. In
// general this is not an issue since swapchain images in vulkan are never multisampled. Thus if // general this is not an issue since swapchain images in vulkan are never multisampled. Thus if
// you want a multisampled RT it is best to wrap the swapchain images and then let Skia handle // you want a multisampled RT it is best to wrap the swapchain images and then let Skia handle
// creating and owning the MSAA images. // creating and owning the MSAA images.
if (wrapDesc.fSampleCnt) { if (backendRT.sampleCnt()) {
return nullptr; return nullptr;
} }
const GrVkImageInfo* info = const GrVkImageInfo* info = backendRT.getVkImageInfo();
reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fRenderTargetHandle); if (!info) {
return nullptr;
}
if (VK_NULL_HANDLE == info->fImage) { if (VK_NULL_HANDLE == info->fImage) {
return nullptr; return nullptr;
} }
GrSurfaceDesc desc; GrSurfaceDesc desc;
desc.fConfig = wrapDesc.fConfig; desc.fConfig = backendRT.config();
desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag;
desc.fWidth = wrapDesc.fWidth; desc.fWidth = backendRT.width();
desc.fHeight = wrapDesc.fHeight; desc.fHeight = backendRT.height();
desc.fSampleCnt = 0; desc.fSampleCnt = 0;
desc.fOrigin = resolve_origin(wrapDesc.fOrigin); SkASSERT(kDefault_GrSurfaceOrigin != origin);
desc.fOrigin = origin;
sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info);
if (tgt && wrapDesc.fStencilBits) { if (tgt && backendRT.stencilBits()) {
if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) { if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) {
return nullptr; return nullptr;
} }
@ -853,6 +857,9 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBacken
int sampleCnt) { int sampleCnt) {
const GrVkImageInfo* info = tex.getVkImageInfo(); const GrVkImageInfo* info = tex.getVkImageInfo();
if (!info) {
return nullptr;
}
if (VK_NULL_HANDLE == info->fImage) { if (VK_NULL_HANDLE == info->fImage) {
return nullptr; return nullptr;
} }

View File

@ -180,7 +180,8 @@ private:
GrBackendTextureFlags, GrBackendTextureFlags,
int sampleCnt, int sampleCnt,
GrWrapOwnership) override; GrWrapOwnership) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
GrSurfaceOrigin) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin, GrSurfaceOrigin,

View File

@ -261,19 +261,36 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
if (!context) { if (!context) {
return nullptr; return nullptr;
} }
if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) {
GrBackendRenderTarget backendRT(desc, context->contextPriv().getBackend());
return MakeFromBackendRenderTarget(context, backendRT, desc.fOrigin,
std::move(colorSpace), props);
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
const GrBackendRenderTarget& backendRT,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!context) {
return nullptr;
}
if (!SkSurface_Gpu::Valid(context, backendRT.config(), colorSpace.get())) {
return nullptr; return nullptr;
} }
sk_sp<GrRenderTargetContext> rtc( sk_sp<GrRenderTargetContext> rtc(
context->contextPriv().makeBackendRenderTargetRenderTargetContext(desc, context->contextPriv().makeBackendRenderTargetRenderTargetContext(backendRT,
origin,
std::move(colorSpace), std::move(colorSpace),
props)); props));
if (!rtc) { if (!rtc) {
return nullptr; 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),
backendRT.width(), backendRT.height(),
SkGpuDevice::kUninit_InitContents)); SkGpuDevice::kUninit_InitContents));
if (!device) { if (!device) {
return nullptr; return nullptr;
@ -282,16 +299,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
return sk_make_sp<SkSurface_Gpu>(std::move(device)); return sk_make_sp<SkSurface_Gpu>(std::move(device));
} }
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTarget&,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace>,
const SkSurfaceProps*) {
// This function is not implemented yet
sk_throw();
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context,
const GrBackendTextureDesc& desc, const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,

View File

@ -316,6 +316,7 @@ bool SkWindow::onDispatchClick(int x, int y, Click::State state,
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrContext.h" #include "GrContext.h"
#include "gl/GrGLInterface.h" #include "gl/GrGLInterface.h"
#include "gl/GrGLUtil.h" #include "gl/GrGLUtil.h"
@ -324,10 +325,9 @@ bool SkWindow::onDispatchClick(int x, int y, Click::State state,
sk_sp<SkSurface> SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachmentInfo, sk_sp<SkSurface> SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachmentInfo,
const GrGLInterface* interface, const GrGLInterface* interface,
GrContext* grContext) { GrContext* grContext) {
GrBackendRenderTargetDesc desc; int width = SkScalarRoundToInt(this->width());
desc.fWidth = SkScalarRoundToInt(this->width()); int height = SkScalarRoundToInt(this->height());
desc.fHeight = SkScalarRoundToInt(this->height()); if (0 == width || 0 == height) {
if (0 == desc.fWidth || 0 == desc.fHeight) {
return nullptr; return nullptr;
} }
@ -340,22 +340,28 @@ sk_sp<SkSurface> SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachment
// //
// ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write, // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write,
// so pretend that it's non-sRGB 8888: // so pretend that it's non-sRGB 8888:
desc.fConfig = GrPixelConfig config = grContext->caps()->srgbSupport() &&
grContext->caps()->srgbSupport() && info().colorSpace() &&
info().colorSpace() && (attachmentInfo.fColorBits != 30)
(attachmentInfo.fColorBits != 30) ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig; GrGLFramebufferInfo fbInfo;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt = attachmentInfo.fSampleCount;
desc.fStencilBits = attachmentInfo.fStencilBits;
GrGLint buffer; GrGLint buffer;
GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
desc.fRenderTargetHandle = buffer; fbInfo.fFBOID = buffer;
GrBackendRenderTarget backendRT(width,
height,
attachmentInfo.fSampleCount,
attachmentInfo.fStencilBits,
config,
fbInfo);
sk_sp<SkColorSpace> colorSpace = sk_sp<SkColorSpace> colorSpace =
grContext->caps()->srgbSupport() && info().colorSpace() grContext->caps()->srgbSupport() && info().colorSpace()
? SkColorSpace::MakeSRGB() : nullptr; ? SkColorSpace::MakeSRGB() : nullptr;
return SkSurface::MakeFromBackendRenderTarget(grContext, desc, colorSpace, &fSurfaceProps); return SkSurface::MakeFromBackendRenderTarget(grContext, backendRT, kBottomLeft_GrSurfaceOrigin,
colorSpace, &fSurfaceProps);
} }
#endif #endif

View File

@ -10,6 +10,7 @@
#include "Test.h" #include "Test.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrRenderTargetProxy.h" #include "GrRenderTargetProxy.h"
#include "GrResourceProvider.h" #include "GrResourceProvider.h"
#include "GrSurfaceProxy.h" #include "GrSurfaceProxy.h"
@ -18,16 +19,12 @@
static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider, static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider,
skiatest::Reporter* reporter, skiatest::Reporter* reporter,
const GrSurfaceDesc& desc) { const GrSurfaceDesc& desc) {
GrBackendRenderTargetDesc backendDesc; GrGLFramebufferInfo fboInfo;
backendDesc.fWidth = desc.fWidth; fboInfo.fFBOID = 0;
backendDesc.fHeight = desc.fHeight; GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
backendDesc.fConfig = desc.fConfig; desc.fConfig, fboInfo);
backendDesc.fOrigin = desc.fOrigin;
backendDesc.fSampleCnt = desc.fSampleCnt;
backendDesc.fStencilBits = 8;
backendDesc.fRenderTargetHandle = 0;
sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendDesc)); sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin));
SkASSERT(!defaultFBO->asTexture()); SkASSERT(!defaultFBO->asTexture());
return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO)); return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
@ -62,6 +59,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo
desc.fWidth = 64; desc.fWidth = 64;
desc.fHeight = 64; desc.fHeight = 64;
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
if (kOpenGL_GrBackend == ctxInfo.backend()) { if (kOpenGL_GrBackend == ctxInfo.backend()) {
// External on-screen render target. // External on-screen render target.

View File

@ -10,6 +10,7 @@
#include "Test.h" #include "Test.h"
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrRenderTargetPriv.h" #include "GrRenderTargetPriv.h"
#include "GrRenderTargetProxy.h" #include "GrRenderTargetProxy.h"
#include "GrResourceProvider.h" #include "GrResourceProvider.h"
@ -20,7 +21,7 @@
static void check_surface(skiatest::Reporter* reporter, static void check_surface(skiatest::Reporter* reporter,
GrSurfaceProxy* proxy, GrSurfaceProxy* proxy,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
int width, int height, int width, int height,
GrPixelConfig config, GrPixelConfig config,
const GrGpuResource::UniqueID& uniqueID, const GrGpuResource::UniqueID& uniqueID,
SkBudgeted budgeted) { SkBudgeted budgeted) {
@ -228,17 +229,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
// External on-screen render target. // External on-screen render target.
if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) { if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
GrBackendRenderTargetDesc backendDesc; GrGLFramebufferInfo fboInfo;
backendDesc.fWidth = kWidthHeight; fboInfo.fFBOID = 0;
backendDesc.fHeight = kWidthHeight; GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, 8,
backendDesc.fConfig = config; config, fboInfo);
backendDesc.fOrigin = origin;
backendDesc.fSampleCnt = numSamples;
backendDesc.fStencilBits = 8;
backendDesc.fRenderTargetHandle = 0;
sk_sp<GrRenderTarget> defaultFBO( sk_sp<GrRenderTarget> defaultFBO(
provider->wrapBackendRenderTarget(backendDesc)); provider->wrapBackendRenderTarget(backendRT, origin));
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO)); sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
check_surface(reporter, sProxy.get(), origin, check_surface(reporter, sProxy.get(), origin,

View File

@ -93,30 +93,24 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) {
true); true);
const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj);
// check basic borrowed creation GrBackendRenderTarget backendRT(kW, kH, 0, 0, *backendTex);
GrBackendRenderTargetDesc desc;
desc.fWidth = kW; sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(backendRT, kTopLeft_GrSurfaceOrigin);
desc.fHeight = kH;
desc.fConfig = kPixelConfig;
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
desc.fSampleCnt = 0;
desc.fStencilBits = 0;
desc.fRenderTargetHandle = backendObj;
sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(desc);
REPORTER_ASSERT(reporter, rt); REPORTER_ASSERT(reporter, rt);
// image is null // image is null
GrVkImageInfo backendCopy = *backendTex; GrVkImageInfo backendCopy = *backendTex;
backendCopy.fImage = VK_NULL_HANDLE; backendCopy.fImage = VK_NULL_HANDLE;
desc.fRenderTargetHandle = (GrBackendObject)&backendCopy; GrBackendRenderTarget backendRT2(kW, kH, 0, 0, backendCopy);
rt = gpu->wrapBackendRenderTarget(desc); rt = gpu->wrapBackendRenderTarget(backendRT2, kTopLeft_GrSurfaceOrigin);
REPORTER_ASSERT(reporter, !rt); REPORTER_ASSERT(reporter, !rt);
// alloc is null // alloc is null
backendCopy.fImage = backendTex->fImage; backendCopy.fImage = backendTex->fImage;
backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 };
// can wrap null alloc // can wrap null alloc
rt = gpu->wrapBackendRenderTarget(desc); GrBackendRenderTarget backendRT3(kW, kH, 0, 0, backendCopy);
rt = gpu->wrapBackendRenderTarget(backendRT3, kTopLeft_GrSurfaceOrigin);
REPORTER_ASSERT(reporter, rt); REPORTER_ASSERT(reporter, rt);
// When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the

View File

@ -359,7 +359,8 @@ private:
return nullptr; return nullptr;
} }
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override { sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
GrSurfaceOrigin) override {
return nullptr; return nullptr;
} }

View File

@ -6,19 +6,18 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "GrBackendSurface.h"
#include "GrContext.h" #include "GrContext.h"
#include "SkSurface.h" #include "GrRenderTarget.h"
#include "GLWindowContext.h" #include "GLWindowContext.h"
#include "gl/GrGLDefines.h" #include "gl/GrGLDefines.h"
#include "gl/GrGLUtil.h" #include "gl/GrGLUtil.h"
#include "GrRenderTarget.h"
#include "GrContext.h"
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkImage_Base.h" #include "SkImage_Base.h"
#include "SkMathPriv.h" #include "SkMathPriv.h"
#include "SkSurface.h"
namespace sk_app { namespace sk_app {
@ -64,7 +63,7 @@ void GLWindowContext::destroyContext() {
fContext->unref(); fContext->unref();
fContext = nullptr; fContext = nullptr;
} }
fBackendContext.reset(nullptr); fBackendContext.reset(nullptr);
this->onDestroyContext(); this->onDestroyContext();
@ -73,18 +72,21 @@ void GLWindowContext::destroyContext() {
sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() { sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
if (nullptr == fSurface) { if (nullptr == fSurface) {
if (fContext) { if (fContext) {
GrBackendRenderTargetDesc desc; GrGLFramebufferInfo fbInfo;
desc.fWidth = this->fWidth;
desc.fHeight = this->fHeight;
desc.fConfig = fPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt = fSampleCount;
desc.fStencilBits = fStencilBits;
GrGLint buffer; GrGLint buffer;
GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer)); GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING,
desc.fRenderTargetHandle = buffer; &buffer));
fbInfo.fFBOID = buffer;
fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, desc, GrBackendRenderTarget backendRT(fWidth,
fHeight,
fSampleCount,
fStencilBits,
fPixelConfig,
fbInfo);
fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, backendRT,
kBottomLeft_GrSurfaceOrigin,
fDisplayParams.fColorSpace, fDisplayParams.fColorSpace,
&fSurfaceProps); &fSurfaceProps);
} }