Adding color space to SkSpecialImage
Mostly means that GPU backed special images need to be supplied (and store) a color space object. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2163343002 Review-Url: https://codereview.chromium.org/2163343002
This commit is contained in:
parent
1b93bd1e6e
commit
afbf71dd92
@ -11,6 +11,7 @@
|
||||
#include "../private/SkTArray.h"
|
||||
#include "../private/SkTemplates.h"
|
||||
#include "../private/SkMutex.h"
|
||||
#include "SkColorSpace.h"
|
||||
#include "SkFilterQuality.h"
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkMatrix.h"
|
||||
@ -131,7 +132,8 @@ public:
|
||||
#if SK_SUPPORT_GPU
|
||||
static sk_sp<SkSpecialImage> DrawWithFP(GrContext* context,
|
||||
sk_sp<GrFragmentProcessor> fp,
|
||||
const SkIRect& bounds);
|
||||
const SkIRect& bounds,
|
||||
sk_sp<SkColorSpace> colorSpace);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -275,7 +275,8 @@ bool SkImageFilter::canComputeFastBounds() const {
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
|
||||
sk_sp<GrFragmentProcessor> fp,
|
||||
const SkIRect& bounds) {
|
||||
const SkIRect& bounds,
|
||||
sk_sp<SkColorSpace> colorSpace) {
|
||||
GrPaint paint;
|
||||
paint.addColorFragmentProcessor(std::move(fp));
|
||||
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
|
||||
@ -293,8 +294,9 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
|
||||
GrFixedClip clip(dstIRect);
|
||||
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
|
||||
|
||||
// TODO: Get the colorSpace from the drawContext (once it has one)
|
||||
return SkSpecialImage::MakeFromGpu(dstIRect, kNeedNewImageUniqueID_SpecialImage,
|
||||
drawContext->asTexture());
|
||||
drawContext->asTexture(), std::move(colorSpace));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
|
||||
virtual GrTexture* onPeekTexture() const { return nullptr; }
|
||||
|
||||
virtual SkColorSpace* onGetColorSpace() const = 0;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0;
|
||||
#endif
|
||||
@ -111,7 +113,8 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) {
|
||||
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resultTex->height()),
|
||||
this->uniqueID(),
|
||||
resultTex, &this->props(), at);
|
||||
resultTex, sk_ref_sp(this->getColorSpace()), &this->props(),
|
||||
at);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
@ -144,6 +147,10 @@ GrContext* SkSpecialImage::getContext() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkColorSpace* SkSpecialImage::getColorSpace() const {
|
||||
return as_SIB(this)->onGetColorSpace();
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const {
|
||||
return as_SIB(this)->onAsTextureRef(context);
|
||||
@ -187,7 +194,8 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset,
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
if (GrTexture* texture = as_IB(image)->peekTexture()) {
|
||||
return MakeFromGpu(subset, image->uniqueID(), sk_ref_sp(texture), props);
|
||||
return MakeFromGpu(subset, image->uniqueID(), sk_ref_sp(texture),
|
||||
sk_ref_sp(as_IB(image)->onImageInfo().colorSpace()), props);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@ -230,6 +238,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
SkColorSpace* onGetColorSpace() const override {
|
||||
return fBitmap.colorSpace();
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override {
|
||||
if (context) {
|
||||
@ -311,10 +323,11 @@ class SkSpecialImage_Gpu : public SkSpecialImage_Base {
|
||||
public:
|
||||
SkSpecialImage_Gpu(const SkIRect& subset,
|
||||
uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at,
|
||||
const SkSurfaceProps* props)
|
||||
sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props)
|
||||
: INHERITED(subset, uniqueID, props)
|
||||
, fTexture(std::move(tex))
|
||||
, fAlphaType(at)
|
||||
, fColorSpace(std::move(colorSpace))
|
||||
, fAddedRasterVersionToCache(false) {
|
||||
}
|
||||
|
||||
@ -334,10 +347,9 @@ public:
|
||||
SkRect dst = SkRect::MakeXYWH(x, y,
|
||||
this->subset().width(), this->subset().height());
|
||||
|
||||
// TODO: Supply correct color space after we're storing it here
|
||||
auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->height(),
|
||||
this->uniqueID(), fAlphaType, fTexture.get(),
|
||||
nullptr, SkBudgeted::kNo));
|
||||
fColorSpace, SkBudgeted::kNo));
|
||||
|
||||
canvas->drawImageRect(img, this->subset(),
|
||||
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
@ -357,7 +369,8 @@ public:
|
||||
|
||||
SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
|
||||
this->isOpaque() ? kOpaque_SkAlphaType
|
||||
: kPremul_SkAlphaType);
|
||||
: kPremul_SkAlphaType,
|
||||
fColorSpace);
|
||||
|
||||
if (!dst->tryAllocPixels(info)) {
|
||||
return false;
|
||||
@ -374,10 +387,14 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
SkColorSpace* onGetColorSpace() const override {
|
||||
return fColorSpace.get();
|
||||
}
|
||||
|
||||
bool getBitmapDeprecated(SkBitmap* result) const override {
|
||||
const SkImageInfo info = GrMakeInfoFromTexture(fTexture.get(),
|
||||
this->width(), this->height(),
|
||||
this->isOpaque());
|
||||
this->isOpaque(), fColorSpace);
|
||||
if (!result->setInfo(info)) {
|
||||
return false;
|
||||
}
|
||||
@ -405,6 +422,7 @@ public:
|
||||
return SkSpecialImage::MakeFromGpu(subset,
|
||||
this->uniqueID(),
|
||||
fTexture,
|
||||
fColorSpace,
|
||||
&this->props(),
|
||||
fAlphaType);
|
||||
}
|
||||
@ -414,10 +432,10 @@ public:
|
||||
fTexture->width() == subset.width() &&
|
||||
fTexture->height() == subset.height()) {
|
||||
// The existing GrTexture is already tight so reuse it in the SkImage
|
||||
// TODO: Supply correct color space after we're storing it here
|
||||
return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height(),
|
||||
kNeedNewImageUniqueID,
|
||||
fAlphaType, fTexture.get(), nullptr, SkBudgeted::kYes);
|
||||
fAlphaType, fTexture.get(), fColorSpace,
|
||||
SkBudgeted::kYes);
|
||||
}
|
||||
|
||||
GrContext* ctx = fTexture->getContext();
|
||||
@ -430,9 +448,8 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0));
|
||||
// TODO: Supply correct color space after we're storing it here
|
||||
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
|
||||
fAlphaType, subTx.get(), nullptr, SkBudgeted::kYes);
|
||||
fAlphaType, subTx.get(), fColorSpace, SkBudgeted::kYes);
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override {
|
||||
@ -442,6 +459,7 @@ public:
|
||||
private:
|
||||
sk_sp<GrTexture> fTexture;
|
||||
const SkAlphaType fAlphaType;
|
||||
sk_sp<SkColorSpace> fColorSpace;
|
||||
mutable SkAtomic<bool> fAddedRasterVersionToCache;
|
||||
|
||||
typedef SkSpecialImage_Base INHERITED;
|
||||
@ -450,10 +468,12 @@ private:
|
||||
sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset,
|
||||
uint32_t uniqueID,
|
||||
sk_sp<GrTexture> tex,
|
||||
sk_sp<SkColorSpace> colorSpace,
|
||||
const SkSurfaceProps* props,
|
||||
SkAlphaType at) {
|
||||
SkASSERT(rect_fits(subset, tex->width(), tex->height()));
|
||||
return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, props);
|
||||
return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
|
||||
std::move(colorSpace), props);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
int width() const { return fSubset.width(); }
|
||||
int height() const { return fSubset.height(); }
|
||||
const SkIRect& subset() const { return fSubset; }
|
||||
SkColorSpace* getColorSpace() const;
|
||||
|
||||
uint32_t uniqueID() const { return fUniqueID; }
|
||||
virtual bool isOpaque() const { return false; }
|
||||
@ -77,6 +78,7 @@ public:
|
||||
static sk_sp<SkSpecialImage> MakeFromGpu(const SkIRect& subset,
|
||||
uint32_t uniqueID,
|
||||
sk_sp<GrTexture>,
|
||||
sk_sp<SkColorSpace>,
|
||||
const SkSurfaceProps* = nullptr,
|
||||
SkAlphaType at = kPremul_SkAlphaType);
|
||||
#endif
|
||||
|
@ -137,9 +137,11 @@ public:
|
||||
~SkSpecialSurface_Gpu() override { }
|
||||
|
||||
sk_sp<SkSpecialImage> onMakeImageSnapshot() override {
|
||||
// TODO: Supply color space from fDrawContext, once it's present
|
||||
sk_sp<SkSpecialImage> tmp(SkSpecialImage::MakeFromGpu(this->subset(),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
fDrawContext->asTexture(),
|
||||
nullptr,
|
||||
&this->props()));
|
||||
fDrawContext = nullptr;
|
||||
return tmp;
|
||||
|
@ -180,7 +180,7 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage*
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DrawWithFP(context, std::move(fp), bounds);
|
||||
return DrawWithFP(context, std::move(fp), bounds, sk_ref_sp(input->getColorSpace()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -132,9 +132,11 @@ sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: Get the colorSpace from the drawContext (once it has one)
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(dstBounds.width(), dstBounds.height()),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
drawContext->asTexture(), &source->props());
|
||||
drawContext->asTexture(),
|
||||
sk_ref_sp(input->getColorSpace()), &source->props());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -346,9 +346,11 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
|
||||
|
||||
offset->fX = bounds.left();
|
||||
offset->fY = bounds.top();
|
||||
// TODO: Get the colorSpace from the drawContext (once it has one)
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
drawContext->asTexture());
|
||||
drawContext->asTexture(),
|
||||
sk_ref_sp(source->getColorSpace()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -453,9 +453,11 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
|
||||
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, bottomRight,
|
||||
kBottomRight_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
|
||||
// TODO: Get the colorSpace from the drawContext (once it has one)
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
drawContext->asTexture());
|
||||
drawContext->asTexture(),
|
||||
sk_ref_sp(source->getColorSpace()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -337,7 +337,7 @@ sk_sp<SkSpecialImage> SkMagnifierImageFilter::onFilterImage(SkSpecialImage* sour
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DrawWithFP(context, std::move(fp), bounds);
|
||||
return DrawWithFP(context, std::move(fp), bounds, sk_ref_sp(input->getColorSpace()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -328,7 +328,7 @@ sk_sp<SkSpecialImage> SkMatrixConvolutionImageFilter::onFilterImage(SkSpecialIma
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return DrawWithFP(context, std::move(fp), bounds);
|
||||
return DrawWithFP(context, std::move(fp), bounds, sk_ref_sp(input->getColorSpace()));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -519,9 +519,11 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
|
||||
srcTexture = dstDrawContext->asTexture();
|
||||
}
|
||||
|
||||
// TODO: Get the colorSpace from the drawContext (once it has one)
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height()),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
std::move(srcTexture), &input->props());
|
||||
std::move(srcTexture), sk_ref_sp(input->getColorSpace()),
|
||||
&input->props());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -252,9 +252,11 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
|
||||
matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
|
||||
drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds));
|
||||
|
||||
// TODO: Get the colorSpace from the drawContext (once it has one)
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
drawContext->asTexture());
|
||||
drawContext->asTexture(),
|
||||
sk_ref_sp(source->getColorSpace()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1240,7 +1240,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
|
||||
sk_sp<SkSpecialImage> srcImg(SkSpecialImage::MakeFromGpu(srcRect,
|
||||
bitmap.getGenerationID(),
|
||||
std::move(texture),
|
||||
std::move(texture),
|
||||
sk_ref_sp(bitmap.colorSpace()),
|
||||
&this->surfaceProps()));
|
||||
|
||||
this->drawSpecial(draw, srcImg.get(), left, top, paint);
|
||||
@ -1406,7 +1407,8 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
|
||||
|
||||
return SkSpecialImage::MakeFromGpu(bitmap.bounds(),
|
||||
bitmap.getGenerationID(),
|
||||
sk_ref_sp(texture),
|
||||
sk_ref_sp(texture),
|
||||
sk_ref_sp(bitmap.colorSpace()),
|
||||
&this->surfaceProps());
|
||||
}
|
||||
|
||||
@ -1417,7 +1419,8 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
|
||||
|
||||
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(image->width(), image->height()),
|
||||
image->uniqueID(),
|
||||
sk_ref_sp(texture),
|
||||
sk_ref_sp(texture),
|
||||
sk_ref_sp(as_IB(image)->onImageInfo().colorSpace()),
|
||||
&this->surfaceProps());
|
||||
} else if (image->peekPixels(&pm)) {
|
||||
SkBitmap bm;
|
||||
@ -1451,7 +1454,8 @@ sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
|
||||
|
||||
return SkSpecialImage::MakeFromGpu(srcRect,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
std::move(texture),
|
||||
std::move(texture),
|
||||
sk_ref_sp(ii.colorSpace()),
|
||||
&this->surfaceProps());
|
||||
}
|
||||
|
||||
|
@ -222,13 +222,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo
|
||||
|
||||
sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeFromGpu(full,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
srcTexture));
|
||||
srcTexture, nullptr));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeFromGpu(subset,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
srcTexture));
|
||||
srcTexture, nullptr));
|
||||
|
||||
test_find_existing(reporter, fullImg, subsetImg);
|
||||
test_dont_find_if_diff_key(reporter, fullImg, subsetImg);
|
||||
|
@ -187,6 +187,7 @@ static void test_texture_backed(skiatest::Reporter* reporter,
|
||||
REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID());
|
||||
REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().width() &&
|
||||
gpuBacked->subset().height() == orig->subset().height());
|
||||
REPORTER_ASSERT(reporter, gpuBacked->getColorSpace() == orig->getColorSpace());
|
||||
}
|
||||
|
||||
// Test out the SkSpecialImage::makeTextureImage entry point
|
||||
@ -236,7 +237,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo)
|
||||
SkIRect::MakeWH(kFullSize,
|
||||
kFullSize),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
std::move(texture)));
|
||||
std::move(texture), nullptr));
|
||||
|
||||
{
|
||||
sk_sp<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(context));
|
||||
@ -272,7 +273,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) {
|
||||
sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeFromGpu(
|
||||
SkIRect::MakeWH(kFullSize, kFullSize),
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
texture));
|
||||
texture, nullptr));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
@ -280,7 +281,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) {
|
||||
sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu(
|
||||
subset,
|
||||
kNeedNewImageUniqueID_SpecialImage,
|
||||
texture));
|
||||
texture, nullptr));
|
||||
test_image(subSImg1, reporter, context, true, kPad, kFullSize);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user