Revert of More removal of SkColorProfileType... (patchset #2 id:20001 of https://codereview.chromium.org/2071393002/ )

Reason for revert:
This was still used in chrome

Original issue's description:
> More removal of SkColorProfileType...
>
> Scrub GMs. Remove the gDefaultProfile thing (it's unused now), along with
> the command line flag that was setting it in DM and nanobench.
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2071393002
>
> Committed: https://skia.googlesource.com/skia/+/944876f2745a62a839e49275daf93a0329372e67

TBR=msarett@google.com,reed@google.com,bsalomon@google.com,brianosman@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/2074103004
This commit is contained in:
egdaniel 2016-06-17 15:11:45 -07:00 committed by Commit bot
parent 992a22d2e9
commit 802acec187
23 changed files with 83 additions and 49 deletions

View File

@ -1025,6 +1025,8 @@ static void start_keepalive() {
intentionallyLeaked->start();
}
extern bool gDefaultProfileIsSRGB;
int nanobench_main();
int nanobench_main() {
SetupCrashHandler();
@ -1036,6 +1038,10 @@ int nanobench_main() {
gGrFactory.reset(new GrContextFactory(grContextOpts));
#endif
if (FLAGS_forceSRGB) {
gDefaultProfileIsSRGB = true;
}
if (FLAGS_veryVerbose) {
FLAGS_verbose = true;
}

View File

@ -1248,6 +1248,8 @@ static sk_sp<SkTypeface> create_from_name(const char familyName[], SkFontStyle s
extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle );
extern bool gDefaultProfileIsSRGB;
int dm_main();
int dm_main() {
setbuf(stdout, nullptr);
@ -1260,6 +1262,10 @@ int dm_main() {
gVLog = freopen(SkOSPath::Join(FLAGS_writePath[0], "verbose.log").c_str(), "w", stderr);
}
if (FLAGS_forceSRGB) {
gDefaultProfileIsSRGB = true;
}
JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
SkAutoGraphics ag;
SkTaskGroup::Enabler enabled(FLAGS_threads);

View File

@ -55,7 +55,7 @@ static void draw_rect_orig(SkCanvas* canvas, const SkRect& r, SkColor c, const S
SkPixmap pmdst;
bmdst.peekPixels(&pmdst);
SkImageInfo info = SkImageInfo::MakeN32Premul(ir.width(), ir.height());
SkImageInfo info = SkImageInfo::MakeN32Premul(ir.width(), ir.height(), kLinear_SkColorProfileType);
sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, pmsrc.addr32(), pmsrc.rowBytes())));
SkPaint paint;
@ -113,6 +113,9 @@ static void draw_rect_fp(SkCanvas* canvas, const SkRect& r, SkColor c, const SkM
}
uint32_t flags = 0;
//if (kSRGB_SkColorProfileType == profile) {
//flags |= SkXfermode::kDstIsSRGB_PM4fFlag;
//}
auto procN = SkXfermode::GetD32Proc(nullptr, flags);
SkLinearBitmapPipeline pipeline{

View File

@ -246,13 +246,13 @@ static uint32_t make_pixel(int x, int y, SkAlphaType alphaType) {
static void make_color_test_bitmap_variant(
SkColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace,
SkColorProfileType profile,
SkBitmap* bm)
{
SkASSERT(colorType == kRGBA_8888_SkColorType || colorType == kBGRA_8888_SkColorType);
SkASSERT(alphaType == kPremul_SkAlphaType || alphaType == kUnpremul_SkAlphaType);
bm->allocPixels(
SkImageInfo::Make(SCALE, SCALE, colorType, alphaType, colorSpace));
SkImageInfo::Make(SCALE, SCALE, colorType, alphaType, profile));
SkPixmap pm;
bm->peekPixels(&pm);
for (int y = 0; y < bm->height(); y++) {
@ -265,17 +265,13 @@ static void make_color_test_bitmap_variant(
DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 2 * SCALE + 10) {
sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
sk_sp<SkColorSpace> colorSpaces[] {
nullptr,
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
};
for (auto colorSpace : colorSpaces) {
for (auto profile : {kSRGB_SkColorProfileType, kLinear_SkColorProfileType}) {
canvas->save();
for (auto alphaType : {kPremul_SkAlphaType, kUnpremul_SkAlphaType}) {
canvas->save();
for (auto colorType : {kRGBA_8888_SkColorType, kBGRA_8888_SkColorType}) {
SkBitmap bm;
make_color_test_bitmap_variant(colorType, alphaType, colorSpace, &bm);
make_color_test_bitmap_variant(colorType, alphaType, profile, &bm);
canvas->drawBitmap(bm, 0.0f, 0.0f);
canvas->translate(SCALE + 10, 0.0f);
}

View File

@ -73,13 +73,10 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
// even if it holds sRGB values.
bg.setColor(0xFFFFFFFF);
sk_sp<SkColorSpace> colorSpaces[]{
nullptr,
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
};
for (auto colorSpace : colorSpaces) {
SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkColorProfileType };
for (auto profile : profiles) {
const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
colorSpace);
profile);
auto surface(SkSurface::MakeRaster(info));
surface->getCanvas()->drawPaint(bg);
draw_into_canvas(surface->getCanvas());

View File

@ -48,9 +48,8 @@ protected:
// set up offscreen rendering with distance field text
#if SK_SUPPORT_GPU
GrContext* ctx = inputCanvas->getGrContext();
SkISize size = onISize();
SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType,
sk_ref_sp(inputCanvas->imageInfo().colorSpace()));
SkImageInfo info = SkImageInfo::MakeN32Premul(onISize(),
inputCanvas->imageInfo().profileType());
SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
uint32_t gammaCorrect = inputCanvas->getProps(&canvasProps)
? canvasProps.flags() & SkSurfaceProps::kGammaCorrect_Flag : 0;

View File

@ -18,7 +18,6 @@ DEF_SIMPLE_GM(gamma, canvas, 560, 200) {
const SkScalar tx = sz + 5.0f;
const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz);
SkShader::TileMode rpt = SkShader::kRepeat_TileMode;
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
SkBitmap ditherBmp;
ditherBmp.allocN32Pixels(2, 2);
@ -27,20 +26,21 @@ DEF_SIMPLE_GM(gamma, canvas, 560, 200) {
pixels[1] = pixels[2] = SkPackARGB32(0xFF, 0, 0, 0);
SkBitmap linearGreyBmp;
SkImageInfo linearGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAlphaType, nullptr);
SkImageInfo linearGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAlphaType,
kLinear_SkColorProfileType);
linearGreyBmp.allocPixels(linearGreyInfo);
linearGreyBmp.eraseARGB(0xFF, 0x7F, 0x7F, 0x7F);
SkBitmap srgbGreyBmp;
SkImageInfo srgbGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAlphaType,
srgbColorSpace);
kSRGB_SkColorProfileType);
srgbGreyBmp.allocPixels(srgbGreyInfo);
// 0xBC = 255 * linear_to_srgb(0.5f)
srgbGreyBmp.eraseARGB(0xFF, 0xBC, 0xBC, 0xBC);
SkBitmap mipmapBmp;
SkImageInfo mipmapInfo = SkImageInfo::Make(2, 2, kN32_SkColorType, kOpaque_SkAlphaType,
srgbColorSpace);
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
mipmapBmp.allocPixels(mipmapInfo);
SkPMColor* mipmapPixels = reinterpret_cast<SkPMColor*>(mipmapBmp.getPixels());
unsigned s25 = 0x89; // 255 * linear_to_srgb(0.25f)

View File

@ -78,7 +78,7 @@ protected:
// must be opaque to have a hope of testing LCD text
const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType,
sk_ref_sp(canvas->imageInfo().colorSpace()));
canvas->imageInfo().profileType());
SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
bool gammaCorrect = canvas->getProps(&canvasProps) && canvasProps.isGammaCorrect();

View File

@ -42,8 +42,7 @@ protected:
SkAutoTUnref<const SkTextBlob> blob(builder.build());
SkImageInfo info = SkImageInfo::MakeN32(200, 200, kPremul_SkAlphaType,
sk_ref_sp(canvas->imageInfo().colorSpace()));
SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200, canvas->imageInfo().profileType());
SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
uint32_t gammaCorrect = canvas->getProps(&canvasProps)
? canvasProps.flags() & SkSurfaceProps::kGammaCorrect_Flag : 0;

View File

@ -102,10 +102,8 @@ protected:
#if SK_SUPPORT_GPU
// Create a new Canvas to enable DFT
GrContext* ctx = inputCanvas->getGrContext();
SkISize size = onISize();
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(inputCanvas->imageInfo().colorSpace());
SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(),
kPremul_SkAlphaType, colorSpace);
SkImageInfo info = SkImageInfo::MakeN32Premul(onISize(),
inputCanvas->imageInfo().profileType());
SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
uint32_t gammaCorrect = inputCanvas->getProps(&canvasProps)
? canvasProps.flags() & SkSurfaceProps::kGammaCorrect_Flag : 0;

View File

@ -97,8 +97,8 @@ protected:
canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorWHITE));
SkImageInfo info = SkImageInfo::MakeN32(kWidth, kHeight, kPremul_SkAlphaType,
sk_ref_sp(canvas->imageInfo().colorSpace()));
SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight,
canvas->imageInfo().profileType());
SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
uint32_t gammaCorrect = canvas->getProps(&canvasProps)
? canvasProps.flags() & SkSurfaceProps::kGammaCorrect_Flag : 0;

View File

@ -126,7 +126,7 @@ private:
GrContext* context = baseCanvas->getGrContext();
SkImageInfo baseInfo = baseCanvas->imageInfo();
SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInfo.alphaType(),
sk_ref_sp(baseInfo.colorSpace()));
baseInfo.profileType());
SkSurfaceProps canvasProps(SkSurfaceProps::kLegacyFontHost_InitType);
baseCanvas->getProps(&canvasProps);
return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &canvasProps);

View File

@ -421,6 +421,7 @@
'<(skia_include_path)/private/SkFloatBits.h',
'<(skia_include_path)/private/SkFloatingPoint.h',
'<(skia_include_path)/private/SkGpuFenceSync.h',
'<(skia_include_path)/private/SkImageInfoPriv.h',
'<(skia_include_path)/private/SkMiniRecorder.h',
'<(skia_include_path)/private/SkMutex.h',
'<(skia_include_path)/private/SkOnce.h',

View File

@ -86,6 +86,9 @@ public:
SkColorType colorType() const { return fInfo.colorType(); }
SkAlphaType alphaType() const { return fInfo.alphaType(); }
SkColorSpace* colorSpace() const { return fInfo.colorSpace(); }
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
SkColorProfileType profileType() const { return fInfo.profileType(); }
#endif
/**
* Return the number of bytes per pixel based on the colortype. If the colortype is

View File

@ -0,0 +1,14 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkImageInfoPriv_DEFINED
#define SkImageInfoPriv_DEFINED
#include "SkImageInfo.h"
SK_API SkColorProfileType SkDefaultColorProfile();
#endif // SkImageInfoPriv_DEFINED

View File

@ -1177,7 +1177,6 @@ static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i
const SkPaint* paint) {
// need to force L32 for now if we have an image filter. Once filters support other colortypes
// e.g. sRGB or F16, we can remove this check
// SRGBTODO: Can we remove this check now?
const bool hasImageFilter = paint && paint->getImageFilter();
SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
@ -1186,7 +1185,7 @@ static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i
return SkImageInfo::MakeN32(w, h, alphaType);
} else {
// keep the same characteristics as the prev
return SkImageInfo::Make(w, h, prev.colorType(), alphaType, sk_ref_sp(prev.colorSpace()));
return SkImageInfo::Make(w, h, prev.colorType(), alphaType, prev.profileType());
}
}

View File

@ -6,6 +6,7 @@
*/
#include "SkImageInfo.h"
#include "SkImageInfoPriv.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
@ -60,6 +61,14 @@ SkColorProfileType SkImageInfo::profileType() const {
}
#endif
// Indicate how images and gradients should interpret colors by default.
bool gDefaultProfileIsSRGB;
SkColorProfileType SkDefaultColorProfile() {
return gDefaultProfileIsSRGB ? kSRGB_SkColorProfileType
: kLinear_SkColorProfileType;
}
static bool alpha_type_is_valid(SkAlphaType alphaType) {
return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
}

View File

@ -244,7 +244,7 @@ void GrContext::flush(int flagsBitfield) {
bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
const void* inPixels, size_t outRowBytes, void* outPixels) {
SkSrcPixelInfo srcPI;
if (!GrPixelConfigToColorAndColorSpace(srcConfig, &srcPI.fColorType, nullptr)) {
if (!GrPixelConfig2ColorAndProfileType(srcConfig, &srcPI.fColorType, nullptr)) {
return false;
}
srcPI.fAlphaType = kUnpremul_SkAlphaType;
@ -511,7 +511,7 @@ bool GrContext::readSurfacePixels(GrSurface* src,
// Perform umpremul conversion if we weren't able to perform it as a draw.
if (unpremul) {
SkDstPixelInfo dstPI;
if (!GrPixelConfigToColorAndColorSpace(dstConfig, &dstPI.fColorType, nullptr)) {
if (!GrPixelConfig2ColorAndProfileType(dstConfig, &dstPI.fColorType, nullptr)) {
return false;
}
dstPI.fAlphaType = kUnpremul_SkAlphaType;

View File

@ -118,11 +118,12 @@ bool GrSurface::readPixels(int left, int top, int width, int height,
SkImageInfo GrSurface::info(SkAlphaType alphaType) const {
SkColorType colorType;
sk_sp<SkColorSpace> colorSpace;
if (!GrPixelConfigToColorAndColorSpace(this->config(), &colorType, &colorSpace)) {
SkColorProfileType profileType;
if (!GrPixelConfig2ColorAndProfileType(this->config(), &colorType, &profileType)) {
sk_throw();
}
return SkImageInfo::Make(this->width(), this->height(), colorType, alphaType, colorSpace);
return SkImageInfo::Make(this->width(), this->height(), colorType, alphaType,
profileType);
}
// TODO: This should probably be a non-member helper function. It might only be needed in

View File

@ -453,10 +453,10 @@ GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, const SkCol
return kUnknown_GrPixelConfig;
}
bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
sk_sp<SkColorSpace>* csOut) {
bool GrPixelConfig2ColorAndProfileType(GrPixelConfig config, SkColorType* ctOut,
SkColorProfileType* ptOut) {
SkColorType ct;
sk_sp<SkColorSpace> cs = nullptr;
SkColorProfileType pt = kLinear_SkColorProfileType;
switch (config) {
case kAlpha_8_GrPixelConfig:
ct = kAlpha_8_SkColorType;
@ -478,11 +478,11 @@ bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
break;
case kSRGBA_8888_GrPixelConfig:
ct = kRGBA_8888_SkColorType;
cs = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
pt = kSRGB_SkColorProfileType;
break;
case kSBGRA_8888_GrPixelConfig:
ct = kBGRA_8888_SkColorType;
cs = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
pt = kSRGB_SkColorProfileType;
break;
case kRGBA_half_GrPixelConfig:
ct = kRGBA_F16_SkColorType;
@ -493,8 +493,8 @@ bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
if (ctOut) {
*ctOut = ct;
}
if (csOut) {
*csOut = cs;
if (ptOut) {
*ptOut = pt;
}
return true;
}
@ -724,9 +724,9 @@ SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) {
SkASSERT(h <= desc.fHeight);
#endif
const GrPixelConfig config = tex->config();
SkColorType ct = kUnknown_SkColorType;
SkColorType ct;
SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
if (!GrPixelConfigToColorAndColorSpace(config, &ct, nullptr)) {
if (!GrPixelConfig2ColorAndProfileType(config, &ct, nullptr)) {
ct = kUnknown_SkColorType;
}
return SkImageInfo::Make(w, h, ct, at);

View File

@ -102,7 +102,7 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&, const GrCaps&);
bool GrPixelConfigToColorAndColorSpace(GrPixelConfig, SkColorType*, sk_sp<SkColorSpace>*);
bool GrPixelConfig2ColorAndProfileType(GrPixelConfig, SkColorType*, SkColorProfileType*);
/**
* If the compressed data in the SkData is supported (as a texture format, this returns

View File

@ -13,6 +13,8 @@ DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
DEFINE_bool(dryRun, false,
"just print the tests that would be run, without actually running them.");
DEFINE_bool(forceSRGB, false, "Force SRGB for imageinfos");
DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
DEFINE_string(images, "", "List of images and/or directories to decode. A directory with no images"

View File

@ -14,6 +14,7 @@
DECLARE_bool(cpu);
DECLARE_bool(dryRun);
DECLARE_bool(forceSRGB);
DECLARE_bool(gpu);
DECLARE_string(images);
DECLARE_string(colorImages);