remove legacy code for resolution
Bug: skia: Change-Id: I6909325d4ee51140ec0edb47682de18617c23cc7 Reviewed-on: https://skia-review.googlesource.com/70100 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
66498bc416
commit
48723156c5
@ -28,11 +28,6 @@ public:
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)
|
||||
|
||||
protected:
|
||||
enum PictureResolution {
|
||||
kDeviceSpace_PictureResolution,
|
||||
kLocalSpace_PictureResolution
|
||||
};
|
||||
|
||||
/* Constructs an SkPictureImageFilter object from an SkReadBuffer.
|
||||
* Note: If the SkPictureImageFilter object construction requires bitmap
|
||||
* decoding, the decoder must be set on the SkReadBuffer parameter by calling
|
||||
@ -46,21 +41,10 @@ protected:
|
||||
|
||||
private:
|
||||
explicit SkPictureImageFilter(sk_sp<SkPicture> picture);
|
||||
SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
|
||||
PictureResolution, SkFilterQuality, sk_sp<SkColorSpace>);
|
||||
SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect, sk_sp<SkColorSpace>);
|
||||
|
||||
void drawPictureAtDeviceResolution(SkCanvas* canvas,
|
||||
const SkIRect& deviceBounds,
|
||||
const Context&) const;
|
||||
void drawPictureAtLocalResolution(SkSpecialImage* source,
|
||||
SkCanvas*,
|
||||
const SkIRect& deviceBounds,
|
||||
const Context&) const;
|
||||
|
||||
sk_sp<SkPicture> fPicture;
|
||||
SkRect fCropRect;
|
||||
PictureResolution fPictureResolution;
|
||||
SkFilterQuality fFilterQuality;
|
||||
sk_sp<SkPicture> fPicture;
|
||||
SkRect fCropRect;
|
||||
|
||||
// Should never be set by a public constructor. This is only used when onMakeColorSpace()
|
||||
// forces a deferred color space xform.
|
||||
|
@ -399,3 +399,19 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
|
||||
}
|
||||
return obj.release();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int32_t SkReadBuffer::checkInt(int32_t min, int32_t max) {
|
||||
SkASSERT(min <= max);
|
||||
int32_t value = this->read32();
|
||||
if (value < min || value > max) {
|
||||
this->validate(false);
|
||||
value = min;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
SkFilterQuality SkReadBuffer::checkFilterQuality() {
|
||||
return this->checkRange<SkFilterQuality>(kNone_SkFilterQuality, kLast_SkFilterQuality);
|
||||
}
|
||||
|
@ -224,7 +224,18 @@ public:
|
||||
SkInflator* getInflator() const { return fInflator; }
|
||||
void setInflator(SkInflator* inf) { fInflator = inf; }
|
||||
|
||||
// sk_sp<SkImage> inflateImage();
|
||||
// Utilities that mark the buffer invalid if the requested value is out-of-range
|
||||
|
||||
// If the read value is outside of the range, validate(false) is called, and min
|
||||
// is returned, else the value is returned.
|
||||
int32_t checkInt(int min, int max);
|
||||
|
||||
template <typename T> T checkRange(T min, T max) {
|
||||
return static_cast<T>(this->checkInt(static_cast<int32_t>(min),
|
||||
static_cast<int32_t>(max)));
|
||||
}
|
||||
|
||||
SkFilterQuality checkFilterQuality();
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorSpaceXformCanvas.h"
|
||||
#include "SkColorSpaceXformer.h"
|
||||
#include "SkImageSource.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkSpecialSurface.h"
|
||||
@ -22,33 +23,35 @@ sk_sp<SkImageFilter> SkPictureImageFilter::Make(sk_sp<SkPicture> picture) {
|
||||
|
||||
sk_sp<SkImageFilter> SkPictureImageFilter::Make(sk_sp<SkPicture> picture,
|
||||
const SkRect& cropRect) {
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture),
|
||||
cropRect,
|
||||
kDeviceSpace_PictureResolution,
|
||||
kLow_SkFilterQuality,
|
||||
nullptr));
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture), cropRect, nullptr));
|
||||
}
|
||||
|
||||
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
|
||||
: INHERITED(nullptr, 0, nullptr)
|
||||
, fPicture(std::move(picture))
|
||||
, fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty())
|
||||
, fPictureResolution(kDeviceSpace_PictureResolution)
|
||||
, fFilterQuality(kLow_SkFilterQuality) {
|
||||
, fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty()) {
|
||||
}
|
||||
|
||||
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
|
||||
PictureResolution pictureResolution,
|
||||
SkFilterQuality filterQuality,
|
||||
sk_sp<SkColorSpace> colorSpace)
|
||||
: INHERITED(nullptr, 0, nullptr)
|
||||
, fPicture(std::move(picture))
|
||||
, fCropRect(cropRect)
|
||||
, fPictureResolution(pictureResolution)
|
||||
, fFilterQuality(filterQuality)
|
||||
, fColorSpace(std::move(colorSpace)) {
|
||||
}
|
||||
|
||||
enum PictureResolution {
|
||||
kDeviceSpace_PictureResolution,
|
||||
kLocalSpace_PictureResolution
|
||||
};
|
||||
static sk_sp<SkImageFilter> make_localspace_filter(sk_sp<SkPicture> pic, const SkRect& cropRect,
|
||||
SkFilterQuality fq) {
|
||||
SkISize dim = { SkScalarRoundToInt(cropRect.width()), SkScalarRoundToInt(cropRect.height()) };
|
||||
auto img = SkImage::MakeFromPicture(std::move(pic), dim, nullptr, nullptr,
|
||||
SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB());
|
||||
return SkImageSource::Make(img, cropRect, cropRect, fq);
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
sk_sp<SkPicture> picture;
|
||||
SkRect cropRect;
|
||||
@ -62,24 +65,15 @@ sk_sp<SkFlattenable> SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
}
|
||||
buffer.readRect(&cropRect);
|
||||
|
||||
// NOTE: these two fields can be removed from the class once we have out-lived the need
|
||||
// to load pictures older than SkReadBuffer::kRemovePictureImageFilterLocalSpace
|
||||
//
|
||||
PictureResolution pictureResolution = kDeviceSpace_PictureResolution;
|
||||
SkFilterQuality filterQuality = kNone_SkFilterQuality;
|
||||
|
||||
if (buffer.isVersionLT(SkReadBuffer::kRemovePictureImageFilterLocalSpace)) {
|
||||
pictureResolution = (PictureResolution)buffer.readInt();
|
||||
PictureResolution pictureResolution = buffer.checkRange<PictureResolution>(
|
||||
kDeviceSpace_PictureResolution, kLocalSpace_PictureResolution);
|
||||
if (kLocalSpace_PictureResolution == pictureResolution) {
|
||||
//filterLevel is only serialized if pictureResolution is LocalSpace
|
||||
filterQuality = (SkFilterQuality)buffer.readInt();
|
||||
return make_localspace_filter(std::move(picture), cropRect,
|
||||
buffer.checkFilterQuality());
|
||||
}
|
||||
}
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(picture,
|
||||
cropRect,
|
||||
pictureResolution,
|
||||
filterQuality,
|
||||
nullptr));
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(picture, cropRect, nullptr));
|
||||
}
|
||||
|
||||
void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
@ -120,12 +114,16 @@ sk_sp<SkSpecialImage> SkPictureImageFilter::onFilterImage(SkSpecialImage* source
|
||||
SkASSERT(canvas);
|
||||
canvas->clear(0x0);
|
||||
|
||||
if (kDeviceSpace_PictureResolution == fPictureResolution ||
|
||||
0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
|
||||
this->drawPictureAtDeviceResolution(canvas, bounds, ctx);
|
||||
} else {
|
||||
this->drawPictureAtLocalResolution(source, canvas, bounds, ctx);
|
||||
std::unique_ptr<SkCanvas> xformCanvas;
|
||||
if (fColorSpace) {
|
||||
// Only non-null in the case where onMakeColorSpace() was called. This instructs
|
||||
// us to do the color space xform on playback.
|
||||
xformCanvas = SkCreateColorSpaceXformCanvas(canvas, fColorSpace);
|
||||
canvas = xformCanvas.get();
|
||||
}
|
||||
canvas->translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop));
|
||||
canvas->concat(ctx.ctm());
|
||||
canvas->drawPicture(fPicture);
|
||||
|
||||
offset->fX = bounds.fLeft;
|
||||
offset->fY = bounds.fTop;
|
||||
@ -138,80 +136,7 @@ sk_sp<SkImageFilter> SkPictureImageFilter::onMakeColorSpace(SkColorSpaceXformer*
|
||||
return this->refMe();
|
||||
}
|
||||
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(fPicture, fCropRect, fPictureResolution,
|
||||
fFilterQuality, std::move(dstCS)));
|
||||
}
|
||||
|
||||
void SkPictureImageFilter::drawPictureAtDeviceResolution(SkCanvas* canvas,
|
||||
const SkIRect& deviceBounds,
|
||||
const Context& ctx) const {
|
||||
std::unique_ptr<SkCanvas> xformCanvas = nullptr;
|
||||
if (fColorSpace) {
|
||||
// Only non-null in the case where onMakeColorSpace() was called. This instructs
|
||||
// us to do the color space xform on playback.
|
||||
xformCanvas = SkCreateColorSpaceXformCanvas(canvas, fColorSpace);
|
||||
canvas = xformCanvas.get();
|
||||
}
|
||||
canvas->translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
|
||||
canvas->concat(ctx.ctm());
|
||||
canvas->drawPicture(fPicture);
|
||||
}
|
||||
|
||||
void SkPictureImageFilter::drawPictureAtLocalResolution(SkSpecialImage* source,
|
||||
SkCanvas* canvas,
|
||||
const SkIRect& deviceBounds,
|
||||
const Context& ctx) const {
|
||||
SkMatrix inverseCtm;
|
||||
if (!ctx.ctm().invert(&inverseCtm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkRect localBounds = SkRect::Make(ctx.clipBounds());
|
||||
inverseCtm.mapRect(&localBounds);
|
||||
if (!localBounds.intersect(fCropRect)) {
|
||||
return;
|
||||
}
|
||||
SkIRect localIBounds = localBounds.roundOut();
|
||||
|
||||
sk_sp<SkSpecialImage> localImg;
|
||||
{
|
||||
sk_sp<SkSpecialSurface> localSurface(source->makeSurface(ctx.outputProperties(),
|
||||
localIBounds.size()));
|
||||
if (!localSurface) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkCanvas* localCanvas = localSurface->getCanvas();
|
||||
SkASSERT(localCanvas);
|
||||
std::unique_ptr<SkCanvas> xformCanvas = nullptr;
|
||||
if (fColorSpace) {
|
||||
// Only non-null in the case where onMakeColorSpace() was called. This instructs
|
||||
// us to do the color space xform on playback.
|
||||
xformCanvas = SkCreateColorSpaceXformCanvas(localCanvas, fColorSpace);
|
||||
localCanvas = xformCanvas.get();
|
||||
}
|
||||
|
||||
localCanvas->clear(0x0);
|
||||
|
||||
localCanvas->translate(-SkIntToScalar(localIBounds.fLeft),
|
||||
-SkIntToScalar(localIBounds.fTop));
|
||||
localCanvas->drawPicture(fPicture);
|
||||
|
||||
localImg = localSurface->makeImageSnapshot();
|
||||
SkASSERT(localImg);
|
||||
}
|
||||
|
||||
{
|
||||
canvas->translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
|
||||
canvas->concat(ctx.ctm());
|
||||
SkPaint paint;
|
||||
paint.setFilterQuality(fFilterQuality);
|
||||
|
||||
localImg->draw(canvas,
|
||||
SkIntToScalar(localIBounds.fLeft),
|
||||
SkIntToScalar(localIBounds.fTop),
|
||||
&paint);
|
||||
}
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(fPicture, fCropRect, std::move(dstCS)));
|
||||
}
|
||||
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
|
Loading…
Reference in New Issue
Block a user