diff options
-rw-r--r-- | gn/core.gni | 2 | ||||
-rw-r--r-- | include/core/SkDeferredDisplayListRecorder.h | 2 | ||||
-rw-r--r-- | include/core/SkSurfaceCharacterization.h (renamed from include/private/SkSurfaceCharacterization.h) | 44 | ||||
-rw-r--r-- | include/gpu/GrContext.h | 3 | ||||
-rw-r--r-- | tests/DeferredDisplayListTest.cpp | 27 |
5 files changed, 64 insertions, 14 deletions
diff --git a/gn/core.gni b/gn/core.gni index e73227867c..bcec7c02f0 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -430,6 +430,7 @@ skia_core_sources = [ "$_include/core/SkString.h", "$_include/core/SkStrokeRec.h", "$_include/core/SkSurface.h", + "$_include/core/SkSurfaceCharacterization.h", "$_include/core/SkSwizzle.h", "$_include/core/SkTextBlob.h", "$_include/core/SkTime.h", @@ -454,7 +455,6 @@ skia_core_sources = [ "$_include/private/SkSemaphore.h", "$_include/private/SkShadowFlags.h", "$_include/private/SkSpinlock.h", - "$_include/private/SkSurfaceCharacterization.h", "$_include/private/SkTemplates.h", "$_include/private/SkTArray.h", "$_include/private/SkTDArray.h", diff --git a/include/core/SkDeferredDisplayListRecorder.h b/include/core/SkDeferredDisplayListRecorder.h index 1dcbbcbe92..c985e7377d 100644 --- a/include/core/SkDeferredDisplayListRecorder.h +++ b/include/core/SkDeferredDisplayListRecorder.h @@ -9,9 +9,9 @@ #define SkDeferredDisplayListMaker_DEFINED #include "SkRefCnt.h" +#include "SkSurfaceCharacterization.h" #include "../private/SkDeferredDisplayList.h" -#include "../private/SkSurfaceCharacterization.h" class GrContext; diff --git a/include/private/SkSurfaceCharacterization.h b/include/core/SkSurfaceCharacterization.h index 9327a538b6..65e5e23d4b 100644 --- a/include/private/SkSurfaceCharacterization.h +++ b/include/core/SkSurfaceCharacterization.h @@ -54,6 +54,24 @@ public: SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default; SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default; + SkSurfaceCharacterization createResized(int width, int height) const { + const GrCaps* caps = fContextInfo->caps(); + if (!caps) { + return SkSurfaceCharacterization(); + } + + if (width <= 0 || height <= 0 || + width > caps->maxRenderTargetSize() || height > caps->maxRenderTargetSize()) { + return SkSurfaceCharacterization(); + } + + return SkSurfaceCharacterization(fContextInfo, + fCacheMaxResourceBytes, + fOrigin, width, height, fConfig, fFSAAType, fStencilCnt, + fIsTextureable, fIsMipMapped, fColorSpace, + fSurfaceProps); + } + GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); } sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; } size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; } @@ -144,25 +162,27 @@ private: class SkSurfaceCharacterization { public: - SkSurfaceCharacterization() - : fWidth(0) - , fHeight(0) - , fSurfaceProps(0, kUnknown_SkPixelGeometry) { + SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { } + + SkSurfaceCharacterization createResized(int width, int height) const { + return *this; } + size_t cacheMaxResourceBytes() const { return 0; } + bool isValid() const { return false; } - int width() const { return fWidth; } - int height() const { return fHeight; } - SkColorSpace* colorSpace() const { return fColorSpace.get(); } - sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } + int width() const { return 0; } + int height() const { return 0; } + int stencilCount() const { return 0; } + bool isTextureable() const { return false; } + bool isMipMapped() const { return false; } + SkColorSpace* colorSpace() const { return nullptr; } + sk_sp<SkColorSpace> refColorSpace() const { return nullptr; } const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; } private: - int fWidth; - int fHeight; - sk_sp<SkColorSpace> fColorSpace; - SkSurfaceProps fSurfaceProps; + SkSurfaceProps fSurfaceProps; }; #endif diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index bbd43df694..521a3dde7c 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -399,6 +399,9 @@ public: const SkSurfaceProps& surfaceProps, bool isMipMapped); + const GrCaps* caps() const { return fCaps.get(); } + sk_sp<const GrCaps> refCaps() const { return fCaps; } + private: // DDL TODO: need to add unit tests for backend & maybe options GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index 924a93464a..4b425aed7e 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -313,6 +313,33 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) SkSurfaceCharacterization c; REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c)); } + + // Exercise the createResized method + { + SurfaceParameters params; + + sk_sp<SkSurface> s = params.make(context); + if (!s) { + return; + } + + SkSurfaceCharacterization char0; + SkAssertResult(s->characterize(&char0)); + + // Too small + SkSurfaceCharacterization char1 = char0.createResized(-1, -1); + REPORTER_ASSERT(reporter, !char1.isValid()); + + // Too large + SkSurfaceCharacterization char2 = char0.createResized(1000000, 32); + REPORTER_ASSERT(reporter, !char2.isValid()); + + // Just right + SkSurfaceCharacterization char3 = char0.createResized(32, 32); + REPORTER_ASSERT(reporter, char3.isValid()); + REPORTER_ASSERT(reporter, 32 == char3.width()); + REPORTER_ASSERT(reporter, 32 == char3.height()); + } } static constexpr int kSize = 8; |