Make SkColorSpaceXform::New() take bare ptrs
There's no need to take sk_sp if we're not going to
ref the ptr.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2360863003
Review-Url: https://codereview.chromium.org/2360863003
diff --git a/bench/ColorCodecBench.cpp b/bench/ColorCodecBench.cpp
index faa2a9a..84d4f92 100644
--- a/bench/ColorCodecBench.cpp
+++ b/bench/ColorCodecBench.cpp
@@ -94,7 +94,8 @@
if (!srcSpace) {
srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
}
- std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, fDstSpace);
+ std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace.get(),
+ fDstSpace.get());
SkASSERT(xform);
void* dst = fDst.get();
diff --git a/gm/colorspacexform.cpp b/gm/colorspacexform.cpp
index b3d79c9..e1afb1c 100644
--- a/gm/colorspacexform.cpp
+++ b/gm/colorspacexform.cpp
@@ -37,9 +37,12 @@
SkMatrix44 wideGamut(SkMatrix44::kUninitialized_Constructor);
wideGamut.set3x3RowMajorf(kWideGamutRGB_toXYZD50);
- std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(
- SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named),
- SkColorSpace::NewRGB(SkColorSpace::kLinear_RenderTargetGamma, wideGamut));
+
+ sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+ sk_sp<SkColorSpace> dstSpace =
+ SkColorSpace::NewRGB(SkColorSpace::kLinear_RenderTargetGamma, wideGamut);
+ std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace.get(),
+ dstSpace.get());
xform->apply(fWideGamutColors, colors, kNumColors,
SkColorSpaceXform::kRGBA_F32_ColorFormat, kOpaque_SkAlphaType);
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index c865fbc..ac57799 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -633,8 +633,7 @@
void SkJpegCodec::initializeColorXform(const SkImageInfo& dstInfo) {
if (needs_color_xform(dstInfo, this->getInfo())) {
- fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
- sk_ref_sp(dstInfo.colorSpace()));
+ fColorXform = SkColorSpaceXform::New(this->getInfo().colorSpace(), dstInfo.colorSpace());
SkASSERT(fColorXform);
}
}
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 1e633ea..3fdb858 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -1111,8 +1111,7 @@
fColorXform = nullptr;
if (needs_color_xform(dstInfo, this->getInfo())) {
- fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
- sk_ref_sp(dstInfo.colorSpace()));
+ fColorXform = SkColorSpaceXform::New(this->getInfo().colorSpace(), dstInfo.colorSpace());
SkASSERT(fColorXform);
}
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 86bda57..e25a57f 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -199,8 +199,7 @@
std::unique_ptr<SkColorSpaceXform> colorXform = nullptr;
if (needs_color_xform(dstInfo, this->getInfo())) {
- colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
- sk_ref_sp(dstInfo.colorSpace()));
+ colorXform = SkColorSpaceXform::New(this->getInfo().colorSpace(), dstInfo.colorSpace());
SkASSERT(colorXform);
}
diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp
index b1dda34..f1c7511 100644
--- a/src/core/SkColorSpaceXform.cpp
+++ b/src/core/SkColorSpaceXform.cpp
@@ -256,8 +256,8 @@
// Build tables to transform src gamma to linear.
template <typename T>
static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage, int gammaTableSize,
- const sk_sp<SkColorSpace>& space, const GammaFns<T>& fns,
- bool gammasAreMatching) {
+ SkColorSpace* space, const GammaFns<T>& fns, bool gammasAreMatching)
+{
switch (as_CSB(space)->gammaNamed()) {
case kSRGB_SkGammaNamed:
outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = fns.fSRGBTable;
@@ -342,8 +342,8 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
-std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpace>& srcSpace,
- const sk_sp<SkColorSpace>& dstSpace) {
+std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace,
+ SkColorSpace* dstSpace) {
if (!srcSpace || !dstSpace) {
// Invalid input
return nullptr;
@@ -351,7 +351,7 @@
ColorSpaceMatch csm = kNone_ColorSpaceMatch;
SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
- if (SkColorSpace::Equals(srcSpace.get(), dstSpace.get())) {
+ if (SkColorSpace::Equals(srcSpace, dstSpace)) {
srcToDst.setIdentity();
csm = kFull_ColorSpaceMatch;
} else {
@@ -1210,14 +1210,13 @@
template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM>
SkColorSpaceXform_Base<kSrc, kDst, kCSM>
-::SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44& srcToDst,
- const sk_sp<SkColorSpace>& dstSpace)
+::SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, SkColorSpace* dstSpace)
: fColorLUT(sk_ref_sp((SkColorLookUpTable*) as_CSB(srcSpace)->colorLUT()))
{
srcToDst.asColMajorf(fSrcToDst);
- const int numSrcTables = num_tables(srcSpace.get());
- const int numDstTables = num_tables(dstSpace.get());
+ const int numSrcTables = num_tables(srcSpace);
+ const int numDstTables = num_tables(dstSpace);
const size_t srcTableBytes = numSrcTables * 256 * sizeof(float);
const size_t dstTableBytes = numDstTables * kDstGammaTableSize * sizeof(uint8_t);
fStorage.reset(srcTableBytes + dstTableBytes);
@@ -1365,7 +1364,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
-std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space) {
+std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space) {
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch>
(space, SkMatrix::I(), space));
diff --git a/src/core/SkColorSpaceXform.h b/src/core/SkColorSpaceXform.h
index 6c996a9..307cc70 100644
--- a/src/core/SkColorSpaceXform.h
+++ b/src/core/SkColorSpaceXform.h
@@ -22,8 +22,7 @@
* @param dstSpace The destination color space.
*
*/
- static std::unique_ptr<SkColorSpaceXform> New(const sk_sp<SkColorSpace>& srcSpace,
- const sk_sp<SkColorSpace>& dstSpace);
+ static std::unique_ptr<SkColorSpaceXform> New(SkColorSpace* srcSpace, SkColorSpace* dstSpace);
enum ColorFormat : uint8_t {
kRGBA_8888_ColorFormat,
@@ -79,8 +78,8 @@
static constexpr int kDstGammaTableSize = 1024;
private:
- SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44& srcToDst,
- const sk_sp<SkColorSpace>& dstSpace);
+ SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst,
+ SkColorSpace* dstSpace);
sk_sp<SkColorLookUpTable> fColorLUT;
@@ -92,10 +91,10 @@
float fSrcToDst[16];
friend class SkColorSpaceXform;
- friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space);
+ friend std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space);
};
// For testing. Bypasses opts for when src and dst color spaces are equal.
-std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space);
+std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space);
#endif
diff --git a/tests/ColorSpaceXformTest.cpp b/tests/ColorSpaceXformTest.cpp
index 2401af5..156b2da 100644
--- a/tests/ColorSpaceXformTest.cpp
+++ b/tests/ColorSpaceXformTest.cpp
@@ -22,7 +22,7 @@
nullptr, kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr));
// Use special testing entry point, so we don't skip the xform, even though src == dst.
- return SlowIdentityXform(space);
+ return SlowIdentityXform(space.get());
}
};