aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-04-04 11:12:39 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-04 15:41:48 +0000
commitc1267c60516cab68e8c7780280256ca8e8e53ab2 (patch)
treebc6f4c12482ca0c5102cdd6f7d1a79af25956c00
parentdc09213b17cfd100e1c1859387b47e3045a36010 (diff)
Add SkSurfaceCharacterization operator== && !=
TBR=bsalomon@google.com Change-Id: Ic58849dcb3be1f00431f897af328f6f3c3f00d75 Reviewed-on: https://skia-review.googlesource.com/118340 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--gn/core.gni1
-rw-r--r--include/core/SkSurfaceCharacterization.h9
-rw-r--r--include/gpu/GrContext.h1
-rw-r--r--src/core/SkSurfaceCharacterization.cpp31
-rw-r--r--tests/DeferredDisplayListTest.cpp54
5 files changed, 95 insertions, 1 deletions
diff --git a/gn/core.gni b/gn/core.gni
index d0041d5835..6f019f3f4d 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -302,6 +302,7 @@ skia_core_sources = [
"$_src/core/SkStrokeRec.cpp",
"$_src/core/SkStrokerPriv.cpp",
"$_src/core/SkStrokerPriv.h",
+ "$_src/core/SkSurfaceCharacterization.cpp",
"$_src/core/SkSurfacePriv.h",
"$_src/core/SkSwizzle.cpp",
"$_src/core/SkSRGB.cpp",
diff --git a/include/core/SkSurfaceCharacterization.h b/include/core/SkSurfaceCharacterization.h
index 7070d21fd4..90c7935d99 100644
--- a/include/core/SkSurfaceCharacterization.h
+++ b/include/core/SkSurfaceCharacterization.h
@@ -47,6 +47,10 @@ public:
SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
+ bool operator==(const SkSurfaceCharacterization& other) const;
+ bool operator!=(const SkSurfaceCharacterization& other) const {
+ return !(*this == other);
+ }
SkSurfaceCharacterization createResized(int width, int height) const {
const GrCaps* caps = fContextInfo->caps();
@@ -162,6 +166,11 @@ public:
return *this;
}
+ bool operator==(const SkSurfaceCharacterization& other) const { return false; }
+ bool operator!=(const SkSurfaceCharacterization& other) const {
+ return !(*this == other);
+ }
+
size_t cacheMaxResourceBytes() const { return 0; }
bool isValid() const { return false; }
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index cc9346c269..2e5225bd3f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -409,6 +409,7 @@ private:
friend class GrDirectContext; // To construct this object
friend class GrContextPriv; // for access to 'fOptions' in MakeDDL
friend class GrDDLContext; // to implement the GrDDLContext ctor (access to all members)
+ friend class SkSurfaceCharacterization; // for access to 'fContextUniqueID' for operator==
typedef SkRefCnt INHERITED;
};
diff --git a/src/core/SkSurfaceCharacterization.cpp b/src/core/SkSurfaceCharacterization.cpp
new file mode 100644
index 0000000000..b82f2a681f
--- /dev/null
+++ b/src/core/SkSurfaceCharacterization.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkSurfaceCharacterization.h"
+
+#if SK_SUPPORT_GPU
+bool SkSurfaceCharacterization::operator==(const SkSurfaceCharacterization& other) const {
+ if (!this->isValid() || !other.isValid()) {
+ return false;
+ }
+
+ if (fContextInfo->fContextUniqueID != other.fContextInfo->fContextUniqueID) {
+ return false;
+ }
+
+ return fCacheMaxResourceBytes == other.fCacheMaxResourceBytes &&
+ fOrigin == other.fOrigin &&
+ fImageInfo == other.fImageInfo &&
+ fConfig == other.fConfig &&
+ fFSAAType == other.fFSAAType &&
+ fStencilCnt == other.fStencilCnt &&
+ fIsTextureable == other.fIsTextureable &&
+ fIsMipMapped == other.fIsMipMapped &&
+ fSurfaceProps == other.fSurfaceProps;
+}
+
+#endif
diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp
index 5960aa2b42..8c361560b7 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -14,6 +14,7 @@
#include "GrTextureProxyPriv.h"
#include "SkCanvas.h"
+#include "SkColorSpacePriv.h"
#include "SkDeferredDisplayListRecorder.h"
#include "SkGpuDevice.h"
#include "SkImage_Gpu.h"
@@ -295,12 +296,17 @@ public:
fOrigin = kBottomLeft_GrSurfaceOrigin;
break;
case 3:
+ // The color type and config need to be changed together.
+ // The original SRGB color space no longer makes sense for F16
fColorType = kRGBA_F16_SkColorType;
fConfig = kRGBA_half_GrPixelConfig;
fColorSpace = SkColorSpace::MakeSRGBLinear();
break;
case 4:
- fColorSpace = SkColorSpace::MakeSRGBLinear();
+ // This just needs to be a colorSpace different from that returned by MakeSRGB()
+ // but still be considered SRGB. In this case we just change the gamut.
+ fColorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
+ SkColorSpace::kAdobeRGB_Gamut);
break;
case kSampleCount:
fSampleCount = 4;
@@ -407,6 +413,52 @@ private:
bool fShouldCreateMipMaps;
};
+// Test out operator== && operator!=
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
+ GrContext* context = ctxInfo.grContext();
+
+ for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
+ SurfaceParameters params1(context->caps());
+ params1.modify(i);
+
+ SkSurfaceCharacterization char1 = params1.createCharacterization(context);
+ if (!char1.isValid()) {
+ continue; // can happen on some platforms (ChromeOS)
+ }
+
+ for (int j = 0; j < SurfaceParameters::kNumParams; ++j) {
+ SurfaceParameters params2(context->caps());
+ params2.modify(j);
+
+ SkSurfaceCharacterization char2 = params2.createCharacterization(context);
+ if (!char2.isValid()) {
+ continue; // can happen on some platforms (ChromeOS)
+ }
+
+ if (i == j) {
+ REPORTER_ASSERT(reporter, char1 == char2);
+ } else {
+ REPORTER_ASSERT(reporter, char1 != char2);
+ }
+
+ }
+ }
+
+ {
+ SurfaceParameters params(context->caps());
+
+ SkSurfaceCharacterization valid = params.createCharacterization(context);
+ SkASSERT(valid.isValid());
+
+ SkSurfaceCharacterization inval1, inval2;
+ SkASSERT(!inval1.isValid() && !inval2.isValid());
+
+ REPORTER_ASSERT(reporter, inval1 != inval2);
+ REPORTER_ASSERT(reporter, valid != inval1);
+ REPORTER_ASSERT(reporter, inval1 != valid);
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// This tests SkSurfaceCharacterization/SkSurface compatibility
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {