Reland "Remove GPU-related calls from SkSurface.h when !SK_SUPPORT_GPU"

This is a reland of 74105c5d09

Original change's description:
> Remove GPU-related calls from SkSurface.h when !SK_SUPPORT_GPU
>
> Change-Id: Idca02c40bd8f540919702f09ba2a809acc377e67
> Bug: skia:12584
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/464295
> Reviewed-by: Brian Osman <brianosman@google.com>

Bug: skia:12584
Change-Id: Id679bd61eddb341598e149a7a87e3ba9f0dc8943
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/464976
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Kevin Lubick 2021-10-28 15:06:25 -04:00
parent ae67f07a58
commit 17616469dd
4 changed files with 170 additions and 158 deletions

View File

@ -14,8 +14,11 @@ Milestone 97
MakeFromYUVAPixmaps, MakePromiseTexture, MakePromiseYUVATexture, MakeBackendTextureFromSkImage,
flush, flushAndSubmit, getBackendTexture, makeTextureImage.
These were all no-ops anyway when just the CPU backend was compiled in.
* * *
* The following functions and methods are not defined in SkSurface when SK_SUPPORT_GPU is 0:
MakeFromBackendTexture, MakeFromBackendRenderTarget, MakeRenderTarget,
getBackendTexture, getBackendRenderTarget, replaceBackendTexture. flush() with parameters
was removed as well. These were all no-ops anyway when just the CPU backend was compiled in
(noting that flush() and flushAndSubmit() are still no-ops on the CPU backend).
Milestone 96
------------

View File

@ -13,7 +13,9 @@
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurfaceProps.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrTypes.h"
#endif
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
#include <android/hardware_buffer.h>
@ -34,6 +36,7 @@ class GrBackendTexture;
class GrDirectContext;
class GrRecordingContext;
class GrRenderTarget;
enum GrSurfaceOrigin: int;
/** \class SkSurface
SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
@ -249,6 +252,110 @@ public:
RenderTargetReleaseProc releaseProc = nullptr,
ReleaseContext releaseContext = nullptr);
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
describes the pixel format in SkColorType, and transparency in
SkAlphaType, and color matching in SkColorSpace.
sampleCount requests the number of samples per pixel.
Pass zero to disable multi-sample anti-aliasing. The request is rounded
up to the next supported count, or rounded down if it is larger than the
maximum supported count.
surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
@param context GPU context
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace;
width, or height, or both, may be zero
@param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@param shouldCreateWithMips hint that SkSurface will host mip map images
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo,
int sampleCount, GrSurfaceOrigin surfaceOrigin,
const SkSurfaceProps* surfaceProps,
bool shouldCreateWithMips = false);
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
describes the pixel format in SkColorType, and transparency in
SkAlphaType, and color matching in SkColorSpace.
sampleCount requests the number of samples per pixel.
Pass zero to disable multi-sample anti-aliasing. The request is rounded
up to the next supported count, or rounded down if it is larger than the
maximum supported count.
SkSurface bottom-left corner is pinned to the origin.
@param context GPU context
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
of raster surface; width, or height, or both, may be zero
@param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo, int sampleCount,
const SkSurfaceProps* surfaceProps) {
#if SK_SUPPORT_GPU
return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
kBottomLeft_GrSurfaceOrigin, surfaceProps);
#else
// TODO(kjlubick, scroggo) Remove this once Android is updated.
return nullptr;
#endif
}
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
describes the pixel format in SkColorType, and transparency in
SkAlphaType, and color matching in SkColorSpace.
SkSurface bottom-left corner is pinned to the origin.
@param context GPU context
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
of raster surface; width, or height, or both, may be zero
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo) {
#if SK_SUPPORT_GPU
if (!imageInfo.width() || !imageInfo.height()) {
return nullptr;
}
return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin,
nullptr);
#else
// TODO(kjlubick, scroggo) Remove this once Android is updated.
return nullptr;
#endif
}
/** Returns SkSurface on GPU indicated by context that is compatible with the provided
characterization. budgeted selects whether allocation for pixels is tracked by context.
@param context GPU context
@param characterization description of the desired SkSurface
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
const SkSurfaceCharacterization& characterization,
SkBudgeted budgeted);
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
/** Private.
Creates SkSurface from Android hardware buffer.
@ -333,99 +440,6 @@ public:
SK_API_AVAILABLE(macos(10.11), ios(9.0));
#endif
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
describes the pixel format in SkColorType, and transparency in
SkAlphaType, and color matching in SkColorSpace.
sampleCount requests the number of samples per pixel.
Pass zero to disable multi-sample anti-aliasing. The request is rounded
up to the next supported count, or rounded down if it is larger than the
maximum supported count.
surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
@param context GPU context
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace;
width, or height, or both, may be zero
@param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@param shouldCreateWithMips hint that SkSurface will host mip map images
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo,
int sampleCount, GrSurfaceOrigin surfaceOrigin,
const SkSurfaceProps* surfaceProps,
bool shouldCreateWithMips = false);
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
describes the pixel format in SkColorType, and transparency in
SkAlphaType, and color matching in SkColorSpace.
sampleCount requests the number of samples per pixel.
Pass zero to disable multi-sample anti-aliasing. The request is rounded
up to the next supported count, or rounded down if it is larger than the
maximum supported count.
SkSurface bottom-left corner is pinned to the origin.
@param context GPU context
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
of raster surface; width, or height, or both, may be zero
@param sampleCount samples per pixel, or 0 to disable multi-sample anti-aliasing
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo, int sampleCount,
const SkSurfaceProps* surfaceProps) {
return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
kBottomLeft_GrSurfaceOrigin, surfaceProps);
}
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
describes the pixel format in SkColorType, and transparency in
SkAlphaType, and color matching in SkColorSpace.
SkSurface bottom-left corner is pinned to the origin.
@param context GPU context
@param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace,
of raster surface; width, or height, or both, may be zero
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo) {
if (!imageInfo.width() || !imageInfo.height()) {
return nullptr;
}
return MakeRenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin,
nullptr);
}
/** Returns SkSurface on GPU indicated by context that is compatible with the provided
characterization. budgeted selects whether allocation for pixels is tracked by context.
@param context GPU context
@param characterization description of the desired SkSurface
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context,
const SkSurfaceCharacterization& characterization,
SkBudgeted budgeted);
/** Is this surface compatible with the provided characterization?
This method can be used to determine if an existing SkSurface is a viable destination
@ -497,6 +511,7 @@ public:
*/
GrRecordingContext* recordingContext();
#if SK_SUPPORT_GPU
enum BackendHandleAccess {
kFlushRead_BackendHandleAccess, //!< back-end object is readable
kFlushWrite_BackendHandleAccess, //!< back-end object is writable
@ -559,6 +574,7 @@ public:
ContentChangeMode mode = kRetain_ContentChangeMode,
TextureReleaseProc textureReleaseProc = nullptr,
ReleaseContext releaseContext = nullptr);
#endif
/** Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas.
SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface
@ -887,6 +903,7 @@ public:
kPresent, //!< back-end surface will be used for presenting to screen
};
#if SK_SUPPORT_GPU
/** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
MSAA. A call to GrDirectContext::submit is always required to ensure work is actually sent
to the gpu. Some specific API details:
@ -921,7 +938,7 @@ public:
the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
client is still responsible for deleting any initialized semaphores.
Regardleess of semaphore submission the context will still be flushed. It should be
Regardless of semaphore submission the context will still be flushed. It should be
emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
happen. It simply means there were no semaphores submitted to the GPU. A caller should only
take this as a failure if they passed in semaphores to be submitted.
@ -979,8 +996,9 @@ public:
*/
GrSemaphoresSubmitted flush(const GrFlushInfo& info,
const GrBackendSurfaceMutableState* newState = nullptr);
#endif // SK_SUPPORT_GPU
void flush() { this->flush({}); }
void flush();
/** Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
executing any more commands on the GPU for this surface. If this call returns false, then

View File

@ -8,7 +8,6 @@
#include <atomic>
#include <cmath>
#include "include/core/SkCanvas.h"
#include "include/gpu/GrBackendSurface.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkImagePriv.h"
#include "src/core/SkPaintPriv.h"
@ -16,6 +15,10 @@
#include "src/image/SkRescaleAndReadPixels.h"
#include "src/image/SkSurface_Base.h"
#ifdef SK_SUPPORT_GPU
#include "include/gpu/GrBackendSurface.h"
#endif
SkSurfaceProps::SkSurfaceProps() : fFlags(0), fPixelGeometry(kUnknown_SkPixelGeometry) {}
SkSurfaceProps::SkSurfaceProps(uint32_t flags, SkPixelGeometry pg)
@ -51,6 +54,7 @@ GrRecordingContext* SkSurface_Base::onGetRecordingContext() {
return nullptr;
}
#if SK_SUPPORT_GPU
GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) {
return GrBackendTexture(); // invalid
}
@ -65,6 +69,7 @@ bool SkSurface_Base::onReplaceBackendTexture(const GrBackendTexture&,
ReleaseContext) {
return false;
}
#endif
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
const SkSamplingOptions& sampling, const SkPaint* paint) {
@ -313,6 +318,28 @@ GrRecordingContext* SkSurface::recordingContext() {
return asSB(this)->onGetRecordingContext();
}
bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
bool deleteSemaphoresAfterWait) {
return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
}
bool SkSurface::characterize(SkSurfaceCharacterization* characterization) const {
return asConstSB(this)->onCharacterize(characterization);
}
bool SkSurface::isCompatible(const SkSurfaceCharacterization& characterization) const {
return asConstSB(this)->onIsCompatible(characterization);
}
bool SkSurface::draw(sk_sp<const SkDeferredDisplayList> ddl, int xOffset, int yOffset) {
if (xOffset != 0 || yOffset != 0) {
return false; // the offsets currently aren't supported
}
return asSB(this)->onDraw(std::move(ddl), { xOffset, yOffset });
}
#if SK_SUPPORT_GPU
GrBackendTexture SkSurface::getBackendTexture(BackendHandleAccess access) {
return asSB(this)->onGetBackendTexture(access);
}
@ -338,26 +365,20 @@ GrSemaphoresSubmitted SkSurface::flush(const GrFlushInfo& info,
return asSB(this)->onFlush(BackendSurfaceAccess::kNoAccess, info, newState);
}
bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
bool deleteSemaphoresAfterWait) {
return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
void SkSurface::flush() {
this->flush({});
}
#else
void SkSurface::flush() {} // Flush is a no-op for CPU surfaces
bool SkSurface::characterize(SkSurfaceCharacterization* characterization) const {
return asConstSB(this)->onCharacterize(characterization);
}
bool SkSurface::isCompatible(const SkSurfaceCharacterization& characterization) const {
return asConstSB(this)->onIsCompatible(characterization);
}
bool SkSurface::draw(sk_sp<const SkDeferredDisplayList> ddl, int xOffset, int yOffset) {
if (xOffset != 0 || yOffset != 0) {
return false; // the offsets currently aren't supported
}
return asSB(this)->onDraw(std::move(ddl), { xOffset, yOffset });
void SkSurface::flushAndSubmit(bool syncCpu) {}
// TODO(kjlubick, scroggo) Remove this once Android is updated.
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext*, SkBudgeted, const SkImageInfo&,
int, GrSurfaceOrigin, const SkSurfaceProps*, bool) {
return nullptr;
}
#endif
//////////////////////////////////////////////////////////////////////////////////////
#include "include/utils/SkNoDrawCanvas.h"
@ -388,38 +409,5 @@ sk_sp<SkSurface> SkSurface::MakeNull(int width, int height) {
//////////////////////////////////////////////////////////////////////////////////////
#if !SK_SUPPORT_GPU
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext*, SkBudgeted, const SkImageInfo&,
int, GrSurfaceOrigin, const SkSurfaceProps*, bool) {
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext*, const SkSurfaceCharacterization&,
SkBudgeted) {
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrRecordingContext*, const GrBackendTexture&,
GrSurfaceOrigin origin, int sampleCnt,
SkColorType, sk_sp<SkColorSpace>,
const SkSurfaceProps*,
TextureReleaseProc, ReleaseContext) {
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrRecordingContext*,
const GrBackendRenderTarget&,
GrSurfaceOrigin origin,
SkColorType,
sk_sp<SkColorSpace>,
const SkSurfaceProps*,
RenderTargetReleaseProc, ReleaseContext) {
return nullptr;
}
void SkSurface::flushAndSubmit(bool syncCpu) {
this->flush(BackendSurfaceAccess::kNoAccess, GrFlushInfo());
}
#endif

View File

@ -22,6 +22,7 @@ public:
virtual GrRecordingContext* onGetRecordingContext();
#if SK_SUPPORT_GPU
virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);
virtual GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess);
virtual bool onReplaceBackendTexture(const GrBackendTexture&,
@ -29,6 +30,18 @@ public:
ContentChangeMode,
TextureReleaseProc,
ReleaseContext);
/**
* Issue any pending surface IO to the current backend 3D API and resolve any surface MSAA.
* Inserts the requested number of semaphores for the gpu to signal when work is complete on the
* gpu and inits the array of GrBackendSemaphores with the signaled semaphores.
*/
virtual GrSemaphoresSubmitted onFlush(BackendSurfaceAccess access, const GrFlushInfo&,
const GrBackendSurfaceMutableState*) {
return GrSemaphoresSubmitted::kNo;
}
#endif
/**
* Allocate a canvas that will draw into this surface. We will cache this
* canvas, to return the same object to the caller multiple times. We
@ -105,16 +118,6 @@ public:
*/
virtual void onRestoreBackingMutability() {}
/**
* Issue any pending surface IO to the current backend 3D API and resolve any surface MSAA.
* Inserts the requested number of semaphores for the gpu to signal when work is complete on the
* gpu and inits the array of GrBackendSemaphores with the signaled semaphores.
*/
virtual GrSemaphoresSubmitted onFlush(BackendSurfaceAccess access, const GrFlushInfo&,
const GrBackendSurfaceMutableState*) {
return GrSemaphoresSubmitted::kNo;
}
/**
* Caused the current backend 3D API to wait on the passed in semaphores before executing new
* commands on the gpu. Any previously submitting commands will not be blocked by these