Revert of Lots of progress switching to SkColorSpace rather than SkColorProfileType (patchset #10 id:180001 of https://codereview.chromium.org/2069173002/ )

Reason for revert:
Mac crashes in GrUploadPixmapToTexture

Original issue's description:
> Lots of progress on switching to SkColorSpace rather than SkColorProfileType
>
> Fixed a bunch of code in Ganesh, as well as usage of SkColorProfileType in most of our tools (DM, SampleApp, Viewer, nanobench, skiaserve, HelloWorld).
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2069173002
>
> Committed: https://skia.googlesource.com/skia/+/6a61a875467646f8dbc37cfecf49e12d1f475170

TBR=reed@google.com,herb@google.com,msarett@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review-Url: https://codereview.chromium.org/2072813002
This commit is contained in:
brianosman 2016-06-16 11:41:44 -07:00 committed by Commit bot
parent 6a61a87546
commit ab8241880d
34 changed files with 130 additions and 137 deletions

View File

@ -37,7 +37,7 @@ protected:
return; return;
} }
SkImageInfo info = SkImageInfo::Make(fW, fH, kN32_SkColorType, kPremul_SkAlphaType, SkImageInfo info = SkImageInfo::Make(fW, fH, kN32_SkColorType, kPremul_SkAlphaType,
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); kSRGB_SkColorProfileType);
fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
} }

View File

@ -424,7 +424,7 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
Benchmark::kGPU_Backend, Benchmark::kGPU_Backend,
kN32_SkColorType, kN32_SkColorType,
kPremul_SkAlphaType, kPremul_SkAlphaType,
nullptr, kLinear_SkColorProfileType,
sampleCount, sampleCount,
ctxType, ctxType,
ctxOptions, ctxOptions,
@ -436,29 +436,28 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
} }
#endif #endif
#define CPU_CONFIG(name, backend, color, alpha, colorSpace) \ #define CPU_CONFIG(name, backend, color, alpha, profile) \
if (config->getTag().equals(#name)) { \ if (config->getTag().equals(#name)) { \
Config config = { \ Config config = { \
SkString(#name), Benchmark::backend, color, alpha, colorSpace, \ SkString(#name), Benchmark::backend, color, alpha, profile, \
0, kBogusContextType, kBogusContextOptions, false \ 0, kBogusContextType, kBogusContextOptions, false \
}; \ }; \
configs->push_back(config); \ configs->push_back(config); \
return; \ return; \
} }
if (FLAGS_cpu) { if (FLAGS_cpu) {
CPU_CONFIG(nonrendering, kNonRendering_Backend, CPU_CONFIG(nonrendering, kNonRendering_Backend,
kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr) kUnknown_SkColorType, kUnpremul_SkAlphaType, kLinear_SkColorProfileType);
CPU_CONFIG(8888, kRaster_Backend, CPU_CONFIG(8888, kRaster_Backend,
kN32_SkColorType, kPremul_SkAlphaType, nullptr) kN32_SkColorType, kPremul_SkAlphaType, kLinear_SkColorProfileType)
CPU_CONFIG(565, kRaster_Backend, CPU_CONFIG(565, kRaster_Backend,
kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr) kRGB_565_SkColorType, kOpaque_SkAlphaType, kLinear_SkColorProfileType)
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
CPU_CONFIG(srgb, kRaster_Backend, CPU_CONFIG(srgb, kRaster_Backend,
kN32_SkColorType, kPremul_SkAlphaType, srgbColorSpace) kN32_SkColorType, kPremul_SkAlphaType, kSRGB_SkColorProfileType)
CPU_CONFIG(f16, kRaster_Backend, CPU_CONFIG(f16, kRaster_Backend,
kRGBA_F16_SkColorType, kPremul_SkAlphaType, nullptr) kRGBA_F16_SkColorType, kPremul_SkAlphaType, kLinear_SkColorProfileType)
} }
#undef CPU_CONFIG #undef CPU_CONFIG
@ -466,7 +465,7 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
if (config->getTag().equals("hwui")) { if (config->getTag().equals("hwui")) {
Config config = { SkString("hwui"), Benchmark::kHWUI_Backend, Config config = { SkString("hwui"), Benchmark::kHWUI_Backend,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, kRGBA_8888_SkColorType, kPremul_SkAlphaType, kLinear_SkColorProfileType,
0, kBogusContextType, kBogusContextOptions, false }; 0, kBogusContextType, kBogusContextOptions, false };
configs->push_back(config); configs->push_back(config);
} }
@ -489,7 +488,7 @@ static Target* is_enabled(Benchmark* bench, const Config& config) {
} }
SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
config.color, config.alpha, config.colorSpace); config.color, config.alpha, config.profile);
Target* target = nullptr; Target* target = nullptr;

View File

@ -26,7 +26,7 @@ struct Config {
Benchmark::Backend backend; Benchmark::Backend backend;
SkColorType color; SkColorType color;
SkAlphaType alpha; SkAlphaType alpha;
sk_sp<SkColorSpace> colorSpace; SkColorProfileType profile;
int samples; int samples;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
sk_gpu_test::GrContextFactory::ContextType ctxType; sk_gpu_test::GrContextFactory::ContextType ctxType;

View File

@ -802,8 +802,8 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
contextOptions = static_cast<GrContextFactory::ContextOptions>( contextOptions = static_cast<GrContextFactory::ContextOptions>(
contextOptions | GrContextFactory::kEnableNVPR_ContextOptions); contextOptions | GrContextFactory::kEnableNVPR_ContextOptions);
} }
if (SkColorAndColorSpaceAreGammaCorrect(gpuConfig->getColorType(), if (SkColorAndProfileAreGammaCorrect(gpuConfig->getColorType(),
gpuConfig->getColorSpace())) { gpuConfig->getProfileType())) {
contextOptions = static_cast<GrContextFactory::ContextOptions>( contextOptions = static_cast<GrContextFactory::ContextOptions>(
contextOptions | GrContextFactory::kRequireSRGBSupport_ContextOptions); contextOptions | GrContextFactory::kRequireSRGBSupport_ContextOptions);
} }
@ -815,7 +815,7 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
} }
return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(), return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(),
gpuConfig->getUseDIText(), gpuConfig->getColorType(), gpuConfig->getUseDIText(), gpuConfig->getColorType(),
sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading); gpuConfig->getProfileType(), FLAGS_gpu_threading);
} }
} }
#endif #endif
@ -827,11 +827,9 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
#endif #endif
if (FLAGS_cpu) { if (FLAGS_cpu) {
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
SINK("565", RasterSink, kRGB_565_SkColorType); SINK("565", RasterSink, kRGB_565_SkColorType);
SINK("8888", RasterSink, kN32_SkColorType); SINK("8888", RasterSink, kN32_SkColorType);
SINK("srgb", RasterSink, kN32_SkColorType, srgbColorSpace); SINK("srgb", RasterSink, kN32_SkColorType, kSRGB_SkColorProfileType);
SINK("f16", RasterSink, kRGBA_F16_SkColorType); SINK("f16", RasterSink, kRGBA_F16_SkColorType);
SINK("pdf", PDFSink); SINK("pdf", PDFSink);
SINK("skp", SKPSink); SINK("skp", SKPSink);

View File

@ -1060,14 +1060,14 @@ GPUSink::GPUSink(GrContextFactory::ContextType ct,
int samples, int samples,
bool diText, bool diText,
SkColorType colorType, SkColorType colorType,
sk_sp<SkColorSpace> colorSpace, SkColorProfileType profileType,
bool threaded) bool threaded)
: fContextType(ct) : fContextType(ct)
, fContextOptions(options) , fContextOptions(options)
, fSampleCount(samples) , fSampleCount(samples)
, fUseDIText(diText) , fUseDIText(diText)
, fColorType(colorType) , fColorType(colorType)
, fColorSpace(std::move(colorSpace)) , fProfileType(profileType)
, fThreaded(threaded) {} , fThreaded(threaded) {}
void PreAbandonGpuContextErrorHandler(SkError, void*) {} void PreAbandonGpuContextErrorHandler(SkError, void*) {}
@ -1093,7 +1093,7 @@ Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) co
const SkISize size = src.size(); const SkISize size = src.size();
const SkImageInfo info = const SkImageInfo info =
SkImageInfo::Make(size.width(), size.height(), fColorType, SkImageInfo::Make(size.width(), size.height(), fColorType,
kPremul_SkAlphaType, fColorSpace); kPremul_SkAlphaType, fProfileType);
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
GrContext* context = factory.getContextInfo(fContextType, fContextOptions).grContext(); GrContext* context = factory.getContextInfo(fContextType, fContextOptions).grContext();
const int maxDimension = context->caps()->maxTextureSize(); const int maxDimension = context->caps()->maxTextureSize();
@ -1213,9 +1213,9 @@ Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
RasterSink::RasterSink(SkColorType colorType, sk_sp<SkColorSpace> colorSpace) RasterSink::RasterSink(SkColorType colorType, SkColorProfileType profileType)
: fColorType(colorType) : fColorType(colorType)
, fColorSpace(std::move(colorSpace)) {} , fProfileType(profileType) {}
Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const { Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
const SkISize size = src.size(); const SkISize size = src.size();
@ -1225,7 +1225,7 @@ Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) con
SkMallocPixelRef::ZeroedPRFactory factory; SkMallocPixelRef::ZeroedPRFactory factory;
dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), dst->allocPixels(SkImageInfo::Make(size.width(), size.height(),
fColorType, alphaType, fColorSpace), fColorType, alphaType, fProfileType),
&factory, &factory,
nullptr/*colortable*/); nullptr/*colortable*/);
SkCanvas canvas(*dst); SkCanvas canvas(*dst);

View File

@ -281,7 +281,7 @@ class GPUSink : public Sink {
public: public:
GPUSink(sk_gpu_test::GrContextFactory::ContextType, GPUSink(sk_gpu_test::GrContextFactory::ContextType,
sk_gpu_test::GrContextFactory::ContextOptions, sk_gpu_test::GrContextFactory::ContextOptions,
int samples, bool diText, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, int samples, bool diText, SkColorType colorType, SkColorProfileType profileType,
bool threaded); bool threaded);
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
@ -294,7 +294,7 @@ private:
int fSampleCount; int fSampleCount;
bool fUseDIText; bool fUseDIText;
SkColorType fColorType; SkColorType fColorType;
sk_sp<SkColorSpace> fColorSpace; SkColorProfileType fProfileType;
bool fThreaded; bool fThreaded;
}; };
@ -318,14 +318,14 @@ public:
class RasterSink : public Sink { class RasterSink : public Sink {
public: public:
explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr); explicit RasterSink(SkColorType, SkColorProfileType=kLinear_SkColorProfileType);
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "png"; } const char* fileExtension() const override { return "png"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
private: private:
SkColorType fColorType; SkColorType fColorType;
sk_sp<SkColorSpace> fColorSpace; SkColorProfileType fProfileType;
}; };
class SKPSink : public Sink { class SKPSink : public Sink {

View File

@ -155,9 +155,13 @@ void HelloWorldWindow::draw(SkCanvas* canvas) {
if (snap->peekPixels(&pmap)) { if (snap->peekPixels(&pmap)) {
const SkImageInfo& info = pmap.info(); const SkImageInfo& info = pmap.info();
fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), fRenderTarget->writePixels(0, 0, snap->width(), snap->height(),
SkImageInfo2GrPixelConfig(info, *fContext->caps()), SkImageInfo2GrPixelConfig(info.colorType(),
pmap.addr(), pmap.rowBytes(), info.alphaType(),
GrContext::kFlushWrites_PixelOp); info.profileType(),
*fContext->caps()),
pmap.addr(),
pmap.rowBytes(),
GrContext::kFlushWrites_PixelOp);
} }
} }
INHERITED::present(); INHERITED::present();

View File

@ -85,7 +85,6 @@ public:
int height() const { return fInfo.height(); } int height() const { return fInfo.height(); }
SkColorType colorType() const { return fInfo.colorType(); } SkColorType colorType() const { return fInfo.colorType(); }
SkAlphaType alphaType() const { return fInfo.alphaType(); } SkAlphaType alphaType() const { return fInfo.alphaType(); }
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
SkColorProfileType profileType() const { return fInfo.profileType(); } SkColorProfileType profileType() const { return fInfo.profileType(); }
/** /**

View File

@ -379,14 +379,12 @@ private:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static inline bool SkColorAndColorSpaceAreGammaCorrect(SkColorType ct, SkColorSpace* cs) { static inline bool SkColorAndProfileAreGammaCorrect(SkColorType ct, SkColorProfileType pt) {
// Anything with a color-space attached is gamma-correct, as is F16. return kSRGB_SkColorProfileType == pt || kRGBA_F16_SkColorType == ct;
// To get legacy behavior, you need to ask for non-F16, with a nullptr color space.
return (cs != nullptr) || kRGBA_F16_SkColorType == ct;
} }
static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) { static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) {
return SkColorAndColorSpaceAreGammaCorrect(info.colorType(), info.colorSpace()); return SkColorAndProfileAreGammaCorrect(info.colorType(), info.profileType());
} }
#endif #endif

View File

@ -248,7 +248,7 @@ public:
* not be created with the given config), or this PixelRef does not support deep * not be created with the given config), or this PixelRef does not support deep
* copies. * copies.
*/ */
virtual SkPixelRef* deepCopy(SkColorType, SkColorSpace*, const SkIRect* /*subset*/) { virtual SkPixelRef* deepCopy(SkColorType, SkColorProfileType, const SkIRect* /*subset*/) {
return NULL; return NULL;
} }

View File

@ -72,11 +72,10 @@ GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTexture
SkSourceGammaTreatment); SkSourceGammaTreatment);
// TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses). // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses).
GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, const SkColorSpace*, GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType, const GrCaps&);
const GrCaps&);
static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) { static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) {
return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.colorSpace(), caps); return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType(), caps);
} }
GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,

View File

@ -50,7 +50,8 @@ public:
protected: protected:
// overrides from SkPixelRef // overrides from SkPixelRef
bool onReadPixels(SkBitmap* dst, SkColorType, const SkIRect* subset) override; bool onReadPixels(SkBitmap* dst, SkColorType, const SkIRect* subset) override;
SkPixelRef* deepCopy(SkColorType, SkColorSpace*, const SkIRect* subset) override; SkPixelRef* deepCopy(SkColorType, SkColorProfileType,
const SkIRect* subset) override;
void onNotifyPixelsChanged() override; void onNotifyPixelsChanged() override;
private: private:

View File

@ -52,7 +52,7 @@ public:
void resize(int width, int height); void resize(int width, int height);
void resize(const SkImageInfo&); void resize(const SkImageInfo&);
void setColorType(SkColorType, sk_sp<SkColorSpace>); void setColorType(SkColorType, SkColorProfileType);
bool isDirty() const { return !fDirtyRgn.isEmpty(); } bool isDirty() const { return !fDirtyRgn.isEmpty(); }
bool update(SkIRect* updateArea); bool update(SkIRect* updateArea);

View File

@ -48,18 +48,17 @@ class GrContext;
const struct { const struct {
SkColorType fColorType; SkColorType fColorType;
bool fSRGB; SkColorProfileType fProfileType;
const char* fName; const char* fName;
} gConfig[] = { } gConfig[] = {
{ kN32_SkColorType, false, "L32" }, { kN32_SkColorType, kLinear_SkColorProfileType, "L32" },
{ kN32_SkColorType, true, "S32" }, { kN32_SkColorType, kSRGB_SkColorProfileType, "S32" },
{ kRGBA_F16_SkColorType, false, "F16" }, { kRGBA_F16_SkColorType, kLinear_SkColorProfileType, "F16" },
}; };
static const char* find_config_name(const SkImageInfo& info) { static const char* find_config_name(const SkImageInfo& info) {
for (const auto& config : gConfig) { for (const auto& config : gConfig) {
if (config.fColorType == info.colorType() && if (config.fColorType == info.colorType() && config.fProfileType == info.profileType()) {
config.fSRGB == (info.colorSpace() != nullptr)) {
return config.fName; return config.fName;
} }
} }
@ -1533,9 +1532,7 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
return true; return true;
} }
if (SkOSMenu::FindListIndex(evt, "ColorType", &selected)) { if (SkOSMenu::FindListIndex(evt, "ColorType", &selected)) {
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); this->setDeviceColorType(gConfig[selected].fColorType, gConfig[selected].fProfileType);
this->setDeviceColorType(gConfig[selected].fColorType,
gConfig[selected].fSRGB ? srgbColorSpace : nullptr);
return true; return true;
} }
if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) {
@ -1750,8 +1747,8 @@ void SampleWindow::setDeviceType(DeviceType type) {
this->inval(nullptr); this->inval(nullptr);
} }
void SampleWindow::setDeviceColorType(SkColorType ct, sk_sp<SkColorSpace> cs) { void SampleWindow::setDeviceColorType(SkColorType ct, SkColorProfileType pt) {
this->setColorType(ct, std::move(cs)); this->setColorType(ct, pt);
fDevManager->tearDownBackend(this); fDevManager->tearDownBackend(this);
fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor); fDevManager->setUpBackend(this, fMSAASampleCount, fDeepColor);

View File

@ -116,7 +116,7 @@ public:
void draw(SkCanvas*) override; void draw(SkCanvas*) override;
void setDeviceType(DeviceType type); void setDeviceType(DeviceType type);
void setDeviceColorType(SkColorType, sk_sp<SkColorSpace>); void setDeviceColorType(SkColorType, SkColorProfileType);
void toggleRendering(); void toggleRendering();
void toggleSlideshow(); void toggleSlideshow();
void toggleFPS(); void toggleFPS();

View File

@ -742,7 +742,7 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
if (fPixelRef->getTexture() != nullptr) { if (fPixelRef->getTexture() != nullptr) {
// Do a deep copy // Do a deep copy
SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->colorSpace(), &subset); SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->profileType(), &subset);
if (pixelRef != nullptr) { if (pixelRef != nullptr) {
SkBitmap dst; SkBitmap dst;
dst.setInfo(this->info().makeWH(subset.width(), subset.height())); dst.setInfo(this->info().makeWH(subset.width(), subset.height()));
@ -911,7 +911,7 @@ bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType, Allocator* alloc)
bool SkBitmap::deepCopyTo(SkBitmap* dst) const { bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
const SkColorType dstCT = this->colorType(); const SkColorType dstCT = this->colorType();
SkColorSpace* dstCS = this->colorSpace(); const SkColorProfileType dstPT = this->profileType();
if (!this->canCopyTo(dstCT)) { if (!this->canCopyTo(dstCT)) {
return false; return false;
@ -920,10 +920,10 @@ bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
// If we have a PixelRef, and it supports deep copy, use it. // If we have a PixelRef, and it supports deep copy, use it.
// Currently supported only by texture-backed bitmaps. // Currently supported only by texture-backed bitmaps.
if (fPixelRef) { if (fPixelRef) {
SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstCS, nullptr); SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstPT, nullptr);
if (pixelRef) { if (pixelRef) {
uint32_t rowBytes; uint32_t rowBytes;
if (this->colorType() == dstCT && this->colorSpace() == dstCS) { if (this->colorType() == dstCT && this->profileType() == dstPT) {
// Since there is no subset to pass to deepCopy, and deepCopy // Since there is no subset to pass to deepCopy, and deepCopy
// succeeded, the new pixel ref must be identical. // succeeded, the new pixel ref must be identical.
SkASSERT(fPixelRef->info() == pixelRef->info()); SkASSERT(fPixelRef->info() == pixelRef->info());

View File

@ -213,7 +213,7 @@ sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context,
SkColorType ct = origInfo.colorType(); SkColorType ct = origInfo.colorType();
SkAlphaType at = origInfo.alphaType(); SkAlphaType at = origInfo.alphaType();
SkColorSpace* cs = origInfo.colorSpace(); SkColorProfileType pt = origInfo.profileType();
if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) { if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) {
at = kOpaque_SkAlphaType; // force this setting at = kOpaque_SkAlphaType; // force this setting
} }
@ -221,13 +221,13 @@ sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context,
at = kPremul_SkAlphaType; // force this setting at = kPremul_SkAlphaType; // force this setting
} }
GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps()); GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, pt, *context->caps());
if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) { if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) {
// Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32 // Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32
ct = kN32_SkColorType; ct = kN32_SkColorType;
} }
GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps()); GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, pt, *context->caps());
return context->newDrawContext(SkBackingFit::kExact, // Why exact? return context->newDrawContext(SkBackingFit::kExact, // Why exact?
origInfo.width(), origInfo.height(), origInfo.width(), origInfo.height(),

View File

@ -243,7 +243,7 @@ GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps); GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *caps);
if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) && if (caps->srgbSupport() && !GrPixelConfigIsSRGB(desc.fConfig) &&
pixmap.info().colorSpace() && pixmap.info().colorSpace()->gammaCloseToSRGB()) { kSRGB_SkColorProfileType == pixmap.info().profileType()) {
// We were supplied sRGB as the profile type, but we don't have a suitable pixel config. // We were supplied sRGB as the profile type, but we don't have a suitable pixel config.
// Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't // Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't
// handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both the source and // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both the source and
@ -418,7 +418,7 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
// alphatype is ignore for now, but if GrPixelConfig is expanded to encompass // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
// alpha info, that will be considered. // alpha info, that will be considered.
GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, const SkColorSpace* cs, GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProfileType pt,
const GrCaps& caps) { const GrCaps& caps) {
// We intentionally ignore profile type for non-8888 formats. Anything we can't support // We intentionally ignore profile type for non-8888 formats. Anything we can't support
// in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture. // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture.
@ -432,10 +432,10 @@ GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, const SkCol
case kARGB_4444_SkColorType: case kARGB_4444_SkColorType:
return kRGBA_4444_GrPixelConfig; return kRGBA_4444_GrPixelConfig;
case kRGBA_8888_SkColorType: case kRGBA_8888_SkColorType:
return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) return (kSRGB_SkColorProfileType == pt && caps.srgbSupport())
? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig; ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
case kBGRA_8888_SkColorType: case kBGRA_8888_SkColorType:
return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) return (kSRGB_SkColorProfileType == pt && caps.srgbSupport())
? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig; ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
case kIndex_8_SkColorType: case kIndex_8_SkColorType:
return kIndex_8_GrPixelConfig; return kIndex_8_GrPixelConfig;

View File

@ -50,7 +50,7 @@ bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorType dstCT, static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorType dstCT,
SkColorSpace* dstCS, const SkIRect* subset) { SkColorProfileType dstPT, const SkIRect* subset) {
if (nullptr == texture || kUnknown_SkColorType == dstCT) { if (nullptr == texture || kUnknown_SkColorType == dstCT) {
return nullptr; return nullptr;
} }
@ -74,7 +74,7 @@ static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp
srcRect = *subset; srcRect = *subset;
} }
desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstCS, *context->caps()); desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT, *context->caps());
desc.fIsMipMapped = false; desc.fIsMipMapped = false;
GrTexture* dst = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0); GrTexture* dst = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
@ -89,7 +89,7 @@ static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp
context->flushSurfaceWrites(dst); context->flushSurfaceWrites(dst);
SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType, SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType,
sk_ref_sp(dstCS)); dstPT);
SkGrPixelRef* pixelRef = new SkGrPixelRef(info, dst); SkGrPixelRef* pixelRef = new SkGrPixelRef(info, dst);
SkSafeUnref(dst); SkSafeUnref(dst);
return pixelRef; return pixelRef;
@ -130,7 +130,8 @@ void SkGrPixelRef::onNotifyPixelsChanged() {
} }
} }
SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorSpace* dstCS, const SkIRect* subset) { SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorProfileType dstPT,
const SkIRect* subset) {
if (nullptr == fSurface) { if (nullptr == fSurface) {
return nullptr; return nullptr;
} }
@ -141,7 +142,7 @@ SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorSpace* dstCS, const
// a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
// independently of that texture. Texture-backed pixel refs, on the other // independently of that texture. Texture-backed pixel refs, on the other
// hand, own their GrTextures, and are thus self-contained. // hand, own their GrTextures, and are thus self-contained.
return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstCS, subset); return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstPT, subset);
} }
static bool tryAllocBitmapPixels(SkBitmap* bitmap) { static bool tryAllocBitmapPixels(SkBitmap* bitmap) {
@ -182,7 +183,7 @@ bool SkGrPixelRef::onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIR
SkBitmap cachedBitmap; SkBitmap cachedBitmap;
cachedBitmap.setInfo(SkImageInfo::Make(bounds.width(), bounds.height(), colorType, cachedBitmap.setInfo(SkImageInfo::Make(bounds.width(), bounds.height(), colorType,
this->info().alphaType(), this->info().alphaType(),
sk_ref_sp(this->info().colorSpace()))); this->info().profileType()));
// If we can't alloc the pixels, then fail // If we can't alloc the pixels, then fail
if (!tryAllocBitmapPixels(&cachedBitmap)) { if (!tryAllocBitmapPixels(&cachedBitmap)) {

View File

@ -111,7 +111,9 @@ static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
int srcX, int srcY, CachingHint) const { int srcX, int srcY, CachingHint) const {
GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps()); GrPixelConfig config = SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(),
info.profileType(),
*fTexture->getContext()->caps());
uint32_t flags = 0; uint32_t flags = 0;
if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlphaType) { if (kUnpremul_SkAlphaType == info.alphaType() && kPremul_SkAlphaType == fAlphaType) {
// let the GPU perform this transformation for us // let the GPU perform this transformation for us

View File

@ -67,16 +67,15 @@ void SkWindow::resize(int width, int height) {
this->resize(fBitmap.info().makeWH(width, height)); this->resize(fBitmap.info().makeWH(width, height));
} }
void SkWindow::setColorType(SkColorType ct, sk_sp<SkColorSpace> cs) { void SkWindow::setColorType(SkColorType ct, SkColorProfileType pt) {
const SkImageInfo& info = fBitmap.info(); const SkImageInfo& info = fBitmap.info();
this->resize(SkImageInfo::Make(info.width(), info.height(), ct, kPremul_SkAlphaType, cs)); this->resize(SkImageInfo::Make(info.width(), info.height(), ct, kPremul_SkAlphaType, pt));
// Set the global flag that enables or disables "legacy" mode, depending on our format. // Set the global flag that enables or disables "legacy" mode, depending on our format.
// With sRGB 32-bit or linear FP 16, we turn on gamma-correct handling of inputs: // With sRGB 32-bit or linear FP 16, we turn on gamma-correct handling of inputs:
SkSurfaceProps props = this->getSurfaceProps(); SkSurfaceProps props = this->getSurfaceProps();
uint32_t flags = (props.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) | uint32_t flags = (props.flags() & ~SkSurfaceProps::kGammaCorrect_Flag) |
(SkColorAndColorSpaceAreGammaCorrect(ct, cs.get()) (SkColorAndProfileAreGammaCorrect(ct, pt) ? SkSurfaceProps::kGammaCorrect_Flag : 0);
? SkSurfaceProps::kGammaCorrect_Flag : 0);
this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry())); this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry()));
} }

View File

@ -424,7 +424,7 @@ static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* tex
GrPixelConfig dstConfig = GrPixelConfig dstConfig =
SkImageInfo2GrPixelConfig(gReadPixelsConfigs[c].fColorType, SkImageInfo2GrPixelConfig(gReadPixelsConfigs[c].fColorType,
gReadPixelsConfigs[c].fAlphaType, gReadPixelsConfigs[c].fAlphaType,
nullptr, kLinear_SkColorProfileType,
*texture->getContext()->caps()); *texture->getContext()->caps());
uint32_t flags = 0; uint32_t flags = 0;
if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) { if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) {

View File

@ -46,7 +46,8 @@ DEF_TEST(ParseConfigs_Gpu, reporter) {
REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false); REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_SkColorType); REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_SkColorType);
REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr); REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getProfileType()
== kLinear_SkColorProfileType);
#endif #endif
} }
@ -82,8 +83,6 @@ DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
SkCommandLineConfigArray configs; SkCommandLineConfigArray configs;
ParseConfigs(config1, &configs); ParseConfigs(config1, &configs);
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
REPORTER_ASSERT(reporter, configs.count() == config1.count()); REPORTER_ASSERT(reporter, configs.count() == config1.count());
for (int i = 0; i < config1.count(); ++i) { for (int i = 0; i < config1.count(); ++i) {
REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
@ -119,11 +118,14 @@ DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu()); REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu());
REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType()
REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == nullptr); == kRGBA_F16_SkColorType);
REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kN32_SkColorType); REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getProfileType()
REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); == kLinear_SkColorProfileType);
REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType()
== kN32_SkColorType);
REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getProfileType()
== kSRGB_SkColorProfileType);
#if SK_ANGLE #if SK_ANGLE
#ifdef SK_BUILD_FOR_WIN #ifdef SK_BUILD_FOR_WIN
REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
@ -155,7 +157,8 @@ DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText()); REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText());
REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()); REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kN32_SkColorType); REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kN32_SkColorType);
REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getProfileType() ==
kSRGB_SkColorProfileType);
REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()); REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4); REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4);
#ifdef SK_VULKAN #ifdef SK_VULKAN

View File

@ -192,14 +192,14 @@ SkCommandLineConfig::~SkCommandLineConfig() {
SkCommandLineConfigGpu::SkCommandLineConfigGpu( SkCommandLineConfigGpu::SkCommandLineConfigGpu(
const SkString& tag, const SkTArray<SkString>& viaParts, const SkString& tag, const SkTArray<SkString>& viaParts,
ContextType contextType, bool useNVPR, bool useDIText, int samples, ContextType contextType, bool useNVPR, bool useDIText, int samples,
SkColorType colorType, sk_sp<SkColorSpace> colorSpace) SkColorType colorType, SkColorProfileType profileType)
: SkCommandLineConfig(tag, SkString("gpu"), viaParts) : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
, fContextType(contextType) , fContextType(contextType)
, fUseNVPR(useNVPR) , fUseNVPR(useNVPR)
, fUseDIText(useDIText) , fUseDIText(useDIText)
, fSamples(samples) , fSamples(samples)
, fColorType(colorType) , fColorType(colorType)
, fColorSpace(std::move(colorSpace)) { , fProfileType(profileType) {
} }
static bool parse_option_int(const SkString& value, int* outInt) { static bool parse_option_int(const SkString& value, int* outInt) {
if (value.isEmpty()) { if (value.isEmpty()) {
@ -276,20 +276,20 @@ static bool parse_option_gpu_api(const SkString& value,
} }
static bool parse_option_gpu_color(const SkString& value, static bool parse_option_gpu_color(const SkString& value,
SkColorType* outColorType, SkColorType* outColorType,
sk_sp<SkColorSpace>* outColorSpace) { SkColorProfileType* outProfileType) {
if (value.equals("8888")) { if (value.equals("8888")) {
*outColorType = kN32_SkColorType; *outColorType = kN32_SkColorType;
*outColorSpace = nullptr; *outProfileType = kLinear_SkColorProfileType;
return true; return true;
} }
if (value.equals("f16")) { if (value.equals("f16")) {
*outColorType = kRGBA_F16_SkColorType; *outColorType = kRGBA_F16_SkColorType;
*outColorSpace = nullptr; *outProfileType = kLinear_SkColorProfileType;
return true; return true;
} }
if (value.equals("srgb")) { if (value.equals("srgb")) {
*outColorType = kN32_SkColorType; *outColorType = kN32_SkColorType;
*outColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); *outProfileType = kSRGB_SkColorProfileType;
return true; return true;
} }
return false; return false;
@ -309,7 +309,7 @@ SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
int samples = 0; int samples = 0;
bool seenColor = false; bool seenColor = false;
SkColorType colorType = kN32_SkColorType; SkColorType colorType = kN32_SkColorType;
sk_sp<SkColorSpace> colorSpace = nullptr; SkColorProfileType profileType = kLinear_SkColorProfileType;
SkTArray<SkString> optionParts; SkTArray<SkString> optionParts;
SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
@ -335,7 +335,7 @@ SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
valueOk = parse_option_int(value, &samples); valueOk = parse_option_int(value, &samples);
seenSamples = true; seenSamples = true;
} else if (key.equals("color") && !seenColor) { } else if (key.equals("color") && !seenColor) {
valueOk = parse_option_gpu_color(value, &colorType, &colorSpace); valueOk = parse_option_gpu_color(value, &colorType, &profileType);
seenColor = true; seenColor = true;
} }
if (!valueOk) { if (!valueOk) {
@ -343,7 +343,7 @@ SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
} }
} }
return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText, samples, return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText, samples,
colorType, colorSpace); colorType, profileType);
} }
#endif #endif

View File

@ -53,14 +53,14 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig {
typedef sk_gpu_test::GrContextFactory::ContextType ContextType; typedef sk_gpu_test::GrContextFactory::ContextType ContextType;
SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts, SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
ContextType contextType, bool useNVPR, bool useDIText, int samples, ContextType contextType, bool useNVPR, bool useDIText, int samples,
SkColorType colorType, sk_sp<SkColorSpace> colorSpace); SkColorType colorType, SkColorProfileType profileType);
const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
ContextType getContextType() const { return fContextType; } ContextType getContextType() const { return fContextType; }
bool getUseNVPR() const { return fUseNVPR; } bool getUseNVPR() const { return fUseNVPR; }
bool getUseDIText() const { return fUseDIText; } bool getUseDIText() const { return fUseDIText; }
int getSamples() const { return fSamples; } int getSamples() const { return fSamples; }
SkColorType getColorType() const { return fColorType; } SkColorType getColorType() const { return fColorType; }
SkColorSpace* getColorSpace() const { return fColorSpace.get(); } SkColorProfileType getProfileType() const { return fProfileType; }
private: private:
ContextType fContextType; ContextType fContextType;
@ -68,7 +68,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig {
bool fUseDIText; bool fUseDIText;
int fSamples; int fSamples;
SkColorType fColorType; SkColorType fColorType;
sk_sp<SkColorSpace> fColorSpace; SkColorProfileType fProfileType;
}; };
#endif #endif

View File

@ -80,9 +80,8 @@ namespace sk_tools {
SkAutoTMalloc<uint32_t> rgba(w*h); SkAutoTMalloc<uint32_t> rgba(w*h);
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); if (bitmap. colorType() == kN32_SkColorType &&
if (bitmap. colorType() == kN32_SkColorType && bitmap.profileType() == kSRGB_SkColorProfileType) {
bitmap.colorSpace() == srgbColorSpace.get()) {
// These are premul sRGB 8-bit pixels in SkPMColor order. // These are premul sRGB 8-bit pixels in SkPMColor order.
// We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats.
bitmap.lockPixels(); bitmap.lockPixels();

View File

@ -159,14 +159,14 @@ namespace {
struct ColorAndProfile { struct ColorAndProfile {
SkColorType fColorType; SkColorType fColorType;
bool fSRGB; SkColorProfileType fProfileType;
bool fGammaCorrect; bool fGammaCorrect;
}; };
ColorAndProfile ColorModes[] = { ColorAndProfile ColorModes[] = {
{ kN32_SkColorType, false, false }, { kN32_SkColorType, kLinear_SkColorProfileType, false },
{ kN32_SkColorType, true, true }, { kN32_SkColorType, kSRGB_SkColorProfileType, true },
{ kRGBA_F16_SkColorType, false, true }, { kRGBA_F16_SkColorType, kLinear_SkColorProfileType, true },
}; };
} }
@ -174,9 +174,8 @@ ColorAndProfile ColorModes[] = {
SkSurface* Request::createCPUSurface() { SkSurface* Request::createCPUSurface() {
SkIRect bounds = this->getBounds(); SkIRect bounds = this->getBounds();
ColorAndProfile cap = ColorModes[fColorMode]; ColorAndProfile cap = ColorModes[fColorMode];
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType, SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
kPremul_SkAlphaType, cap.fSRGB ? srgbColorSpace : nullptr); kPremul_SkAlphaType, cap.fProfileType);
uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0; uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
return SkSurface::MakeRaster(info, &props).release(); return SkSurface::MakeRaster(info, &props).release();
@ -186,9 +185,8 @@ SkSurface* Request::createGPUSurface() {
GrContext* context = this->getContext(); GrContext* context = this->getContext();
SkIRect bounds = this->getBounds(); SkIRect bounds = this->getBounds();
ColorAndProfile cap = ColorModes[fColorMode]; ColorAndProfile cap = ColorModes[fColorMode];
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType, SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
kPremul_SkAlphaType, cap.fSRGB ? srgbColorSpace : nullptr); kPremul_SkAlphaType, cap.fProfileType);
uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0; uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0,

View File

@ -122,8 +122,8 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
}); });
fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() { fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() {
DisplayParams params = fWindow->getDisplayParams(); DisplayParams params = fWindow->getDisplayParams();
params.fColorSpace = (nullptr == params.fColorSpace) params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType)
? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr; ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
fWindow->setDisplayParams(params); fWindow->setDisplayParams(params);
this->updateTitle(); this->updateTitle();
fWindow->inval(); fWindow->inval();
@ -266,9 +266,7 @@ Viewer::~Viewer() {
void Viewer::updateTitle() { void Viewer::updateTitle() {
SkString title("Viewer: "); SkString title("Viewer: ");
title.append(fSlides[fCurrentSlide]->getName()); title.append(fSlides[fCurrentSlide]->getName());
if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) {
// TODO: For now, any color-space on the window means sRGB
if (fWindow->getDisplayParams().fColorSpace) {
title.append(" sRGB"); title.append(" sRGB");
} }
title.append(kBackendTypeStrings[fBackendType]); title.append(kBackendTypeStrings[fBackendType]);

View File

@ -14,14 +14,14 @@ namespace sk_app {
struct DisplayParams { struct DisplayParams {
DisplayParams() DisplayParams()
: fColorType(kN32_SkColorType) : fColorType(kN32_SkColorType)
, fColorSpace(nullptr) , fProfileType(kLinear_SkColorProfileType)
, fMSAASampleCount(0) , fMSAASampleCount(0)
, fDeepColor(false) {} , fDeepColor(false) {}
SkColorType fColorType; SkColorType fColorType;
sk_sp<SkColorSpace> fColorSpace; SkColorProfileType fProfileType;
int fMSAASampleCount; int fMSAASampleCount;
bool fDeepColor; bool fDeepColor;
}; };
} // namespace sk_app } // namespace sk_app

View File

@ -47,8 +47,8 @@ void GLWindowContext::initializeContext(void* platformData, const DisplayParams&
// ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write, // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write,
// so pretend that it's non-sRGB 8888: // so pretend that it's non-sRGB 8888:
fPixelConfig = fContext->caps()->srgbSupport() && fPixelConfig = fContext->caps()->srgbSupport() &&
SkColorAndColorSpaceAreGammaCorrect(fDisplayParams.fColorType, SkColorAndProfileAreGammaCorrect(fDisplayParams.fColorType,
fDisplayParams.fColorSpace.get()) && fDisplayParams.fProfileType) &&
(fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig; (fColorBits != 30) ? kSkiaGamma8888_GrPixelConfig : kSkia8888_GrPixelConfig;
} }

View File

@ -173,8 +173,7 @@ bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height,
// Pick our surface format. For now, just make sure it matches our sRGB request: // Pick our surface format. For now, just make sure it matches our sRGB request:
VkFormat surfaceFormat = VK_FORMAT_UNDEFINED; VkFormat surfaceFormat = VK_FORMAT_UNDEFINED;
VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); bool wantSRGB = kSRGB_SkColorProfileType == params.fProfileType;
bool wantSRGB = srgbColorSpace == params.fColorSpace;
for (uint32_t i = 0; i < surfaceFormatCount; ++i) { for (uint32_t i = 0; i < surfaceFormatCount; ++i) {
GrPixelConfig config; GrPixelConfig config;
if (GrVkFormatToPixelConfig(surfaceFormats[i].format, &config) && if (GrVkFormatToPixelConfig(surfaceFormats[i].format, &config) &&

View File

@ -36,7 +36,7 @@ sk_sp<SkSurface> WindowContext::createRenderSurface(sk_sp<GrRenderTarget> rt, in
SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
fDisplayParams.fColorType, fDisplayParams.fColorType,
kUnknown_SkAlphaType, kUnknown_SkAlphaType,
fDisplayParams.fColorSpace); fDisplayParams.fProfileType);
return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info, return SkSurface::MakeRenderTarget(fContext, SkBudgeted::kNo, info,
fDisplayParams.fMSAASampleCount, &props); fDisplayParams.fMSAASampleCount, &props);
} else { } else {
@ -52,7 +52,7 @@ void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<G
SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
fDisplayParams.fColorType, fDisplayParams.fColorType,
kUnknown_SkAlphaType, kUnknown_SkAlphaType,
fDisplayParams.fColorSpace); fDisplayParams.fProfileType);
SkBitmap bm; SkBitmap bm;
bm.allocPixels(info); bm.allocPixels(info);
renderSurface->getCanvas()->readPixels(&bm, 0, 0); renderSurface->getCanvas()->readPixels(&bm, 0, 0);

View File

@ -99,8 +99,7 @@ void GLWindowContext_android::onInitializeContext(void* platformData, const Disp
EGL_NONE, EGL_NONE,
}; };
const EGLint* windowAttribs = nullptr; const EGLint* windowAttribs = nullptr;
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); if (kSRGB_SkColorProfileType == params.fProfileType && majorVersion == 1 && minorVersion >= 2) {
if (srgbColorSpace == params.fColorSpace && majorVersion == 1 && minorVersion >= 2) {
windowAttribs = srgbWindowAttribs; windowAttribs = srgbWindowAttribs;
} }

View File

@ -68,7 +68,7 @@ sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() {
SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, SkImageInfo info = SkImageInfo::Make(fWidth, fHeight,
fDisplayParams.fColorType, fDisplayParams.fColorType,
kOpaque_SkAlphaType, kOpaque_SkAlphaType,
fDisplayParams.fColorSpace); fDisplayParams.fProfileType);
fBackbufferSurface = SkSurface::MakeRasterDirect( fBackbufferSurface = SkSurface::MakeRasterDirect(
info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr); info, fBuffer.bits, fBuffer.stride * bytePerPixel, nullptr);
} }