Add SkSurfaceCharacterization::createResized
Change-Id: Ia98ce3cf6c0b9f9100eea9850af56048e43b8d07 Reviewed-on: https://skia-review.googlesource.com/112580 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
e041e31926
commit
94458ee0f2
@ -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",
|
||||
|
@ -9,9 +9,9 @@
|
||||
#define SkDeferredDisplayListMaker_DEFINED
|
||||
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkSurfaceCharacterization.h"
|
||||
|
||||
#include "../private/SkDeferredDisplayList.h"
|
||||
#include "../private/SkSurfaceCharacterization.h"
|
||||
|
||||
class GrContext;
|
||||
|
||||
|
@ -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
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user