Delete SkColorSpaceXformImageGenerator and SkImagePriv::SkMakeImageInColorSpace
These don't seem to be used by anyone anymore so lets kill them. Bug: skia: Change-Id: I7908a9c9357e9e3b3166af9a14899dab522c3f11 Reviewed-on: https://skia-review.googlesource.com/97144 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
440f8382b0
commit
59a1df225d
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkColorSpaceXformImageGenerator.h"
|
||||
|
||||
class ColorXformImageGenGM : public skiagm::GM {
|
||||
public:
|
||||
ColorXformImageGenGM() {}
|
||||
|
||||
protected:
|
||||
|
||||
SkString onShortName() override {
|
||||
return SkString("color_xform_image_gen");
|
||||
}
|
||||
|
||||
SkISize onISize() override {
|
||||
return SkISize::Make(100, 100);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkBitmap bitmap;
|
||||
SkImageInfo info =
|
||||
SkImageInfo::MakeN32(100, 100, kOpaque_SkAlphaType, SkColorSpace::MakeSRGB());
|
||||
bitmap.allocPixels(info);
|
||||
bitmap.eraseColor(SK_ColorRED);
|
||||
bitmap.eraseArea(SkIRect::MakeWH(25, 25), SK_ColorBLUE); // We should not see any blue.
|
||||
|
||||
std::unique_ptr<SkImageGenerator> gen = SkColorSpaceXformImageGenerator::Make(
|
||||
bitmap,
|
||||
SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
||||
SkColorSpace::kRec2020_Gamut),
|
||||
kNever_SkCopyPixelsMode);
|
||||
|
||||
SkIRect subset = SkIRect::MakeXYWH(25, 25, 50, 50);
|
||||
sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen), &subset);
|
||||
canvas->drawImage(image, 25, 25);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
DEF_GM( return new ColorXformImageGenGM(); )
|
@ -85,8 +85,6 @@ skia_core_sources = [
|
||||
"$_src/core/SkColorSpaceXformCanvas.cpp",
|
||||
"$_src/core/SkColorSpaceXformer.cpp",
|
||||
"$_src/core/SkColorSpaceXformer.h",
|
||||
"$_src/core/SkColorSpaceXformImageGenerator.cpp",
|
||||
"$_src/core/SkColorSpaceXformImageGenerator.h",
|
||||
"$_src/core/SkColorSpaceXform_A2B.cpp",
|
||||
"$_src/core/SkColorSpaceXform_A2B.h",
|
||||
"$_src/core/SkColorTable.cpp",
|
||||
|
@ -335,6 +335,5 @@ gm_sources = [
|
||||
"$_gm/xfermodes.cpp",
|
||||
"$_gm/xfermodes2.cpp",
|
||||
"$_gm/xfermodes3.cpp",
|
||||
"$_gm/xform_image_gen.cpp",
|
||||
"$_gm/yuvtorgbeffect.cpp",
|
||||
]
|
||||
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkColorSpaceXformImageGenerator.h"
|
||||
|
||||
std::unique_ptr<SkImageGenerator> SkColorSpaceXformImageGenerator::Make(
|
||||
const SkBitmap& src, sk_sp<SkColorSpace> dst, SkCopyPixelsMode mode) {
|
||||
return SkColorSpaceXformImageGenerator::Make(src, dst, mode, kNeedNewImageUniqueID);
|
||||
}
|
||||
|
||||
std::unique_ptr<SkImageGenerator> SkColorSpaceXformImageGenerator::Make(
|
||||
const SkBitmap& src, sk_sp<SkColorSpace> dst, SkCopyPixelsMode mode, uint32_t id) {
|
||||
if (!dst) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const SkBitmap* srcPtr = &src;
|
||||
SkBitmap copy;
|
||||
if (kAlways_SkCopyPixelsMode == mode ||
|
||||
(kNever_SkCopyPixelsMode != mode && !src.isImmutable())) {
|
||||
if (!copy.tryAllocPixels(src.info())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkAssertResult(src.readPixels(copy.info(), copy.getPixels(), copy.rowBytes(), 0, 0));
|
||||
copy.setImmutable();
|
||||
srcPtr = ©
|
||||
}
|
||||
|
||||
return std::unique_ptr<SkImageGenerator>(
|
||||
new SkColorSpaceXformImageGenerator(*srcPtr, std::move(dst), id));
|
||||
}
|
||||
|
||||
SkColorSpaceXformImageGenerator::SkColorSpaceXformImageGenerator(const SkBitmap& src,
|
||||
sk_sp<SkColorSpace> dst,
|
||||
uint32_t id)
|
||||
: INHERITED(src.info().makeColorSpace(dst), id)
|
||||
, fSrc(src)
|
||||
, fDst(std::move(dst))
|
||||
{}
|
||||
|
||||
bool SkColorSpaceXformImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
|
||||
size_t rowBytes, const Options& opts) {
|
||||
SkImageInfo dstInfo = info;
|
||||
if (!info.colorSpace()) {
|
||||
dstInfo = dstInfo.makeColorSpace(fDst);
|
||||
}
|
||||
return fSrc.readPixels(dstInfo, pixels, rowBytes, 0, 0, opts.fBehavior);
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrClip.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrContextPriv.h"
|
||||
#include "GrPaint.h"
|
||||
#include "GrRenderTargetContext.h"
|
||||
#include "GrTextureProxy.h"
|
||||
#include "SkGr.h"
|
||||
#include "effects/GrNonlinearColorSpaceXformEffect.h"
|
||||
|
||||
sk_sp<GrTextureProxy> SkColorSpaceXformImageGenerator::onGenerateTexture(
|
||||
GrContext* ctx, const SkImageInfo& info, const SkIPoint& origin,
|
||||
SkTransferFunctionBehavior, bool willNeedMipMaps) {
|
||||
// FIXME:
|
||||
// This always operates as if SkTranferFunctionBehavior is kIgnore. Should we add
|
||||
// options so that caller can also request kRespect?
|
||||
|
||||
SkASSERT(ctx);
|
||||
|
||||
sk_sp<GrTextureProxy> proxy = GrUploadBitmapToTextureProxy(ctx->contextPriv().proxyProvider(),
|
||||
fSrc, nullptr);
|
||||
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkColorSpace> srcSpace =
|
||||
fSrc.colorSpace() ? sk_ref_sp(fSrc.colorSpace()) : SkColorSpace::MakeSRGB();
|
||||
auto xform = GrNonlinearColorSpaceXformEffect::Make(srcSpace.get(), fDst.get());
|
||||
if (!xform) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrMipMapped mipMapped = willNeedMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
|
||||
|
||||
sk_sp<GrRenderTargetContext> renderTargetContext = ctx->makeDeferredRenderTargetContext(
|
||||
SkBackingFit::kExact, info.width(), info.height(), kRGBA_8888_GrPixelConfig, nullptr,
|
||||
0, mipMapped, kTopLeft_GrSurfaceOrigin);
|
||||
if (!renderTargetContext) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrPaint paint;
|
||||
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
||||
paint.addColorTextureProcessor(std::move(proxy), SkMatrix::MakeTrans(origin.fX, origin.fY));
|
||||
paint.addColorFragmentProcessor(std::move(xform));
|
||||
|
||||
const SkRect rect = SkRect::MakeWH(info.width(), info.height());
|
||||
renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), rect);
|
||||
return sk_ref_sp(renderTargetContext->asTextureProxy());
|
||||
}
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkColorSpaceXformImageGenerator_DEFINED
|
||||
#define SkColorSpaceXformImageGenerator_DEFINED
|
||||
|
||||
#include "SkImageGenerator.h"
|
||||
#include "SkImagePriv.h"
|
||||
|
||||
class SkColorSpaceXformImageGenerator : public SkImageGenerator {
|
||||
public:
|
||||
|
||||
static std::unique_ptr<SkImageGenerator> Make(
|
||||
const SkBitmap& src, sk_sp<SkColorSpace> dst, SkCopyPixelsMode);
|
||||
|
||||
protected:
|
||||
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||
const Options& opts) override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&,
|
||||
SkTransferFunctionBehavior,
|
||||
bool willNeedMipMaps) override;
|
||||
TexGenType onCanGenerateTexture() const override {
|
||||
return TexGenType::kExpensive;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
SkBitmap fSrc;
|
||||
sk_sp<SkColorSpace> fDst;
|
||||
|
||||
static std::unique_ptr<SkImageGenerator> Make(
|
||||
const SkBitmap& src, sk_sp<SkColorSpace> dst, SkCopyPixelsMode, uint32_t id);
|
||||
SkColorSpaceXformImageGenerator(const SkBitmap& src, sk_sp<SkColorSpace> dst, uint32_t id);
|
||||
|
||||
friend sk_sp<SkImage> SkMakeImageInColorSpace(const SkBitmap&, sk_sp<SkColorSpace>, uint32_t,
|
||||
SkCopyPixelsMode);
|
||||
typedef SkImageGenerator INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkColorSpaceXformImageGenerator_DEFINED
|
@ -45,19 +45,6 @@ sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode, SkSh
|
||||
*/
|
||||
extern SK_API sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsMode);
|
||||
|
||||
/**
|
||||
* Similar to SkMakeImageFromRasterBitmap, this wraps a |src| bitmap in an image.
|
||||
*
|
||||
* It also promises to transform the bitmap into the |dst| color space before it
|
||||
* is drawn. The transform will happen lazily.
|
||||
*
|
||||
* If |id| is non-zero, the output image will use that as its unique id. Otherwise,
|
||||
* it will generate a new id.
|
||||
*/
|
||||
extern sk_sp<SkImage> SkMakeImageInColorSpace(const SkBitmap& src, sk_sp<SkColorSpace> dst,
|
||||
uint32_t id,
|
||||
SkCopyPixelsMode = kNever_SkCopyPixelsMode);
|
||||
|
||||
// Given an image created from SkNewImageFromBitmap, return its pixelref. This
|
||||
// may be called to see if the surface and the image share the same pixelref,
|
||||
// in which case the surface may need to perform a copy-on-write.
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "SkBitmapProcShader.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorSpaceXform_Base.h"
|
||||
#include "SkColorSpaceXformImageGenerator.h"
|
||||
#include "SkColorSpaceXformPriv.h"
|
||||
#include "SkColorTable.h"
|
||||
#include "SkConvertPixels.h"
|
||||
@ -324,35 +323,6 @@ sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode
|
||||
return SkMakeImageFromRasterBitmapPriv(bm, cpm, kNeedNewImageUniqueID);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkMakeImageInColorSpace(const SkBitmap& bm, sk_sp<SkColorSpace> dstCS, uint32_t id,
|
||||
SkCopyPixelsMode cpm) {
|
||||
if (!SkImageInfoIsValidAllowNumericalCS(bm.info()) || !bm.getPixels() ||
|
||||
bm.rowBytes() < bm.info().minRowBytes() || !dstCS) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkColorSpace> srcCS = bm.info().refColorSpace();
|
||||
if (!srcCS) {
|
||||
// Treat nullptr as sRGB.
|
||||
srcCS = SkColorSpace::MakeSRGB();
|
||||
}
|
||||
|
||||
sk_sp<SkImage> image = nullptr;
|
||||
|
||||
// For the Android use case, this is very likely to be true.
|
||||
if (SkColorSpace::Equals(srcCS.get(), dstCS.get())) {
|
||||
SkASSERT(kNeedNewImageUniqueID == id || bm.getGenerationID() == id);
|
||||
image = SkMakeImageFromRasterBitmapPriv(bm, cpm, id);
|
||||
} else {
|
||||
image = SkImage::MakeFromGenerator(SkColorSpaceXformImageGenerator::Make(bm, dstCS, cpm,
|
||||
id));
|
||||
}
|
||||
|
||||
// If the caller suplied an id, we must propagate that to the image we return
|
||||
SkASSERT(kNeedNewImageUniqueID == id || image->uniqueID() == id);
|
||||
return image;
|
||||
}
|
||||
|
||||
const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
|
||||
return ((const SkImage_Raster*)image)->getPixelRef();
|
||||
}
|
||||
|
@ -110,46 +110,3 @@ DEF_TEST(PictureImageGenerator, reporter) {
|
||||
}
|
||||
}
|
||||
|
||||
#include "SkImagePriv.h"
|
||||
|
||||
DEF_TEST(ColorXformGenerator, r) {
|
||||
SkBitmap a, b, c, d, e;
|
||||
SkImageInfo info = SkImageInfo::MakeS32(1, 1, kPremul_SkAlphaType);
|
||||
a.allocPixels(info);
|
||||
b.allocPixels(info.makeColorSpace(nullptr));
|
||||
c.allocPixels(info.makeColorSpace(SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
||||
SkColorSpace::kRec2020_Gamut)));
|
||||
d.allocPixels(info.makeColorSpace(SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
||||
SkColorSpace::kAdobeRGB_Gamut)));
|
||||
e.allocPixels(info);
|
||||
a.eraseColor(0);
|
||||
b.eraseColor(1);
|
||||
c.eraseColor(2);
|
||||
d.eraseColor(3);
|
||||
e.eraseColor(4);
|
||||
|
||||
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
|
||||
sk_sp<SkImage> ia = SkMakeImageInColorSpace(a, srgb, 0);
|
||||
sk_sp<SkImage> ib = SkMakeImageInColorSpace(b, srgb, b.getGenerationID());
|
||||
sk_sp<SkImage> ic = SkMakeImageInColorSpace(c, srgb, c.getGenerationID());
|
||||
sk_sp<SkImage> id = SkMakeImageInColorSpace(d, srgb, 0);
|
||||
sk_sp<SkImage> ie = SkMakeImageInColorSpace(e, srgb, e.getGenerationID(),
|
||||
kAlways_SkCopyPixelsMode);
|
||||
|
||||
// Equal because sRGB->sRGB is a no-op.
|
||||
REPORTER_ASSERT(r, ia->uniqueID() == a.getGenerationID());
|
||||
|
||||
// Equal because nullptr->sRGB is a no-op (nullptr is treated as sRGB), and because
|
||||
// we pass the explicit id that we want. In the no-op case, the implementation
|
||||
// actually asserts that if we pass an id, it must match the id on the bitmap.
|
||||
REPORTER_ASSERT(r, ib->uniqueID() == b.getGenerationID());
|
||||
|
||||
// Equal because we pass in an explicit id.
|
||||
REPORTER_ASSERT(r, ic->uniqueID() == c.getGenerationID());
|
||||
|
||||
// Not equal because sRGB->Adobe is not a no-op and we do not pass an explicit id.
|
||||
REPORTER_ASSERT(r, id->uniqueID() != d.getGenerationID());
|
||||
|
||||
// Equal because we pass in an explicit id. Forcing a copy, but still want the id respected.
|
||||
REPORTER_ASSERT(r, ie->uniqueID() == e.getGenerationID());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user