This change makes SkImageFilter and SkBlurImageFilter flattenable/unflattenable.
The imageblur test also needed to stop calling getDeviceSize(), since it was returning 99999x99999 for the SkPicture case. git-svn-id: http://skia.googlecode.com/svn/trunk@2699 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
da957724d2
commit
54e01b2ab9
@ -8,6 +8,9 @@
|
||||
#include "gm.h"
|
||||
#include "SkBlurImageFilter.h"
|
||||
|
||||
#define WIDTH 500
|
||||
#define HEIGHT 500
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
class ImageBlurGM : public GM {
|
||||
@ -22,22 +25,19 @@ protected:
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
return make_isize(500, 500);
|
||||
return make_isize(WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref();
|
||||
canvas->saveLayer(NULL, &paint);
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
paint.setTextSize(100);
|
||||
paint.setAntiAlias(true);
|
||||
const char* str = "The quick brown fox jumped over the lazy dog.";
|
||||
srand(1234);
|
||||
SkISize size = canvas->getDeviceSize();
|
||||
for (int i = 0; i < 25; ++i) {
|
||||
int x = rand() % size.fWidth;
|
||||
int y = rand() % size.fHeight;
|
||||
int x = rand() % WIDTH;
|
||||
int y = rand() % HEIGHT;
|
||||
paint.setColor(rand() % 0x1000000 | 0xFF000000);
|
||||
paint.setTextSize(rand() % 300);
|
||||
canvas->drawText(str, strlen(str), x, y, paint);
|
||||
|
@ -25,7 +25,7 @@ struct SkPoint;
|
||||
*
|
||||
* If the imagefilter returns false, nothing is drawn.
|
||||
*/
|
||||
class SK_API SkImageFilter : public SkRefCnt /*SkFlattenable*/ {
|
||||
class SK_API SkImageFilter : public SkFlattenable {
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -53,11 +53,13 @@ public:
|
||||
virtual bool asABlur(SkSize* sigma) const;
|
||||
|
||||
protected:
|
||||
SkImageFilter() {}
|
||||
explicit SkImageFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
|
||||
virtual bool onFilterImage(const SkBitmap& src, const SkMatrix&,
|
||||
SkBitmap* result, SkIPoint* offset);
|
||||
|
||||
private:
|
||||
typedef SkRefCnt INHERITED;
|
||||
typedef SkFlattenable INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -15,8 +15,16 @@ class SK_API SkBlurImageFilter : public SkImageFilter {
|
||||
public:
|
||||
SkBlurImageFilter(SkScalar sigmaX, SkScalar sigmaY);
|
||||
virtual bool asABlur(SkSize* sigma) const;
|
||||
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
|
||||
return SkNEW_ARGS(SkBlurImageFilter, (buffer));
|
||||
}
|
||||
protected:
|
||||
explicit SkBlurImageFilter(SkFlattenableReadBuffer& buffer);
|
||||
virtual void flatten(SkFlattenableWriteBuffer& buffer);
|
||||
virtual Factory getFactory() { return CreateProc; }
|
||||
private:
|
||||
SkSize fSigma;
|
||||
typedef SkImageFilter INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1592,7 +1592,8 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
asint(this->getMaskFilter()) |
|
||||
asint(this->getColorFilter()) |
|
||||
asint(this->getRasterizer()) |
|
||||
asint(this->getLooper())) {
|
||||
asint(this->getLooper()) |
|
||||
asint(this->getImageFilter())) {
|
||||
flatFlags |= kHasEffects_FlatFlag;
|
||||
}
|
||||
|
||||
@ -1628,6 +1629,7 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
buffer.writeFlattenable(this->getColorFilter());
|
||||
buffer.writeFlattenable(this->getRasterizer());
|
||||
buffer.writeFlattenable(this->getLooper());
|
||||
buffer.writeFlattenable(this->getImageFilter());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1677,6 +1679,7 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
|
||||
SkSafeUnref(this->setColorFilter((SkColorFilter*) buffer.readFlattenable()));
|
||||
SkSafeUnref(this->setRasterizer((SkRasterizer*) buffer.readFlattenable()));
|
||||
SkSafeUnref(this->setLooper((SkDrawLooper*) buffer.readFlattenable()));
|
||||
SkSafeUnref(this->setImageFilter((SkImageFilter*) buffer.readFlattenable()));
|
||||
} else {
|
||||
this->setPathEffect(NULL);
|
||||
this->setShader(NULL);
|
||||
@ -1685,6 +1688,7 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
|
||||
this->setColorFilter(NULL);
|
||||
this->setRasterizer(NULL);
|
||||
this->setLooper(NULL);
|
||||
this->setImageFilter(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,12 @@
|
||||
|
||||
#include "SkBlurImageFilter.h"
|
||||
|
||||
SkBlurImageFilter::SkBlurImageFilter(SkFlattenableReadBuffer& buffer)
|
||||
: INHERITED(buffer) {
|
||||
fSigma.fWidth = buffer.readScalar();
|
||||
fSigma.fHeight = buffer.readScalar();
|
||||
}
|
||||
|
||||
SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, SkScalar sigmaY)
|
||||
: fSigma(SkSize::Make(sigmaX, sigmaY)) {
|
||||
SkASSERT(sigmaX >= 0 && sigmaY >= 0);
|
||||
@ -16,3 +22,12 @@ bool SkBlurImageFilter::asABlur(SkSize* sigma) const {
|
||||
*sigma = fSigma;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkBlurImageFilter::flatten(SkFlattenableWriteBuffer& buffer) {
|
||||
this->INHERITED::flatten(buffer);
|
||||
buffer.writeScalar(fSigma.fWidth);
|
||||
buffer.writeScalar(fSigma.fHeight);
|
||||
}
|
||||
|
||||
static SkFlattenable::Registrar
|
||||
gSrcColorFilterReg("SkBlurImageFilter", SkBlurImageFilter::CreateProc);
|
||||
|
Loading…
Reference in New Issue
Block a user