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

This reverts commit 74105c5d09.

Reason for revert: Breaking Android's GPU-less build (used on desktops for AndroidStudio)

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: I7742f67d3498f45ab862daae4c1d3518e89f7c2c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/464921
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Leon Scroggins <scroggo@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Owners-Override: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Leon Scroggins 2021-10-28 17:04:49 +00:00 committed by Kevin Lubick
parent 1fe391f0dc
commit af5049b0d7
4 changed files with 150 additions and 147 deletions

View File

@ -14,11 +14,8 @@ 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,9 +13,7 @@
#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>
@ -172,7 +170,6 @@ public:
static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height,
const SkSurfaceProps* surfaceProps = nullptr);
#if SK_SUPPORT_GPU
/** Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. */
typedef void* ReleaseContext;
@ -252,6 +249,90 @@ public:
RenderTargetReleaseProc releaseProc = nullptr,
ReleaseContext releaseContext = nullptr);
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
/** Private.
Creates SkSurface from Android hardware buffer.
Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released
when the SkSurface is destroyed and there is no pending work on the GPU involving the
buffer.
Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
Currently this is only supported for buffers that can be textured as well as rendered to.
In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.
@param context GPU context
@param hardwareBuffer AHardwareBuffer Android hardware buffer
@param colorSpace range of colors; may be nullptr
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrDirectContext* context,
AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps);
#endif
#ifdef SK_METAL
/** Creates SkSurface from CAMetalLayer.
Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be
released when the SkSurface is destroyed.
Only available when Metal API is enabled.
Will grab the current drawable from the layer and use its texture as a backendRT to
create a renderable surface.
@param context GPU context
@param layer GrMTLHandle (expected to be a CAMetalLayer*)
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
@param colorSpace range of colors; may be nullptr
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@param drawable Pointer to drawable to be filled in when this surface is
instantiated; may not be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromCAMetalLayer(GrRecordingContext* context,
GrMTLHandle layer,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps,
GrMTLHandle* drawable)
SK_API_AVAILABLE_CA_METAL_LAYER;
/** Creates SkSurface from MTKView.
Returned SkSurface takes a reference on the MTKView. The ref on the layer will be
released when the SkSurface is destroyed.
Only available when Metal API is enabled.
Will grab the current drawable from the layer and use its texture as a backendRT to
create a renderable surface.
@param context GPU context
@param layer GrMTLHandle (expected to be a MTKView*)
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
@param colorSpace range of colors; may be nullptr
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromMTKView(GrRecordingContext* context,
GrMTLHandle mtkView,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps)
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
@ -345,92 +426,6 @@ public:
const SkSurfaceCharacterization& characterization,
SkBudgeted budgeted);
#endif // SK_SUPPORT_GPU
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
/** Private.
Creates SkSurface from Android hardware buffer.
Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released
when the SkSurface is destroyed and there is no pending work on the GPU involving the
buffer.
Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
Currently this is only supported for buffers that can be textured as well as rendered to.
In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and
AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.
@param context GPU context
@param hardwareBuffer AHardwareBuffer Android hardware buffer
@param colorSpace range of colors; may be nullptr
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrDirectContext* context,
AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps);
#endif
#ifdef SK_METAL
/** Creates SkSurface from CAMetalLayer.
Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be
released when the SkSurface is destroyed.
Only available when Metal API is enabled.
Will grab the current drawable from the layer and use its texture as a backendRT to
create a renderable surface.
@param context GPU context
@param layer GrMTLHandle (expected to be a CAMetalLayer*)
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
@param colorSpace range of colors; may be nullptr
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@param drawable Pointer to drawable to be filled in when this surface is
instantiated; may not be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromCAMetalLayer(GrRecordingContext* context,
GrMTLHandle layer,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps,
GrMTLHandle* drawable)
SK_API_AVAILABLE_CA_METAL_LAYER;
/** Creates SkSurface from MTKView.
Returned SkSurface takes a reference on the MTKView. The ref on the layer will be
released when the SkSurface is destroyed.
Only available when Metal API is enabled.
Will grab the current drawable from the layer and use its texture as a backendRT to
create a renderable surface.
@param context GPU context
@param layer GrMTLHandle (expected to be a MTKView*)
@param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
@param colorSpace range of colors; may be nullptr
@param surfaceProps LCD striping orientation and setting for device independent
fonts; may be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromMTKView(GrRecordingContext* context,
GrMTLHandle mtkView,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps)
SK_API_AVAILABLE(macos(10.11), ios(9.0));
#endif
/** Is this surface compatible with the provided characterization?
This method can be used to determine if an existing SkSurface is a viable destination
@ -502,7 +497,6 @@ public:
*/
GrRecordingContext* recordingContext();
#if SK_SUPPORT_GPU
enum BackendHandleAccess {
kFlushRead_BackendHandleAccess, //!< back-end object is readable
kFlushWrite_BackendHandleAccess, //!< back-end object is writable
@ -565,7 +559,6 @@ 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
@ -894,7 +887,6 @@ 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:
@ -929,7 +921,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.
Regardless of semaphore submission the context will still be flushed. It should be
Regardleess 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.
@ -987,9 +979,8 @@ public:
*/
GrSemaphoresSubmitted flush(const GrFlushInfo& info,
const GrBackendSurfaceMutableState* newState = nullptr);
#endif // SK_SUPPORT_GPU
void flush();
void flush() { this->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,6 +8,7 @@
#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"
@ -15,10 +16,6 @@
#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)
@ -54,7 +51,6 @@ GrRecordingContext* SkSurface_Base::onGetRecordingContext() {
return nullptr;
}
#if SK_SUPPORT_GPU
GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) {
return GrBackendTexture(); // invalid
}
@ -69,7 +65,6 @@ 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) {
@ -322,28 +317,6 @@ 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);
}
@ -369,14 +342,26 @@ GrSemaphoresSubmitted SkSurface::flush(const GrFlushInfo& info,
return asSB(this)->onFlush(BackendSurfaceAccess::kNoAccess, info, newState);
}
void SkSurface::flush() {
this->flush({});
bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
bool deleteSemaphoresAfterWait) {
return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
}
#else
void SkSurface::flush() {} // Flush is a no-op for CPU surfaces
void SkSurface::flushAndSubmit(bool syncCpu) {}
#endif
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 });
}
//////////////////////////////////////////////////////////////////////////////////////
#include "include/utils/SkNoDrawCanvas.h"
@ -411,5 +396,38 @@ 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,7 +22,6 @@ public:
virtual GrRecordingContext* onGetRecordingContext();
#if SK_SUPPORT_GPU
virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);
virtual GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess);
virtual bool onReplaceBackendTexture(const GrBackendTexture&,
@ -30,18 +29,6 @@ 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
@ -122,6 +109,16 @@ 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