// around it.
static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src,
int newWidth, int newHeight, int offX, int offY) {
-
- SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight);
- sk_sp<SkSpecialSurface> surf(src->makeSurface(info));
+ // We explicitly want to operate in the source's color space here
+ SkImageFilter::OutputProperties outProps(src->getColorSpace());
+ sk_sp<SkSpecialSurface> surf(src->makeSurface(outProps, SkISize::Make(newWidth, newHeight)));
if (!surf) {
return nullptr;
}
SkIRect dstBounds;
dstRect.roundOut(&dstBounds);
- const SkImageInfo info = SkImageInfo::MakeN32Premul(dstBounds.width(), dstBounds.height());
-
- sk_sp<SkSpecialSurface> surf(input->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(input->makeSurface(ctx.outputProperties(), dstBounds.size()));
if (!surf) {
return nullptr;
}
virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0;
- virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const = 0;
+ virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const = 0;
virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0;
- virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const = 0;
+ virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const = 0;
private:
typedef SkSpecialImage INHERITED;
}
#endif
-sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const {
- return as_SIB(this)->onMakeSurface(info);
+sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const {
+ return as_SIB(this)->onMakeSurface(outProps, size, at);
}
-sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const {
- return as_SIB(this)->onMakeTightSurface(info);
+sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const {
+ return as_SIB(this)->onMakeTightSurface(outProps, size, at);
}
sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
}
#endif
- sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
+// TODO: The raster implementations of image filters all currently assume that the pixels are
+// legacy N32. Until they actually check the format and operate on sRGB or F16 data appropriately,
+// we can't enable this. (They will continue to produce incorrect results, but less-so).
+#define RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 0
+
+ sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const override {
+#if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16
+ SkColorSpace* colorSpace = outProps.colorSpace();
+#else
+ SkColorSpace* colorSpace = nullptr;
+#endif
+ SkColorType colorType = colorSpace && colorSpace->gammaIsLinear()
+ ? kRGBA_F16_SkColorType : kN32_SkColorType;
+ SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at,
+ sk_ref_sp(colorSpace));
return SkSpecialSurface::MakeRaster(info, nullptr);
}
return SkImage::MakeFromBitmap(subsetBM);
}
- sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override {
+ sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const override {
+#if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16
+ SkColorSpace* colorSpace = outProps.colorSpace();
+#else
+ SkColorSpace* colorSpace = nullptr;
+#endif
+ SkColorType colorType = colorSpace && colorSpace->gammaIsLinear()
+ ? kRGBA_F16_SkColorType : kN32_SkColorType;
+ SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at,
+ sk_ref_sp(colorSpace));
return SkSurface::MakeRaster(info);
}
return fColorSpace.get();
}
- sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
+ sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const override {
if (!fTexture->getContext()) {
return nullptr;
}
- GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps());
-
- return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(),
- info.width(), info.height(),
- config, sk_ref_sp(info.colorSpace()));
+ SkColorSpace* colorSpace = outProps.colorSpace();
+ return SkSpecialSurface::MakeRenderTarget(
+ fTexture->getContext(), size.width(), size.height(),
+ GrRenderableConfigForColorSpace(colorSpace), sk_ref_sp(colorSpace));
}
sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {
fAlphaType, subTx.get(), fColorSpace, SkBudgeted::kYes);
}
- sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override {
+ sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size, SkAlphaType at) const override {
+ SkColorSpace* colorSpace = outProps.colorSpace();
+ SkColorType colorType = colorSpace && colorSpace->gammaIsLinear()
+ ? kRGBA_F16_SkColorType : kRGBA_8888_SkColorType;
+ SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at,
+ sk_ref_sp(colorSpace));
return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::kYes, info);
}
#include "SkRefCnt.h"
#include "SkSurfaceProps.h"
-#include "SkImageInfo.h" // for SkAlphaType
+#include "SkImageFilter.h" // for OutputProperties
+#include "SkImageInfo.h" // for SkAlphaType
class GrContext;
class GrTexture;
/**
* Create a new special surface with a backend that is compatible with this special image.
*/
- sk_sp<SkSpecialSurface> makeSurface(const SkImageInfo&) const;
+ sk_sp<SkSpecialSurface> makeSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size,
+ SkAlphaType at = kPremul_SkAlphaType) const;
/**
* Create a new surface with a backend that is compatible with this special image.
* TODO: switch this to makeSurface once we resolved the naming issue
*/
- sk_sp<SkSurface> makeTightSurface(const SkImageInfo&) const;
+ sk_sp<SkSurface> makeTightSurface(const SkImageFilter::OutputProperties& outProps,
+ const SkISize& size,
+ SkAlphaType at = kPremul_SkAlphaType) const;
/**
* Extract a subset of this special image and return it as a special image.
return nullptr;
}
- SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPremul_SkAlphaType);
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
}
SkIPoint displOffset = SkIPoint::Make(0, 0);
- sk_sp<SkSpecialImage> displ(this->filterInput(0, source, ctx, &displOffset));
+ // Creation of the displacement map should happen in a non-colorspace aware context. This
+ // texture is a purely mathematical construct, so we want to just operate on the stored
+ // values. Consider:
+ // User supplies an sRGB displacement map. If we're rendering to a wider gamut, then we could
+ // end up filtering the displacement map into that gamut, which has the effect of reducing
+ // the amount of displacement that it represents (as encoded values move away from the
+ // primaries).
+ // With a more complex DAG attached to this input, it's not clear that working in ANY specific
+ // color space makes sense, so we ignore color spaces (and gamma) entirely. This may not be
+ // ideal, but it's at least consistent and predictable.
+ Context displContext(ctx.ctm(), ctx.clipBounds(), ctx.cache(), OutputProperties(nullptr));
+ sk_sp<SkSpecialImage> displ(this->filterInput(0, source, displContext, &displOffset));
if (!displ) {
return nullptr;
}
return nullptr;
}
- const SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
- kPremul_SkAlphaType);
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
const SkIRect dstIRect = dstRect.roundOut();
- // SRGBTODO: Propagate SkColorType?
- const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.height(),
- kPremul_SkAlphaType);
-
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dstIRect.size()));
if (!surf) {
return nullptr;
}
const int x0 = bounds.left();
const int y0 = bounds.top();
- SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
- kPremul_SkAlphaType);
-
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
return nullptr;
}
- SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
- kPremul_SkAlphaType);
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
return nullptr;
}
- SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
- kPremul_SkAlphaType);
-
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
SkASSERT(!bounds.isEmpty());
- SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPremul_SkAlphaType);
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
sk_sp<SkSpecialImage> localImg;
{
- const SkImageInfo info = SkImageInfo::MakeN32(localIBounds.width(), localIBounds.height(),
- kPremul_SkAlphaType);
-
- sk_sp<SkSpecialSurface> localSurface(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> localSurface(source->makeSurface(ctx.outputProperties(),
+ localIBounds.size()));
if (!localSurface) {
return;
}
}
const SkIRect dstIRect = dstRect.roundOut();
- int dstWidth = dstIRect.width();
- int dstHeight = dstIRect.height();
- if (!fSrcRect.width() || !fSrcRect.height() || !dstWidth || !dstHeight) {
+ if (!fSrcRect.width() || !fSrcRect.height() || !dstIRect.width() || !dstIRect.height()) {
return nullptr;
}
return nullptr;
}
} else {
- const SkImageInfo info = SkImageInfo::MakeN32(srcIRect.width(), srcIRect.height(),
- kPremul_SkAlphaType);
- sk_sp<SkSurface> surf(input->makeTightSurface(info));
+ sk_sp<SkSurface> surf(input->makeTightSurface(ctx.outputProperties(), srcIRect.size()));
if (!surf) {
return nullptr;
}
SkASSERT(subset->width() == srcIRect.width());
SkASSERT(subset->height() == srcIRect.height());
- const SkImageInfo info = SkImageInfo::MakeN32(dstWidth, dstHeight, kPremul_SkAlphaType);
-
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dstIRect.size()));
if (!surf) {
return nullptr;
}
}
#endif
- const SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
- kPremul_SkAlphaType);
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size()));
if (!surf) {
return nullptr;
}
//--------------
// Test that draw restricts itself to the subset
- SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlphaType);
-
- sk_sp<SkSpecialSurface> surf(img->makeSurface(info));
+ SkImageFilter::OutputProperties outProps(img->getColorSpace());
+ sk_sp<SkSpecialSurface> surf(img->makeSurface(outProps, SkISize::Make(kFullSize, kFullSize),
+ kOpaque_SkAlphaType));
SkCanvas* canvas = surf->getCanvas();
REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels(&tmpPixmap));
}
{
- SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(),
- kPremul_SkAlphaType);
- sk_sp<SkSurface> tightSurf(img->makeTightSurface(info));
+ SkImageFilter::OutputProperties outProps(img->getColorSpace());
+ sk_sp<SkSurface> tightSurf(img->makeTightSurface(outProps, subset.size()));
REPORTER_ASSERT(reporter, tightSurf->width() == subset.width());
REPORTER_ASSERT(reporter, tightSurf->height() == subset.height());