aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-05-01 13:50:58 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-01 14:14:50 +0000
commitbcf612b5d0032f09d58c2ea5671de977130395db (patch)
tree1793afbbdb1b1cdc2be3e7de960ca9c76b6806d0
parent53f77bd4fdd76525b66b7f26d1c5c550858120df (diff)
Revert "Revert "Plumb the use of GrBackendRenderTarget throughout Skia""
This reverts commit e3bd422fafc74dd3410c3de24a576635be92c3b4. Reason for revert: Pre-req changes have all landed in other projects at this point. Original change's description: > Revert "Plumb the use of GrBackendRenderTarget throughout Skia" > > This reverts commit fdd77daedbba3b7c53be74a82fb9fae891b51696. > > Reason for revert: Apparently I have a few more build files to update before this can land. > > Original change's description: > > 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> > > > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Change-Id: I984e1909870182474c4c3cce257f01b6a9d8581f > Reviewed-on: https://skia-review.googlesource.com/14531 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ib7ab94aada8a7cb80fe38f24daf32f9208c5b169 Reviewed-on: https://skia-review.googlesource.com/14826 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
-rw-r--r--example/SkiaSDLExample.cpp18
-rw-r--r--include/gpu/GrBackendSurface.h24
-rw-r--r--include/gpu/gl/GrGLTypes.h6
-rw-r--r--include/gpu/vk/GrVkDefines.h4
-rw-r--r--src/gpu/GrBackendSurface.cpp31
-rw-r--r--src/gpu/GrContext.cpp6
-rw-r--r--src/gpu/GrContextPriv.h4
-rw-r--r--src/gpu/GrGpu.cpp7
-rw-r--r--src/gpu/GrGpu.h6
-rw-r--r--src/gpu/GrResourceProvider.cpp4
-rw-r--r--src/gpu/GrResourceProvider.h3
-rw-r--r--src/gpu/gl/GrGLGpu.cpp34
-rw-r--r--src/gpu/gl/GrGLGpu.h3
-rw-r--r--src/gpu/vk/GrVkGpu.cpp25
-rw-r--r--src/gpu/vk/GrVkGpu.h3
-rw-r--r--src/image/SkSurface_Gpu.cpp33
-rw-r--r--src/views/SkWindow.cpp34
-rw-r--r--tests/ProxyConversionTest.cpp18
-rw-r--r--tests/ProxyTest.cpp17
-rw-r--r--tests/VkWrapTests.cpp20
-rw-r--r--tools/gpu/GrTest.cpp3
-rw-r--r--tools/viewer/sk_app/GLWindowContext.cpp34
22 files changed, 181 insertions, 156 deletions
diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp
index abd198afe9..f3be85045e 100644
--- a/example/SkiaSDLExample.cpp
+++ b/example/SkiaSDLExample.cpp
@@ -6,6 +6,7 @@
*
*/
+#include "GrBackendSurface.h"
#include "GrContext.h"
#include "SDL.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
// render to it
- GrBackendRenderTargetDesc desc;
- desc.fWidth = dm.w;
- desc.fHeight = dm.h;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
- desc.fSampleCnt = kMsaaSampleCount;
- desc.fStencilBits = kStencilBits;
+ GrGLFrameBufferInfo fbInfo;
GrGLint 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
// To use distance field text, use commented out SkSurfaceProps instead
@@ -209,7 +206,10 @@ int main(int argc, char** argv) {
// 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();
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index fd99a4312a..d9302dafc2 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -9,9 +9,8 @@
#define GrBackendSurface_DEFINED
#include "GrTypes.h"
-
-struct GrVkImageInfo;
-struct GrGLTextureInfo;
+#include "gl/GrGLTypes.h"
+#include "vk/GrVkTypes.h"
class GrBackendTexture {
public:
@@ -63,22 +62,18 @@ private:
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,
- 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,
int height,
int sampleCnt,
int stencilBits,
GrPixelConfig config,
- const GrGLTextureInfo* glInfo);
+ const GrGLFramebufferInfo& glInfo);
int width() const { return fWidth; }
int height() const { return fHeight; }
@@ -88,12 +83,12 @@ public:
GrBackend backend() const {return fBackend; }
// 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;
- // 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.
- const GrGLTextureInfo* getGLTextureInfo() const;
+ const GrGLFramebufferInfo* getGLFramebufferInfo() const;
private:
// Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc.
@@ -112,9 +107,8 @@ private:
GrBackend fBackend;
union {
- const GrVkImageInfo* fVkInfo;
- const GrGLTextureInfo* fGLInfo;
- GrBackendObject fHandle;
+ GrVkImageInfo fVkInfo;
+ GrGLFramebufferInfo fGLInfo;
};
};
diff --git a/include/gpu/gl/GrGLTypes.h b/include/gpu/gl/GrGLTypes.h
index f2b339eccc..345364b050 100644
--- a/include/gpu/gl/GrGLTypes.h
+++ b/include/gpu/gl/GrGLTypes.h
@@ -135,4 +135,10 @@ protected:
GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLTextureInfo*));
+struct GrGLFramebufferInfo {
+ GrGLuint fFBOID;
+};
+
+GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLFramebufferInfo*));
+
#endif
diff --git a/include/gpu/vk/GrVkDefines.h b/include/gpu/vk/GrVkDefines.h
index 7b9ee8dadf..7defed2ad5 100644
--- a/include/gpu/vk/GrVkDefines.h
+++ b/include/gpu/vk/GrVkDefines.h
@@ -9,6 +9,8 @@
#ifndef GrVkDefines_DEFINED
#define GrVkDefines_DEFINED
+#ifdef SK_VULKAN
+
#if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_WIN32)
# if !defined(VK_USE_PLATFORM_WIN32_KHR)
# define VK_USE_PLATFORM_WIN32_KHR
@@ -29,8 +31,6 @@
# endif
#endif
-#if defined(Bool) || defined(Status) || defined(True) || defined(False)
-# pragma error "Macros unexpectedly defined."
#endif
#include <vulkan/vulkan.h>
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 97b3b6ee03..6a1448e17c 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -70,14 +70,14 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
- const GrVkImageInfo* vkInfo)
+ const GrVkImageInfo& vkInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(sampleCnt)
, fStencilBits(stencilBits)
, fConfig(
#ifdef SK_VULKAN
- GrVkFormatToPixelConfig(vkInfo->fFormat)
+ GrVkFormatToPixelConfig(vkInfo.fFormat)
#else
kUnknown_GrPixelConfig
#endif
@@ -90,7 +90,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
int sampleCnt,
int stencilBits,
GrPixelConfig config,
- const GrGLTextureInfo* glInfo)
+ const GrGLFramebufferInfo& glInfo)
: fWidth(width)
, fHeight(height)
, fSampleCnt(sampleCnt)
@@ -105,26 +105,33 @@ GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& de
, fHeight(desc.fHeight)
, fSampleCnt(desc.fSampleCnt)
, 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
- ? GrVkFormatToPixelConfig(((GrVkImageInfo*)desc.fRenderTargetHandle)->fFormat)
+ const GrVkImageInfo* vkInfo =
+ reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle);
+ fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
+ fVkInfo = *vkInfo;
#else
- ? kUnknown_GrPixelConfig
+ fConfig = kUnknown_GrPixelConfig;
#endif
- : desc.fConfig)
- , fBackend(backend)
- , fHandle(desc.fRenderTargetHandle) {}
+ }
+}
const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) {
- return fVkInfo;
+ return &fVkInfo;
}
return nullptr;
}
-const GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() const {
+const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
if (kOpenGL_GrBackend == fBackend) {
- return fGLInfo;
+ return &fGLInfo;
}
return nullptr;
}
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a2f227226d..aa245b5672 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -702,12 +702,14 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContex
}
sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext(
- const GrBackendRenderTargetDesc& desc,
+ const GrBackendRenderTarget& backendRT,
+ GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
ASSERT_SINGLE_OWNER_PRIV
- sk_sp<GrRenderTarget> rt(fContext->resourceProvider()->wrapBackendRenderTarget(desc));
+ sk_sp<GrRenderTarget> rt(fContext->resourceProvider()->wrapBackendRenderTarget(backendRT,
+ origin));
if (!rt) {
return nullptr;
}
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index c85ac2c9b6..08b26e56d5 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -11,6 +11,7 @@
#include "GrContext.h"
#include "GrSurfaceContext.h"
+class GrBackendRenderTarget;
class GrSemaphore;
class GrSurfaceProxy;
class GrPreFlushCallbackObject;
@@ -52,7 +53,8 @@ public:
const SkSurfaceProps* = nullptr);
sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
- const GrBackendRenderTargetDesc& desc,
+ const GrBackendRenderTarget&,
+ GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr);
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 4bf0c87bf1..5ce8274215 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -223,12 +223,13 @@ sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
return tex;
}
-sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
- if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT,
+ GrSurfaceOrigin origin) {
+ if (!this->caps()->isConfigRenderable(backendRT.config(), backendRT.sampleCnt() > 0)) {
return nullptr;
}
this->handleDirtyContext();
- return this->onWrapBackendRenderTarget(desc);
+ return this->onWrapBackendRenderTarget(backendRT, origin);
}
sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index e1b611f3bd..68d26191bc 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -20,6 +20,7 @@
#include "SkTArray.h"
#include <map>
+class GrBackendRenderTarget;
class GrBuffer;
class GrContext;
struct GrContextOptions;
@@ -135,7 +136,7 @@ public:
/**
* Implements GrResourceProvider::wrapBackendRenderTarget
*/
- sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc&);
+ sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin);
/**
* Implements GrResourceProvider::wrapBackendTextureAsRenderTarget
@@ -552,7 +553,8 @@ private:
GrBackendTextureFlags,
int sampleCnt,
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&,
GrSurfaceOrigin,
int sampleCnt)=0;
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index a250f6826f..d7b90873ed 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -254,10 +254,10 @@ sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture&
}
sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
- const GrBackendRenderTargetDesc& desc)
+ const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin)
{
ASSERT_SINGLE_OWNER
- return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc);
+ return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT, origin);
}
void GrResourceProvider::assignUniqueKeyToResource(const GrUniqueKey& key,
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index c3d96ff803..e22a0d8428 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -12,6 +12,7 @@
#include "GrGpu.h"
#include "GrPathRange.h"
+class GrBackendRenderTarget;
class GrPath;
class GrRenderTarget;
class GrSingleOwner;
@@ -100,7 +101,7 @@ public:
*
* @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;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 8a4476644d..e057b3455c 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -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,
GrSurfaceOrigin origin,
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;
- idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
+ idDesc.fRTFBOID = info->fFBOID;
idDesc.fMSColorRenderbufferID = 0;
idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
idDesc.fIsMixedSampled = false;
GrSurfaceDesc desc;
- desc.fConfig = wrapDesc.fConfig;
+ desc.fConfig = backendRT.config();
desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag;
- desc.fWidth = wrapDesc.fWidth;
- desc.fHeight = wrapDesc.fHeight;
- desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount());
- desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
+ desc.fWidth = backendRT.width();
+ desc.fHeight = backendRT.height();
+ desc.fSampleCnt = SkTMin(backendRT.sampleCnt(), this->caps()->maxSampleCount());
+ 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,
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index c352efe594..6108445966 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -174,7 +174,8 @@ private:
GrBackendTextureFlags,
int sampleCnt,
GrWrapOwnership) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override;
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrSurfaceOrigin origin) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
int sampleCnt) override;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index a107ee2560..447e59dec8 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -817,32 +817,36 @@ sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTe
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
// 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
// creating and owning the MSAA images.
- if (wrapDesc.fSampleCnt) {
+ if (backendRT.sampleCnt()) {
return nullptr;
}
- const GrVkImageInfo* info =
- reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fRenderTargetHandle);
+ const GrVkImageInfo* info = backendRT.getVkImageInfo();
+ if (!info) {
+ return nullptr;
+ }
if (VK_NULL_HANDLE == info->fImage) {
return nullptr;
}
GrSurfaceDesc desc;
- desc.fConfig = wrapDesc.fConfig;
+ desc.fConfig = backendRT.config();
desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag;
- desc.fWidth = wrapDesc.fWidth;
- desc.fHeight = wrapDesc.fHeight;
+ desc.fWidth = backendRT.width();
+ desc.fHeight = backendRT.height();
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);
- if (tgt && wrapDesc.fStencilBits) {
+ if (tgt && backendRT.stencilBits()) {
if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) {
return nullptr;
}
@@ -855,6 +859,9 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBacken
int sampleCnt) {
const GrVkImageInfo* info = tex.getVkImageInfo();
+ if (!info) {
+ return nullptr;
+ }
if (VK_NULL_HANDLE == info->fImage) {
return nullptr;
}
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index b7a68dc150..b06d4c3b77 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -178,7 +178,8 @@ private:
GrBackendTextureFlags,
int sampleCnt,
GrWrapOwnership) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override;
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrSurfaceOrigin) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
GrSurfaceOrigin,
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 96ac31e16c..5001811cea 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -261,19 +261,36 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
if (!context) {
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;
}
sk_sp<GrRenderTargetContext> rtc(
- context->contextPriv().makeBackendRenderTargetRenderTargetContext(desc,
+ context->contextPriv().makeBackendRenderTargetRenderTargetContext(backendRT,
+ origin,
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),
+ backendRT.width(), backendRT.height(),
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
@@ -282,16 +299,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
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,
const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace,
diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp
index f86bb9f9ef..ba06a1f3c2 100644
--- a/src/views/SkWindow.cpp
+++ b/src/views/SkWindow.cpp
@@ -316,6 +316,7 @@ bool SkWindow::onDispatchClick(int x, int y, Click::State state,
#if SK_SUPPORT_GPU
+#include "GrBackendSurface.h"
#include "GrContext.h"
#include "gl/GrGLInterface.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,
const GrGLInterface* interface,
GrContext* grContext) {
- GrBackendRenderTargetDesc desc;
- desc.fWidth = SkScalarRoundToInt(this->width());
- desc.fHeight = SkScalarRoundToInt(this->height());
- if (0 == desc.fWidth || 0 == desc.fHeight) {
+ int width = SkScalarRoundToInt(this->width());
+ int height = SkScalarRoundToInt(this->height());
+ if (0 == width || 0 == height) {
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,
// so pretend that it's non-sRGB 8888:
- desc.fConfig =
- grContext->caps()->srgbSupport() &&
- info().colorSpace() &&
- (attachmentInfo.fColorBits != 30)
- ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
- desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
- desc.fSampleCnt = attachmentInfo.fSampleCount;
- desc.fStencilBits = attachmentInfo.fStencilBits;
+ GrPixelConfig config = grContext->caps()->srgbSupport() &&
+ info().colorSpace() &&
+ (attachmentInfo.fColorBits != 30)
+ ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
+ GrGLFramebufferInfo fbInfo;
GrGLint 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 =
grContext->caps()->srgbSupport() && info().colorSpace()
? SkColorSpace::MakeSRGB() : nullptr;
- return SkSurface::MakeFromBackendRenderTarget(grContext, desc, colorSpace, &fSurfaceProps);
+ return SkSurface::MakeFromBackendRenderTarget(grContext, backendRT, kBottomLeft_GrSurfaceOrigin,
+ colorSpace, &fSurfaceProps);
}
#endif
diff --git a/tests/ProxyConversionTest.cpp b/tests/ProxyConversionTest.cpp
index a041d68c2b..167cc4b10d 100644
--- a/tests/ProxyConversionTest.cpp
+++ b/tests/ProxyConversionTest.cpp
@@ -10,6 +10,7 @@
#include "Test.h"
#if SK_SUPPORT_GPU
+#include "GrBackendSurface.h"
#include "GrRenderTargetProxy.h"
#include "GrResourceProvider.h"
#include "GrSurfaceProxy.h"
@@ -18,16 +19,12 @@
static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider,
skiatest::Reporter* reporter,
const GrSurfaceDesc& desc) {
- GrBackendRenderTargetDesc backendDesc;
- backendDesc.fWidth = desc.fWidth;
- backendDesc.fHeight = desc.fHeight;
- backendDesc.fConfig = desc.fConfig;
- backendDesc.fOrigin = desc.fOrigin;
- backendDesc.fSampleCnt = desc.fSampleCnt;
- backendDesc.fStencilBits = 8;
- backendDesc.fRenderTargetHandle = 0;
-
- sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendDesc));
+ GrGLFramebufferInfo fboInfo;
+ fboInfo.fFBOID = 0;
+ GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
+ desc.fConfig, fboInfo);
+
+ sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin));
SkASSERT(!defaultFBO->asTexture());
return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
@@ -62,6 +59,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo
desc.fWidth = 64;
desc.fHeight = 64;
desc.fConfig = kRGBA_8888_GrPixelConfig;
+ desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
if (kOpenGL_GrBackend == ctxInfo.backend()) {
// External on-screen render target.
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index db407d791f..6553b4e94f 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -10,6 +10,7 @@
#include "Test.h"
#if SK_SUPPORT_GPU
+#include "GrBackendSurface.h"
#include "GrRenderTargetPriv.h"
#include "GrRenderTargetProxy.h"
#include "GrResourceProvider.h"
@@ -20,7 +21,7 @@
static void check_surface(skiatest::Reporter* reporter,
GrSurfaceProxy* proxy,
GrSurfaceOrigin origin,
- int width, int height,
+ int width, int height,
GrPixelConfig config,
const GrGpuResource::UniqueID& uniqueID,
SkBudgeted budgeted) {
@@ -228,17 +229,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
// External on-screen render target.
if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
- GrBackendRenderTargetDesc backendDesc;
- backendDesc.fWidth = kWidthHeight;
- backendDesc.fHeight = kWidthHeight;
- backendDesc.fConfig = config;
- backendDesc.fOrigin = origin;
- backendDesc.fSampleCnt = numSamples;
- backendDesc.fStencilBits = 8;
- backendDesc.fRenderTargetHandle = 0;
+ GrGLFramebufferInfo fboInfo;
+ fboInfo.fFBOID = 0;
+ GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, 8,
+ config, fboInfo);
sk_sp<GrRenderTarget> defaultFBO(
- provider->wrapBackendRenderTarget(backendDesc));
+ provider->wrapBackendRenderTarget(backendRT, origin));
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
check_surface(reporter, sProxy.get(), origin,
diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp
index 44b5e72bc9..0ae3402da2 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -93,30 +93,24 @@ void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) {
true);
const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj);
- // check basic borrowed creation
- GrBackendRenderTargetDesc desc;
- desc.fWidth = kW;
- 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);
+ GrBackendRenderTarget backendRT(kW, kH, 0, 0, *backendTex);
+
+ sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(backendRT, kTopLeft_GrSurfaceOrigin);
REPORTER_ASSERT(reporter, rt);
// image is null
GrVkImageInfo backendCopy = *backendTex;
backendCopy.fImage = VK_NULL_HANDLE;
- desc.fRenderTargetHandle = (GrBackendObject)&backendCopy;
- rt = gpu->wrapBackendRenderTarget(desc);
+ GrBackendRenderTarget backendRT2(kW, kH, 0, 0, backendCopy);
+ rt = gpu->wrapBackendRenderTarget(backendRT2, kTopLeft_GrSurfaceOrigin);
REPORTER_ASSERT(reporter, !rt);
// alloc is null
backendCopy.fImage = backendTex->fImage;
backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 };
// 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);
// When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 5582a2593a..7fe9a43f28 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -358,7 +358,8 @@ private:
return nullptr;
}
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override {
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrSurfaceOrigin) override {
return nullptr;
}
diff --git a/tools/viewer/sk_app/GLWindowContext.cpp b/tools/viewer/sk_app/GLWindowContext.cpp
index ff56ce8668..6195199ce0 100644
--- a/tools/viewer/sk_app/GLWindowContext.cpp
+++ b/tools/viewer/sk_app/GLWindowContext.cpp
@@ -6,19 +6,18 @@
* found in the LICENSE file.
*/
+#include "GrBackendSurface.h"
#include "GrContext.h"
-#include "SkSurface.h"
+#include "GrRenderTarget.h"
#include "GLWindowContext.h"
#include "gl/GrGLDefines.h"
-
#include "gl/GrGLUtil.h"
-#include "GrRenderTarget.h"
-#include "GrContext.h"
#include "SkCanvas.h"
#include "SkImage_Base.h"
#include "SkMathPriv.h"
+#include "SkSurface.h"
namespace sk_app {
@@ -64,7 +63,7 @@ void GLWindowContext::destroyContext() {
fContext->unref();
fContext = nullptr;
}
-
+
fBackendContext.reset(nullptr);
this->onDestroyContext();
@@ -73,18 +72,21 @@ void GLWindowContext::destroyContext() {
sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
if (nullptr == fSurface) {
if (fContext) {
- GrBackendRenderTargetDesc desc;
- desc.fWidth = this->fWidth;
- desc.fHeight = this->fHeight;
- desc.fConfig = fPixelConfig;
- desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
- desc.fSampleCnt = fSampleCount;
- desc.fStencilBits = fStencilBits;
+ GrGLFramebufferInfo fbInfo;
GrGLint buffer;
- GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer));
- desc.fRenderTargetHandle = buffer;
-
- fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, desc,
+ GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING,
+ &buffer));
+ fbInfo.fFBOID = buffer;
+
+ GrBackendRenderTarget backendRT(fWidth,
+ fHeight,
+ fSampleCount,
+ fStencilBits,
+ fPixelConfig,
+ fbInfo);
+
+ fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, backendRT,
+ kBottomLeft_GrSurfaceOrigin,
fDisplayParams.fColorSpace,
&fSurfaceProps);
}