From e2d37c2a07f5473e5fc6fb65e9e23e14127580e9 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Thu, 20 Jul 2017 10:59:44 -0400 Subject: [PATCH] Remove GrBackendRenderTargetDesc in favor of GrBackendRenderTarget. Also removes a reference to GrBackendTextureDesc in a comment and updates markdown docs. Docs-Preview: https://skia.org/?cl=24861 Bug: skia: Change-Id: Ic6490d5ef46953450e6dee69271397bb2b94d0d6 Reviewed-on: https://skia-review.googlesource.com/24861 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- debugger/QT/SkGLWidget.cpp | 34 ++++++++++++------------ debugger/QT/SkGLWidget.h | 3 ++- experimental/GLFWTest/glfw_main.cpp | 28 +++++++++---------- experimental/SkV8Example/SkV8Example.cpp | 25 ++++++++--------- include/core/SkSurface.h | 28 +++---------------- include/gpu/GrBackendSurface.h | 6 ----- include/gpu/GrTypes.h | 33 ----------------------- site/user/sample/color.md | 11 ++++---- site/user/special/vulkan.md | 16 ++++++----- src/gpu/GrBackendSurface.cpp | 23 ---------------- src/image/SkSurface.cpp | 7 ----- src/image/SkSurface_Gpu.cpp | 14 ---------- 12 files changed, 61 insertions(+), 167 deletions(-) diff --git a/debugger/QT/SkGLWidget.cpp b/debugger/QT/SkGLWidget.cpp index a60ae0f0ba..cbd4e777a8 100644 --- a/debugger/QT/SkGLWidget.cpp +++ b/debugger/QT/SkGLWidget.cpp @@ -55,11 +55,10 @@ void SkGLWidget::createRenderTarget() { glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); fCurContext->resetContext(); - - GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()); - desc.fOrigin = kBottomLeft_GrSurfaceOrigin; - - fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext.get(), desc, nullptr); + GrBackendRenderTarget backendRenderTarget = this->getBackendRenderTarget(); + fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext.get(), backendRenderTarget, + kBottomLeft_GrSurfaceOrigin, + nullptr, nullptr); fCanvas = fGpuSurface->getCanvas(); } @@ -78,18 +77,19 @@ void SkGLWidget::paintGL() { } } -GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) { - GrBackendRenderTargetDesc desc; - desc.fWidth = SkScalarRoundToInt(this->width()); - desc.fHeight = SkScalarRoundToInt(this->height()); - desc.fConfig = kSkia8888_GrPixelConfig; - GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_SAMPLES, &desc.fSampleCnt); - GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_STENCIL_BITS, &desc.fStencilBits); - GrGLint buffer; - GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_FRAMEBUFFER_BINDING, &buffer); - desc.fRenderTargetHandle = buffer; - - return desc; +GrBackendRenderTarget SkGLWidget::getBackendRenderTarget() { + GrGLFramebufferInfo info; + int stencilBits; + int sampleCnt; + GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_FRAMEBUFFER_BINDING, &info.fFBOID); + GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_SAMPLES, &sampleCnt); + GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_STENCIL_BITS, &stencilBits); + return GrBackendRenderTarget(SkScalarRoundToInt(this->width()), + SkScalarRoundToInt(this->height()), + sampleCnt, + stencilBits, + kSkia8888_GrPixelConfig, + info); } #endif diff --git a/debugger/QT/SkGLWidget.h b/debugger/QT/SkGLWidget.h index e7493a533c..d590ffb565 100644 --- a/debugger/QT/SkGLWidget.h +++ b/debugger/QT/SkGLWidget.h @@ -16,6 +16,7 @@ #include "SkDebugCanvas.h" #include "SkDebugger.h" #include "SkGpuDevice.h" +#include "GrBackendSurface.h" #include "GrContext.h" #include "gl/GrGLInterface.h" #include "gl/GrGLUtil.h" @@ -51,7 +52,7 @@ private: SkCanvas* fCanvas; SkDebugger* fDebugger; - GrBackendRenderTargetDesc getDesc(int w, int h); + GrBackendRenderTarget getBackendRenderTarget(); }; #endif /* SK_SUPPORT_GPU */ diff --git a/experimental/GLFWTest/glfw_main.cpp b/experimental/GLFWTest/glfw_main.cpp index 63ea1f1d9f..34fbd4ed55 100644 --- a/experimental/GLFWTest/glfw_main.cpp +++ b/experimental/GLFWTest/glfw_main.cpp @@ -5,12 +5,11 @@ * found in the LICENSE file. */ -#include "GLFW/glfw3.h" #include #include - +#include "GLFW/glfw3.h" +#include "GrBackendSurface.h" #include "GrContext.h" - #include "SkCanvas.h" #include "SkImage.h" #include "SkRSXform.h" @@ -32,17 +31,18 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, static void init_skia(int w, int h) { sContext = GrContext::Create(kOpenGL_GrBackend, 0); - - GrBackendRenderTargetDesc desc; - desc.fWidth = w; - desc.fHeight = h; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fOrigin = kBottomLeft_GrSurfaceOrigin; - desc.fSampleCnt = 1; - desc.fStencilBits = 0; - desc.fRenderTargetHandle = 0; // assume default framebuffer - - sSurface = SkSurface::MakeFromBackendRenderTarget(sContext, desc, nullptr, nullptr).release(); + + GrGLFramebufferInfo framebufferInfo; + framebufferInfo.fFBOID = 0; // assume default framebuffer + GrBackendRenderTarget backendRenderTarget(w, h, + 0, // sample count + 0, // stencil bits + kSkia8888_GrPixelConfig, + framebufferInfo); + + sSurface = SkSurface::MakeFromBackendRenderTarget(sContext, backendRenderTarget, + kBottomLeft_GrSurfaceOrigin, + nullptr, nullptr).release(); } static void cleanup_skia() { diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp index a6a2a7e816..b4a0db633b 100644 --- a/experimental/SkV8Example/SkV8Example.cpp +++ b/experimental/SkV8Example/SkV8Example.cpp @@ -8,13 +8,12 @@ */ #include #include - #include "SkV8Example.h" #include "Global.h" #include "JsContext.h" #include "Path2D.h" #include "Path2DBuilder.h" - +#include "GrBackendSurface.h" #include "gl/GrGLUtil.h" #include "gl/GrGLDefines.h" #include "gl/GrGLInterface.h" @@ -85,19 +84,17 @@ void SkV8ExampleWindow::windowSizeChanged() { exit(1); } - GrBackendRenderTargetDesc desc; - desc.fWidth = SkScalarRoundToInt(this->width()); - desc.fHeight = SkScalarRoundToInt(this->height()); - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fOrigin = kBottomLeft_GrSurfaceOrigin; - desc.fSampleCnt = attachmentInfo.fSampleCount; - desc.fStencilBits = attachmentInfo.fStencilBits; - GrGLint buffer; - GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); - desc.fRenderTargetHandle = buffer; - + GrGLFramebufferInfo framebufferInfo; + GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &framebufferInfo.fFBOID); + GrBackendRenderTarget backendRenderTarget(SkScalarRoundToInt(this->width()), + SkScalarRoundToInt(this->height()), + attachmentInfo.fSampleCount, + attachmentInfo.fStencilBits, + kSkia8888_GrPixelConfig, + framebufferInfo); SkSafeUnref(fCurSurface); - fCurSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext, desc, + fCurSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext, backendRenderTarget, + kBottomLeft_GrSurfaceOrigin, nullptr, nullptr).release(); } } diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index c2a98bd315..ec91cc64b1 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -90,16 +90,6 @@ public: GrSurfaceOrigin origin, int sampleCnt, sk_sp, const SkSurfaceProps*); - /** - * Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia will not assume - * ownership of the render target and the client must ensure the render target is valid for the - * lifetime of the SkSurface. - */ - static sk_sp MakeFromBackendRenderTarget(GrContext*, - const GrBackendRenderTargetDesc&, - sk_sp, - const SkSurfaceProps*); - static sk_sp MakeFromBackendRenderTarget(GrContext*, const GrBackendRenderTarget&, GrSurfaceOrigin origin, @@ -109,10 +99,9 @@ public: /** * Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will treat the texture as * a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own - * the associated render target objects (but not the provided texture). The kRenderTarget flag - * must be set on GrBackendTextureDesc for this to succeed. Skia will not assume ownership - * of the texture and the client must ensure the texture is valid for the lifetime of the - * SkSurface. + * the associated render target objects (but not the provided texture). Skia will not assume + * ownership of the texture and the client must ensure the texture is valid for the lifetime + * of the SkSurface. */ static sk_sp MakeFromBackendTextureAsRenderTarget(GrContext*, const GrBackendTexture&, @@ -121,17 +110,6 @@ public: sk_sp, const SkSurfaceProps*); - /** - * Legacy version of the above factory, without color space support. This creates a "legacy" - * surface that operate without gamma correction or color management. - */ - static sk_sp MakeFromBackendRenderTarget(GrContext* ctx, - const GrBackendRenderTargetDesc& desc, - const SkSurfaceProps* props) { - return MakeFromBackendRenderTarget(ctx, desc, nullptr, props); - } - - /** * Return a new surface whose contents will be drawn to an offscreen * render target, allocated by the surface. diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index c9a9ad02e6..55cec78548 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -108,12 +108,6 @@ public: #endif private: - // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc. - GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, GrBackend backend); - - // Friending for access to above constructor taking a GrBackendRenderTargetDesc - friend class SkSurface; - int fWidth; // MakeFromEncoded(sk_sp encoded); // Create an image from a texture in a particular color space - // Caution: There are versions of this constructor that do not take an - // SkColorSpace. But without an SkColorSpace, Skia does not have - // enough information to draw correctly. - sk_sp MakeFromTexture(GrContext*, const GrBackendTextureDesc&, - SkAlphaType, sk_sp, ...); + sk_sp MakeFromTexture(GrContext*, const GrBackendTexture&, + GrSurfaceOrigin, SkAlphaType, sk_sp, + ...); **SkBitmap** is another (not preferred) representation for image sources. Be careful to not forget the color space. @@ -190,4 +188,5 @@ cannot know how to draw without knowing the color space of the source. It is possible to create **an object that is both a source and destination**, if Skia will both draw into it and then draw it somewhere else. The same rules from above still apply, but it is subtle that the color space tag could have an effect (or no effect) depending on how the object is -used. \ No newline at end of file +used. + diff --git a/site/user/special/vulkan.md b/site/user/special/vulkan.md index 8dfd26a46b..45f613f4fe 100644 --- a/site/user/special/vulkan.md +++ b/site/user/special/vulkan.md @@ -33,14 +33,16 @@ To create a GrContext that is backed by Vulkan the client creates a Vulkan devic sk_sp context = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) vkBackendContext); -When using the Vulkan backend the GrBackendObject field in -GrBackendRenderTargetDesc and GrBackendTextureDesc is interpeted as a pointer -to a GrVkImageInfo object. GrVkImageInfo specifies a VkImage and associated -state (tiling, layout, format, etc). This allows the client to import -externally created Vulkan images as destinations for Skia rendering via -SkSurface factory functions or for to composite Skia rendered content using -SkImage::getTextureHandle(). +When using the Vulkan backend, GrVkImageInfo is used to construct GrBackendTexture +and GrBackendRenderTarget objects that in turn are used to create SkSurface and SkImage +objects that refer to VkImages created by the Skia client. +The GrBackendObject returned by SkImage::getTextureHandle(), +SkSurface::getTextureHandle(), and SkSurface::getRenderTargetHandle() should be +interpreted as a GrVkImageInfo*. This allows a client to get the backing VkImage +of a SkImage or SkSurface. + +GrVkImageInfo specifies a VkImage and associated state (tiling, layout, format, etc). After getting a GrVkImageInfo* via getTextureHandle() or getRenderTargetHandle(), the client should check the fImageLayout field to know what layout Skia left the VkImage in before using the VkImage. If the client diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp index d37c73a4a0..04216b7508 100644 --- a/src/gpu/GrBackendSurface.cpp +++ b/src/gpu/GrBackendSurface.cpp @@ -97,29 +97,6 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width, , fBackend(kOpenGL_GrBackend) , fGLInfo(glInfo) {} -GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, - GrBackend backend) - : fWidth(desc.fWidth) - , fHeight(desc.fHeight) - , fSampleCnt(desc.fSampleCnt) - , fStencilBits(desc.fStencilBits) - , fConfig(desc.fConfig) - , fBackend(backend) { - if (kOpenGL_GrBackend == backend) { - fGLInfo.fFBOID = static_cast(desc.fRenderTargetHandle); - } else { - SkASSERT(kVulkan_GrBackend == backend); -#ifdef SK_VULKAN - const GrVkImageInfo* vkInfo = - reinterpret_cast(desc.fRenderTargetHandle); - fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat); - fVkInfo = *vkInfo; -#else - fConfig = kUnknown_GrPixelConfig; -#endif - } -} - #ifdef SK_VULKAN const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { if (kVulkan_GrBackend == fBackend) { diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index d7fa60589a..e0a058093b 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -240,13 +240,6 @@ sk_sp SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTe return nullptr; } -sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext*, - const GrBackendRenderTargetDesc&, - sk_sp, - const SkSurfaceProps*) { - return nullptr; -} - sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext*, const GrBackendRenderTarget&, GrSurfaceOrigin origin, diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 143a6039f0..5b51942b38 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -232,20 +232,6 @@ sk_sp SkSurface::MakeFromBackendTexture(GrContext* context, const GrB return sk_make_sp(std::move(device)); } -sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext* context, - const GrBackendRenderTargetDesc& desc, - sk_sp colorSpace, - const SkSurfaceProps* props) { - if (!context) { - return nullptr; - } - - GrBackendRenderTarget backendRT(desc, context->contextPriv().getBackend()); - return MakeFromBackendRenderTarget(context, backendRT, desc.fOrigin, - std::move(colorSpace), props); - -} - sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin,