Revert "Revert "Revert "Revert "Remove GrBackendRenderTargetDesc in favor of GrBackendRenderTarget.""""

This reverts commit 6df4d6be0d.

Reason for revert: Google3 fix landed

Original change's description:
> Revert "Revert "Revert "Remove GrBackendRenderTargetDesc in favor of GrBackendRenderTarget."""
> 
> This reverts commit 71554bc256.
> 
> Reason for revert: Google3
> 
> Original change's description:
> > Revert "Revert "Remove GrBackendRenderTargetDesc in favor of GrBackendRenderTarget.""
> > 
> > This reverts commit 807371c15b.
> > 
> > Docs-Preview: https://skia.org/?cl=40260
> > Change-Id: I28e0434c455155ff39a5aaa4141abdf442474e87
> > Reviewed-on: https://skia-review.googlesource.com/40260
> > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > Commit-Queue: Brian Salomon <bsalomon@google.com>
> 
> TBR=egdaniel@google.com,bsalomon@google.com
> 
> Change-Id: Ifdfa896a70db69935473276d12dce54de5c6b6f7
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/41500
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

TBR=egdaniel@google.com,bsalomon@google.com

Change-Id: I827419bb19972c3644929a8c984bb9534baab0ba
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/41700
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2017-08-31 20:04:00 +00:00 committed by Skia Commit-Bot
parent 085c0862f6
commit f43d0001e4
12 changed files with 60 additions and 166 deletions

View File

@ -55,11 +55,10 @@ void SkGLWidget::createRenderTarget() {
glClearStencil(0); glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT);
fCurContext->resetContext(); fCurContext->resetContext();
GrBackendRenderTarget backendRenderTarget = this->getBackendRenderTarget();
GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height()); fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext.get(), backendRenderTarget,
desc.fOrigin = kBottomLeft_GrSurfaceOrigin; kBottomLeft_GrSurfaceOrigin,
nullptr, nullptr);
fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext.get(), desc, nullptr);
fCanvas = fGpuSurface->getCanvas(); fCanvas = fGpuSurface->getCanvas();
} }
@ -78,18 +77,19 @@ void SkGLWidget::paintGL() {
} }
} }
GrBackendRenderTargetDesc SkGLWidget::getDesc(int w, int h) { GrBackendRenderTarget SkGLWidget::getBackendRenderTarget() {
GrBackendRenderTargetDesc desc; GrGLFramebufferInfo info;
desc.fWidth = SkScalarRoundToInt(this->width()); int stencilBits;
desc.fHeight = SkScalarRoundToInt(this->height()); int sampleCnt;
desc.fConfig = kSkia8888_GrPixelConfig; GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_FRAMEBUFFER_BINDING, &info.fFBOID);
GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_SAMPLES, &desc.fSampleCnt); GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_SAMPLES, &sampleCnt);
GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_STENCIL_BITS, &desc.fStencilBits); GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_STENCIL_BITS, &stencilBits);
GrGLint buffer; return GrBackendRenderTarget(SkScalarRoundToInt(this->width()),
GR_GL_GetIntegerv(fCurIntf.get(), GR_GL_FRAMEBUFFER_BINDING, &buffer); SkScalarRoundToInt(this->height()),
desc.fRenderTargetHandle = buffer; sampleCnt,
stencilBits,
return desc; kSkia8888_GrPixelConfig,
info);
} }
#endif #endif

View File

@ -16,6 +16,7 @@
#include "SkDebugCanvas.h" #include "SkDebugCanvas.h"
#include "SkDebugger.h" #include "SkDebugger.h"
#include "SkGpuDevice.h" #include "SkGpuDevice.h"
#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"
@ -51,7 +52,7 @@ private:
SkCanvas* fCanvas; SkCanvas* fCanvas;
SkDebugger* fDebugger; SkDebugger* fDebugger;
GrBackendRenderTargetDesc getDesc(int w, int h); GrBackendRenderTarget getBackendRenderTarget();
}; };
#endif /* SK_SUPPORT_GPU */ #endif /* SK_SUPPORT_GPU */

View File

@ -5,12 +5,11 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "GLFW/glfw3.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "GLFW/glfw3.h"
#include "GrBackendSurface.h"
#include "GrContext.h" #include "GrContext.h"
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkImage.h" #include "SkImage.h"
#include "SkRSXform.h" #include "SkRSXform.h"
@ -33,16 +32,17 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
static void init_skia(int w, int h) { static void init_skia(int w, int h) {
sContext = GrContext::MakeGL(nullptr).release(); sContext = GrContext::MakeGL(nullptr).release();
GrBackendRenderTargetDesc desc; GrGLFramebufferInfo framebufferInfo;
desc.fWidth = w; framebufferInfo.fFBOID = 0; // assume default framebuffer
desc.fHeight = h; GrBackendRenderTarget backendRenderTarget(w, h,
desc.fConfig = kSkia8888_GrPixelConfig; 0, // sample count
desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 0, // stencil bits
desc.fSampleCnt = 1; kSkia8888_GrPixelConfig,
desc.fStencilBits = 0; framebufferInfo);
desc.fRenderTargetHandle = 0; // assume default framebuffer
sSurface = SkSurface::MakeFromBackendRenderTarget(sContext, desc, nullptr, nullptr).release(); sSurface = SkSurface::MakeFromBackendRenderTarget(sContext, backendRenderTarget,
kBottomLeft_GrSurfaceOrigin,
nullptr, nullptr).release();
} }
static void cleanup_skia() { static void cleanup_skia() {

View File

@ -8,13 +8,12 @@
*/ */
#include <v8.h> #include <v8.h>
#include <include/libplatform/libplatform.h> #include <include/libplatform/libplatform.h>
#include "SkV8Example.h" #include "SkV8Example.h"
#include "Global.h" #include "Global.h"
#include "JsContext.h" #include "JsContext.h"
#include "Path2D.h" #include "Path2D.h"
#include "Path2DBuilder.h" #include "Path2DBuilder.h"
#include "GrBackendSurface.h"
#include "gl/GrGLUtil.h" #include "gl/GrGLUtil.h"
#include "gl/GrGLDefines.h" #include "gl/GrGLDefines.h"
#include "gl/GrGLInterface.h" #include "gl/GrGLInterface.h"
@ -84,19 +83,17 @@ void SkV8ExampleWindow::windowSizeChanged() {
exit(1); exit(1);
} }
GrBackendRenderTargetDesc desc; GrGLFramebufferInfo framebufferInfo;
desc.fWidth = SkScalarRoundToInt(this->width()); GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &framebufferInfo.fFBOID);
desc.fHeight = SkScalarRoundToInt(this->height()); GrBackendRenderTarget backendRenderTarget(SkScalarRoundToInt(this->width()),
desc.fConfig = kSkia8888_GrPixelConfig; SkScalarRoundToInt(this->height()),
desc.fOrigin = kBottomLeft_GrSurfaceOrigin; attachmentInfo.fSampleCount,
desc.fSampleCnt = attachmentInfo.fSampleCount; attachmentInfo.fStencilBits,
desc.fStencilBits = attachmentInfo.fStencilBits; kSkia8888_GrPixelConfig,
GrGLint buffer; framebufferInfo);
GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer);
desc.fRenderTargetHandle = buffer;
SkSafeUnref(fCurSurface); SkSafeUnref(fCurSurface);
fCurSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext, desc, fCurSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext, backendRenderTarget,
kBottomLeft_GrSurfaceOrigin,
nullptr, nullptr).release(); nullptr, nullptr).release();
} }
} }

View File

@ -94,16 +94,6 @@ public:
GrSurfaceOrigin origin, int sampleCnt, GrSurfaceOrigin origin, int sampleCnt,
sk_sp<SkColorSpace>, const SkSurfaceProps*); sk_sp<SkColorSpace>, 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<SkSurface> MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTargetDesc&,
sk_sp<SkColorSpace>,
const SkSurfaceProps*);
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*, static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTarget&, const GrBackendRenderTarget&,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
@ -113,10 +103,9 @@ public:
/** /**
* Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will treat the texture as * 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 * 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 * the associated render target objects (but not the provided texture). Skia will not assume
* must be set on GrBackendTextureDesc for this to succeed. Skia will not assume ownership * ownership of the texture and the client must ensure the texture is valid for the lifetime
* of the texture and the client must ensure the texture is valid for the lifetime of the * of the SkSurface.
* SkSurface.
*/ */
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext*, static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext*,
const GrBackendTexture&, const GrBackendTexture&,
@ -125,17 +114,6 @@ public:
sk_sp<SkColorSpace>, sk_sp<SkColorSpace>,
const SkSurfaceProps*); 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<SkSurface> 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 * Return a new surface whose contents will be drawn to an offscreen
* render target, allocated by the surface. * render target, allocated by the surface.

View File

@ -108,12 +108,6 @@ public:
#endif #endif
private: 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; //<! width in pixels int fWidth; //<! width in pixels
int fHeight; //<! height in pixels int fHeight; //<! height in pixels

View File

@ -641,39 +641,6 @@ enum GrWrapOwnership {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/**
* Gr can wrap an existing render target created by the client in the 3D API
* with a GrRenderTarget object. The client is responsible for ensuring that the
* underlying 3D API object lives at least as long as the GrRenderTarget object
* wrapping it. We require the client to explicitly provide information about
* the target, such as width, height, and pixel config rather than querying the
* 3D API for these values. We expect these properties to be immutable even if
* the 3D API doesn't require this (OpenGL).
*/
struct GrBackendRenderTargetDesc {
GrBackendRenderTargetDesc() { memset(this, 0, sizeof(*this)); }
int fWidth; //<! width in pixels
int fHeight; //<! height in pixels
GrPixelConfig fConfig; //<! color format
GrSurfaceOrigin fOrigin; //<! pixel origin
/**
* The number of samples per pixel. Gr uses this to influence decisions
* about applying other forms of anti-aliasing.
*/
int fSampleCnt;
/**
* Number of bits of stencil per-pixel.
*/
int fStencilBits;
/**
* Handle to the 3D API object.
* OpenGL: FBO ID
* Vulkan: GrVkImageInfo*
*/
GrBackendObject fRenderTargetHandle;
};
/** /**
* The GrContext's cache of backend context state can be partially invalidated. * The GrContext's cache of backend context state can be partially invalidated.
* These enums are specific to the GL backend and we'd add a new set for an alternative backend. * These enums are specific to the GL backend and we'd add a new set for an alternative backend.

View File

@ -116,11 +116,9 @@ can be in any gamut, but must have a linear transfer function.
sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded); sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded);
// Create an image from a texture in a particular color space // Create an image from a texture in a particular color space
// Caution: There are versions of this constructor that do not take an sk_sp<SkImage> MakeFromTexture(GrContext*, const GrBackendTexture&,
// SkColorSpace. But without an SkColorSpace, Skia does not have GrSurfaceOrigin, SkAlphaType, sk_sp<SkColorSpace>,
// enough information to draw correctly. ...);
sk_sp<SkImage> MakeFromTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType, sk_sp<SkColorSpace>, ...);
**SkBitmap** is another (not preferred) representation for image sources. Be careful to not forget **SkBitmap** is another (not preferred) representation for image sources. Be careful to not forget
the color space. the color space.
@ -191,3 +189,4 @@ It is possible to create **an object that is both a source and destination**, if
draw into it and then draw it somewhere else. The same rules from above still apply, but it is 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 subtle that the color space tag could have an effect (or no effect) depending on how the object is
used. used.

View File

@ -33,14 +33,16 @@ To create a GrContext that is backed by Vulkan the client creates a Vulkan devic
sk_sp<GrContext> context = GrContext::MakeVulkan(vkBackendContext); sk_sp<GrContext> context = GrContext::MakeVulkan(vkBackendContext);
When using the Vulkan backend the GrBackendObject field in When using the Vulkan backend, GrVkImageInfo is used to construct GrBackendTexture
GrBackendRenderTargetDesc and GrBackendTextureDesc is interpeted as a pointer and GrBackendRenderTarget objects that in turn are used to create SkSurface and SkImage
to a GrVkImageInfo object. GrVkImageInfo specifies a VkImage and associated objects that refer to VkImages created by the Skia client.
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().
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 After getting a GrVkImageInfo* via getTextureHandle() or
getRenderTargetHandle(), the client should check the fImageLayout field to know getRenderTargetHandle(), the client should check the fImageLayout field to know
what layout Skia left the VkImage in before using the VkImage. If the client what layout Skia left the VkImage in before using the VkImage. If the client

View File

@ -97,29 +97,6 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
, fBackend(kOpenGL_GrBackend) , fBackend(kOpenGL_GrBackend)
, fGLInfo(glInfo) {} , 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<GrGLuint>(desc.fRenderTargetHandle);
} else {
SkASSERT(kVulkan_GrBackend == backend);
#ifdef SK_VULKAN
const GrVkImageInfo* vkInfo =
reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle);
fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
fVkInfo = *vkInfo;
#else
fConfig = kUnknown_GrPixelConfig;
#endif
}
}
#ifdef SK_VULKAN #ifdef SK_VULKAN
const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) { if (kVulkan_GrBackend == fBackend) {

View File

@ -258,13 +258,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTe
return nullptr; return nullptr;
} }
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTargetDesc&,
sk_sp<SkColorSpace>,
const SkSurfaceProps*) {
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*, sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTarget&, const GrBackendRenderTarget&,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,

View File

@ -265,20 +265,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrB
return sk_make_sp<SkSurface_Gpu>(std::move(device)); return sk_make_sp<SkSurface_Gpu>(std::move(device));
} }
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
const GrBackendRenderTargetDesc& desc,
sk_sp<SkColorSpace> 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> SkSurface::MakeFromBackendRenderTarget(GrContext* context, sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
const GrBackendRenderTarget& backendRT, const GrBackendRenderTarget& backendRT,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,