Skip to content

Commit

Permalink
Expose SkSurface::isCompatible
Browse files Browse the repository at this point in the history
This is part of bridging the explicit backend surface API and making SkSurfaces

This is pulled out of:

https://skia-review.googlesource.com/c/skia/+/222781/ (Add bridge between GrContext::createBackendTexture and SkSurface::MakeFromBackendTexture)

Change-Id: Ib55bcd8a0d1a049f230314a8f8ba7a3951b06d5c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223707
Reviewed-by: Greg Daniel <[email protected]>
Reviewed-by: Brian Salomon <[email protected]>
Commit-Queue: Robert Phillips <[email protected]>
  • Loading branch information
rphilli authored and Skia Commit-Bot committed Jun 25, 2019
1 parent a4eecd8 commit 9907e6e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
11 changes: 11 additions & 0 deletions include/core/SkSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,17 @@ class SK_API SkSurface : public SkRefCnt {
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
for an SkDeferredDisplayList.
@param characterization The characterization for which a compatibility check is desired
@return true if this surface is compatible with the characterization;
false otherwise
*/
bool isCompatible(const SkSurfaceCharacterization& characterization) const;

/** Returns SkSurface without backing pixels. Drawing to SkCanvas returned from SkSurface
has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr.
Expand Down
10 changes: 9 additions & 1 deletion src/image/SkSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ static SkSurface_Base* asSB(SkSurface* surface) {
return static_cast<SkSurface_Base*>(surface);
}

static const SkSurface_Base* asConstSB(const SkSurface* surface) {
return static_cast<const SkSurface_Base*>(surface);
}

///////////////////////////////////////////////////////////////////////////////

SkSurface::SkSurface(int width, int height, const SkSurfaceProps* props)
Expand Down Expand Up @@ -453,7 +457,11 @@ bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores
}

bool SkSurface::characterize(SkSurfaceCharacterization* characterization) const {
return asSB(const_cast<SkSurface*>(this))->onCharacterize(characterization);
return asConstSB(this)->onCharacterize(characterization);
}

bool SkSurface::isCompatible(const SkSurfaceCharacterization& characterization) const {
return asConstSB(this)->onIsCompatible(characterization);
}

bool SkSurface::draw(SkDeferredDisplayList* ddl) {
Expand Down
1 change: 1 addition & 0 deletions src/image/SkSurface_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class SkSurface_Base : public SkSurface {
}

virtual bool onCharacterize(SkSurfaceCharacterization*) const { return false; }
virtual bool onIsCompatible(const SkSurfaceCharacterization&) const { return false; }
virtual bool onDraw(const SkDeferredDisplayList*) { return false; }

inline SkCanvas* getCachedCanvas();
Expand Down
12 changes: 5 additions & 7 deletions src/image/SkSurface_Gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai
}
}

bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& characterization) const {
bool SkSurface_Gpu::onIsCompatible(const SkSurfaceCharacterization& characterization) const {
GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
GrContext* ctx = fDevice->context();

Expand Down Expand Up @@ -395,18 +395,16 @@ sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext* context,
return nullptr;
}

sk_sp<SkSurface> s = sk_make_sp<SkSurface_Gpu>(std::move(device));
sk_sp<SkSurface> result = sk_make_sp<SkSurface_Gpu>(std::move(device));
#ifdef SK_DEBUG
if (s) {
SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
SkASSERT(gpuSurface->isCompatible(c));
if (result) {
SkASSERT(result->isCompatible(c));
}
#endif

return s;
return result;
}


sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted,
const SkImageInfo& info, int sampleCount,
GrSurfaceOrigin origin, const SkSurfaceProps* props,
Expand Down
2 changes: 1 addition & 1 deletion src/image/SkSurface_Gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class SkSurface_Gpu : public SkSurface_Base {
GrSemaphoresSubmitted onFlush(BackendSurfaceAccess access, const GrFlushInfo& info) override;
bool onWait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) override;
bool onCharacterize(SkSurfaceCharacterization*) const override;
bool onIsCompatible(const SkSurfaceCharacterization&) const override;
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) override;
bool isCompatible(const SkSurfaceCharacterization&) const;
bool onDraw(const SkDeferredDisplayList*) override;

SkGpuDevice* getDevice() { return fDevice.get(); }
Expand Down
4 changes: 4 additions & 0 deletions tests/DeferredDisplayListTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class SurfaceParameters {
fOrigin, fColorType,
fColorSpace,
&fSurfaceProps);
SkASSERT(result->isCompatible(c));
return result;
}

Expand Down Expand Up @@ -215,6 +216,7 @@ class SurfaceParameters {
return nullptr;
}

SkASSERT(surface->isCompatible(c));
return surface;
}

Expand Down Expand Up @@ -541,13 +543,15 @@ static void test_make_render_target(skiatest::Reporter* reporter,
}

REPORTER_ASSERT(reporter, c.isValid());
REPORTER_ASSERT(reporter, s->isCompatible(c));
// Note that we're leaving 'backend' live here
}

// Make an SkSurface from scratch
{
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
REPORTER_ASSERT(reporter, s);
REPORTER_ASSERT(reporter, s->isCompatible(c));
}

params.cleanUpBackEnd(context, backend);
Expand Down

0 comments on commit 9907e6e

Please sign in to comment.