Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9a97c96

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Revert "Add SkImage::makeColorTypeAndColorSpace"
This reverts commit f855c3c. Reason for revert: DDL and Abandon failures. Original change's description: > Add SkImage::makeColorTypeAndColorSpace > > This works like makeColorSpace, but allows changing color type as well. > Added a GM to test, although the GM demonstrates several ways this can > fail (especially when using this on lazy images). > > For simple use-cases (8888 <-> F16), everything should be fine. > > Bug: skia:8618 > Change-Id: If4c173c0dd4abaf4f8e63b7ae0ffcf8a08c7e9ef > Reviewed-on: https://skia-review.googlesource.com/c/183382 > Reviewed-by: Brian Salomon <[email protected]> > Commit-Queue: Mike Klein <[email protected]> [email protected],[email protected],[email protected] Change-Id: I5d7a72e2b674224351e4b0c982408f89780708f8 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:8618 Reviewed-on: https://skia-review.googlesource.com/c/183392 Reviewed-by: Brian Osman <[email protected]> Commit-Queue: Brian Osman <[email protected]>
1 parent 2ee498c commit 9a97c96

11 files changed

Lines changed: 43 additions & 124 deletions

‎gm/makecolorspace.cpp‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "gm.h"
99
#include "Resources.h"
1010
#include "SkCodec.h"
11-
#include "SkColorSpace.h"
1211
#include "SkImage.h"
1312
#include "SkImagePriv.h"
1413

@@ -83,37 +82,3 @@ class MakeCSGM : public skiagm::GM {
8382
};
8483

8584
DEF_GM(return new MakeCSGM;)
86-
87-
DEF_SIMPLE_GM_BG(makecolortypeandspace, canvas, 128 * 3, 128 * 4, SK_ColorWHITE) {
88-
sk_sp<SkImage> images[] = {
89-
GetResourceAsImage("images/mandrill_128.png"),
90-
GetResourceAsImage("images/color_wheel.png"),
91-
};
92-
auto rec2020 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kRec2020);
93-
94-
// Use the lazy images on the first iteration, and concrete (raster/GPU) images on the second
95-
for (int i = 0; i < 2; ++i) {
96-
for (int j = 0; j < 2; ++j) {
97-
// Unmodified
98-
canvas->drawImage(images[j], 0, 0);
99-
100-
// 565 in a wide color space (should be visibly quantized).
101-
// With the lazy color_wheel image, this fails to draw, because we refuse to decode
102-
// transparent sources to opaque color types. Sigh.
103-
canvas->drawImage(images[j]->makeColorTypeAndColorSpace(kRGB_565_SkColorType, rec2020),
104-
128, 0);
105-
106-
// Grayscale in the original color space. This fails in even more cases, due to the
107-
// above opaque issue, and because Ganesh doesn't support drawing to gray, at all.
108-
canvas->drawImage(images[j]->makeColorTypeAndColorSpace(kGray_8_SkColorType,
109-
images[j]->refColorSpace()),
110-
256, 0);
111-
112-
images[j] = canvas->getGrContext()
113-
? images[j]->makeTextureImage(canvas->getGrContext(), nullptr)
114-
: images[j]->makeRasterImage();
115-
116-
canvas->translate(0, 128);
117-
}
118-
}
119-
}

‎include/core/SkImage.h‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,18 +1020,6 @@ class SK_API SkImage : public SkRefCnt {
10201020
*/
10211021
sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const;
10221022

1023-
/** Creates SkImage in target SkColorType and SkColorSpace.
1024-
Returns nullptr if SkImage could not be created.
1025-
1026-
Returns original SkImage if it is in target SkColorType and SkColorSpace.
1027-
1028-
@param targetColorType SkColorType of returned SkImage
1029-
@param targetColorSpace SkColorSpace of returned SkImage
1030-
@return created SkImage in target SkColorType and SkColorSpace
1031-
*/
1032-
sk_sp<SkImage> makeColorTypeAndColorSpace(SkColorType targetColorType,
1033-
sk_sp<SkColorSpace> targetColorSpace) const;
1034-
10351023
private:
10361024
SkImage(int width, int height, uint32_t uniqueID);
10371025
friend class SkImage_Base;

‎src/image/SkImage.cpp‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,30 +313,12 @@ sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target) const {
313313
if (!colorSpace) {
314314
colorSpace = sk_srgb_singleton();
315315
}
316-
if (SkColorSpace::Equals(colorSpace, target.get()) || this->isAlphaOnly()) {
316+
if (SkColorSpace::Equals(colorSpace, target.get()) ||
317+
kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) {
317318
return sk_ref_sp(const_cast<SkImage*>(this));
318319
}
319320

320-
return as_IB(this)->onMakeColorTypeAndColorSpace(this->colorType(), std::move(target));
321-
}
322-
323-
sk_sp<SkImage> SkImage::makeColorTypeAndColorSpace(SkColorType targetColorType,
324-
sk_sp<SkColorSpace> targetColorSpace) const {
325-
if (kUnknown_SkColorType == targetColorType || !targetColorSpace) {
326-
return nullptr;
327-
}
328-
329-
SkColorType colorType = this->colorType();
330-
SkColorSpace* colorSpace = this->colorSpace();
331-
if (!colorSpace) {
332-
colorSpace = sk_srgb_singleton();
333-
}
334-
if (colorType == targetColorType &&
335-
(SkColorSpace::Equals(colorSpace, targetColorSpace.get()) || this->isAlphaOnly())) {
336-
return sk_ref_sp(const_cast<SkImage*>(this));
337-
}
338-
339-
return as_IB(this)->onMakeColorTypeAndColorSpace(targetColorType, std::move(targetColorSpace));
321+
return as_IB(this)->onMakeColorSpace(std::move(target));
340322
}
341323

342324
sk_sp<SkImage> SkImage::makeNonTextureImage() const {

‎src/image/SkImage_Base.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class SkImage_Base : public SkImage {
9696
virtual bool onPinAsTexture(GrContext*) const { return false; }
9797
virtual void onUnpinAsTexture(GrContext*) const {}
9898

99-
virtual sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>) const = 0;
99+
virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const = 0;
100100
protected:
101101
SkImage_Base(int width, int height, uint32_t uniqueID);
102102

‎src/image/SkImage_Gpu.cpp‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ SkImageInfo SkImage_Gpu::onImageInfo() const {
6060
return SkImageInfo::Make(fProxy->width(), fProxy->height(), colorType, fAlphaType, fColorSpace);
6161
}
6262

63-
sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT,
64-
sk_sp<SkColorSpace> targetCS) const {
63+
sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
6564
auto xform = GrColorSpaceXformEffect::Make(fColorSpace.get(), fAlphaType,
66-
targetCS.get(), fAlphaType);
67-
SkASSERT(xform || targetCT != this->colorType());
65+
target.get(), fAlphaType);
66+
SkASSERT(xform);
6867

6968
sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef();
7069

@@ -76,17 +75,15 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT,
7675
sk_sp<GrRenderTargetContext> renderTargetContext(
7776
fContext->contextPriv().makeDeferredRenderTargetContextWithFallback(
7877
format, SkBackingFit::kExact, this->width(), this->height(),
79-
SkColorType2GrPixelConfig(targetCT), nullptr));
78+
proxy->config(), nullptr));
8079
if (!renderTargetContext) {
8180
return nullptr;
8281
}
8382

8483
GrPaint paint;
8584
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
8685
paint.addColorTextureProcessor(std::move(proxy), SkMatrix::I());
87-
if (xform) {
88-
paint.addColorFragmentProcessor(std::move(xform));
89-
}
86+
paint.addColorFragmentProcessor(std::move(xform));
9087

9188
renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
9289
SkRect::MakeIWH(this->width(), this->height()));
@@ -96,7 +93,7 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT,
9693

9794
// MDB: this call is okay bc we know 'renderTargetContext' was exact
9895
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, fAlphaType,
99-
renderTargetContext->asTextureProxyRef(), std::move(targetCS));
96+
renderTargetContext->asTextureProxyRef(), std::move(target));
10097
}
10198

10299
///////////////////////////////////////////////////////////////////////////////////////////////////

‎src/image/SkImage_Gpu.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SkImage_Gpu : public SkImage_GpuBase {
3737

3838
virtual bool onIsTextureBacked() const override { return SkToBool(fProxy.get()); }
3939

40-
sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>) const final;
40+
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const final;
4141

4242
/**
4343
Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. The main

‎src/image/SkImage_GpuYUVA.cpp‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,15 @@ sk_sp<GrTextureProxy> SkImage_GpuYUVA::asMippedTextureProxyRef() const {
143143

144144
//////////////////////////////////////////////////////////////////////////////////////////////////
145145

146-
sk_sp<SkImage> SkImage_GpuYUVA::onMakeColorTypeAndColorSpace(SkColorType,
147-
sk_sp<SkColorSpace> targetCS) const {
148-
// We explicitly ignore color type changes, for now.
149-
146+
sk_sp<SkImage> SkImage_GpuYUVA::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
150147
// we may need a mutex here but for now we expect usage to be in a single thread
151148
if (fOnMakeColorSpaceTarget &&
152-
SkColorSpace::Equals(targetCS.get(), fOnMakeColorSpaceTarget.get())) {
149+
SkColorSpace::Equals(target.get(), fOnMakeColorSpaceTarget.get())) {
153150
return fOnMakeColorSpaceResult;
154151
}
155-
sk_sp<SkImage> result = sk_sp<SkImage>(new SkImage_GpuYUVA(this, targetCS));
152+
sk_sp<SkImage> result = sk_sp<SkImage>(new SkImage_GpuYUVA(this, target));
156153
if (result) {
157-
fOnMakeColorSpaceTarget = targetCS;
154+
fOnMakeColorSpaceTarget = target;
158155
fOnMakeColorSpaceResult = result;
159156
}
160157
return result;

‎src/image/SkImage_GpuYUVA.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SkImage_GpuYUVA : public SkImage_GpuBase {
3636

3737
virtual bool onIsTextureBacked() const override { return SkToBool(fProxies[0].get()); }
3838

39-
sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>) const final;
39+
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const final;
4040

4141
virtual bool isYUVA() const override { return true; }
4242
virtual bool asYUVATextureProxiesRef(sk_sp<GrTextureProxy> proxies[4],

‎src/image/SkImage_Lazy.cpp‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SharedGenerator final : public SkNVRefCnt<SharedGenerator> {
5353
///////////////////////////////////////////////////////////////////////////////
5454

5555
SkImage_Lazy::Validator::Validator(sk_sp<SharedGenerator> gen, const SkIRect* subset,
56-
const SkColorType* colorType, sk_sp<SkColorSpace> colorSpace)
56+
sk_sp<SkColorSpace> colorSpace)
5757
: fSharedGenerator(std::move(gen)) {
5858
if (!fSharedGenerator) {
5959
return;
@@ -84,13 +84,8 @@ SkImage_Lazy::Validator::Validator(sk_sp<SharedGenerator> gen, const SkIRect* su
8484

8585
fInfo = info.makeWH(subset->width(), subset->height());
8686
fOrigin = SkIPoint::Make(subset->x(), subset->y());
87-
if (colorType || colorSpace) {
88-
if (colorType) {
89-
fInfo = fInfo.makeColorType(*colorType);
90-
}
91-
if (colorSpace) {
92-
fInfo = fInfo.makeColorSpace(colorSpace);
93-
}
87+
if (colorSpace) {
88+
fInfo = fInfo.makeColorSpace(colorSpace);
9489
fUniqueID = SkNextID::ImageID();
9590
}
9691
}
@@ -254,33 +249,30 @@ sk_sp<SkImage> SkImage_Lazy::onMakeSubset(const SkIRect& subset) const {
254249
SkASSERT(fInfo.bounds() != subset);
255250

256251
const SkIRect generatorSubset = subset.makeOffset(fOrigin.x(), fOrigin.y());
257-
const SkColorType colorType = fInfo.colorType();
258-
Validator validator(fSharedGenerator, &generatorSubset, &colorType, fInfo.refColorSpace());
252+
Validator validator(fSharedGenerator, &generatorSubset, fInfo.refColorSpace());
259253
return validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr;
260254
}
261255

262-
sk_sp<SkImage> SkImage_Lazy::onMakeColorTypeAndColorSpace(SkColorType targetCT,
263-
sk_sp<SkColorSpace> targetCS) const {
264-
SkAutoExclusive autoAquire(fOnMakeColorTypeAndSpaceMutex);
265-
if (fOnMakeColorTypeAndSpaceResult &&
266-
targetCT == fOnMakeColorTypeAndSpaceResult->colorType() &&
267-
SkColorSpace::Equals(targetCS.get(), fOnMakeColorTypeAndSpaceResult->colorSpace())) {
268-
return fOnMakeColorTypeAndSpaceResult;
256+
sk_sp<SkImage> SkImage_Lazy::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
257+
SkAutoExclusive autoAquire(fOnMakeColorSpaceMutex);
258+
if (fOnMakeColorSpaceTarget &&
259+
SkColorSpace::Equals(target.get(), fOnMakeColorSpaceTarget.get())) {
260+
return fOnMakeColorSpaceResult;
269261
}
270262
const SkIRect generatorSubset =
271263
SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
272-
Validator validator(fSharedGenerator, &generatorSubset, &targetCT, targetCS);
264+
Validator validator(fSharedGenerator, &generatorSubset, target);
273265
sk_sp<SkImage> result = validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr;
274266
if (result) {
275-
fOnMakeColorTypeAndSpaceResult = result;
267+
fOnMakeColorSpaceTarget = target;
268+
fOnMakeColorSpaceResult = result;
276269
}
277270
return result;
278271
}
279272

280273
sk_sp<SkImage> SkImage::MakeFromGenerator(std::unique_ptr<SkImageGenerator> generator,
281274
const SkIRect* subset) {
282-
SkImage_Lazy::Validator
283-
validator(SharedGenerator::Make(std::move(generator)), subset, nullptr, nullptr);
275+
SkImage_Lazy::Validator validator(SharedGenerator::Make(std::move(generator)), subset, nullptr);
284276

285277
return validator ? sk_make_sp<SkImage_Lazy>(&validator) : nullptr;
286278
}
@@ -435,10 +427,9 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(
435427
ScopedGenerator generator(fSharedGenerator);
436428
Generator_GrYUVProvider provider(generator);
437429

438-
// The pixels in the texture will be in the generator's color space.
439-
// If onMakeColorTypeAndColorSpace has been called then this will not match this image's
440-
// color space. To correct this, apply a color space conversion from the generator's color
441-
// space to this image's color space.
430+
// The pixels in the texture will be in the generator's color space. If onMakeColorSpace
431+
// has been called then this will not match this image's color space. To correct this, apply
432+
// a color space conversion from the generator's color space to this image's color space.
442433
SkColorSpace* generatorColorSpace = fSharedGenerator->fGenerator->getInfo().colorSpace();
443434
SkColorSpace* thisColorSpace = fInfo.colorSpace();
444435

‎src/image/SkImage_Lazy.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class SharedGenerator;
2020
class SkImage_Lazy : public SkImage_Base {
2121
public:
2222
struct Validator {
23-
Validator(sk_sp<SharedGenerator>, const SkIRect* subset, const SkColorType* colorType,
24-
sk_sp<SkColorSpace> colorSpace);
23+
Validator(sk_sp<SharedGenerator>, const SkIRect* subset, sk_sp<SkColorSpace> colorSpace);
2524

2625
operator bool() const { return fSharedGenerator.get(); }
2726

@@ -56,7 +55,7 @@ class SkImage_Lazy : public SkImage_Base {
5655
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
5756
bool getROPixels(SkBitmap*, CachingHint) const override;
5857
bool onIsLazyGenerated() const override { return true; }
59-
sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>) const override;
58+
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const override;
6059

6160
bool onIsValid(GrContext*) const override;
6261

@@ -78,16 +77,17 @@ class SkImage_Lazy : public SkImage_Base {
7877

7978
sk_sp<SharedGenerator> fSharedGenerator;
8079
// Note that fInfo is not necessarily the info from the generator. It may be cropped by
81-
// onMakeSubset and its color type/space may be changed by onMakeColorTypeAndColorSpace.
80+
// onMakeSubset and its color space may be changed by onMakeColorSpace.
8281
const SkImageInfo fInfo;
8382
const SkIPoint fOrigin;
8483

8584
uint32_t fUniqueID;
8685

87-
// Repeated calls to onMakeColorTypeAndColorSpace will result in a proliferation of unique IDs
88-
// and SkImage_Lazy instances. Cache the result of the last successful call.
89-
mutable SkMutex fOnMakeColorTypeAndSpaceMutex;
90-
mutable sk_sp<SkImage> fOnMakeColorTypeAndSpaceResult;
86+
// Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
87+
// SkImage_Lazy instances. Cache the result of the last successful onMakeColorSpace call.
88+
mutable SkMutex fOnMakeColorSpaceMutex;
89+
mutable sk_sp<SkColorSpace> fOnMakeColorSpaceTarget;
90+
mutable sk_sp<SkImage> fOnMakeColorSpaceResult;
9191

9292
#if SK_SUPPORT_GPU
9393
// When the SkImage_Lazy goes away, we will iterate over all the unique keys we've used and

0 commit comments

Comments
 (0)