4868e6b221
Fixed rendering of shadows under bitmaps. Added an option to SkBlurMask to produce higher quality blurs. The HQ blur option is propagated through SkBlurDrawLooper so that it can be invoked by WebKit for drawing shadows. Added a shadow rendering test to gm. Bugs fixed: 146, 150 Related Chromium bugs: 11153, 42654 Code review: http://codereview.appspot.com/4174049 git-svn-id: http://skia.googlecode.com/svn/trunk@818 2bbb7eff-a529-9590-31e7-b0007b416f81
100 lines
3.3 KiB
C++
100 lines
3.3 KiB
C++
#include "gm.h"
|
|
#include "SkPicture.h"
|
|
#include "SkRectShape.h"
|
|
#include "SkBlurDrawLooper.h"
|
|
|
|
namespace skiagm {
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class ShadowsGM : public GM {
|
|
|
|
public:
|
|
SkPath fCirclePath;
|
|
SkPaint fPaint;
|
|
SkRectShape fRectShape;
|
|
ShadowsGM() {
|
|
fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
|
|
fPaint.setStrokeWidth(SkIntToScalar(4));
|
|
fPaint.setAntiAlias(true);
|
|
fPaint.setColor(0xFF00FF00);
|
|
fPaint.setStyle(SkPaint::kStroke_Style);
|
|
SkRect rect;
|
|
rect.set(SkIntToScalar(10), SkIntToScalar(10),
|
|
SkIntToScalar(30), SkIntToScalar(30));
|
|
fRectShape.setRect(rect);
|
|
fRectShape.paint().setColor(SK_ColorRED);
|
|
}
|
|
|
|
virtual ~ShadowsGM() {
|
|
}
|
|
|
|
protected:
|
|
virtual SkString onShortName() {
|
|
return SkString("shadows");
|
|
}
|
|
|
|
virtual SkISize onISize() {
|
|
return make_isize(200, 80);
|
|
}
|
|
|
|
void drawBG(SkCanvas* canvas) {
|
|
canvas->drawColor(0xFFDDDDDD);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
this->drawBG(canvas);
|
|
|
|
SkBlurDrawLooper* shadowLoopers[5];
|
|
shadowLoopers[0] =
|
|
new SkBlurDrawLooper (10, 5, 10, 0xFF0000FF,
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag |
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag );
|
|
SkAutoUnref aurL0(shadowLoopers[0]);
|
|
shadowLoopers[1] =
|
|
new SkBlurDrawLooper (10, 5, 10, 0xFF0000FF,
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag );
|
|
SkAutoUnref aurL1(shadowLoopers[1]);
|
|
shadowLoopers[2] =
|
|
new SkBlurDrawLooper (5, 5, 10, 0xFF000000,
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag );
|
|
SkAutoUnref aurL2(shadowLoopers[2]);
|
|
shadowLoopers[3] =
|
|
new SkBlurDrawLooper (5, -5 ,-10, 0x7FFF0000,
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag |
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag );
|
|
SkAutoUnref aurL3(shadowLoopers[3]);
|
|
shadowLoopers[4] =
|
|
new SkBlurDrawLooper (0, 5, 5, 0xFF000000,
|
|
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
|
|
SkBlurDrawLooper::kOverrideColor_BlurFlag |
|
|
SkBlurDrawLooper::kHighQuality_BlurFlag );
|
|
SkAutoUnref aurL4(shadowLoopers[4]);
|
|
|
|
for (int looper = 0; looper < 5; looper ++)
|
|
{
|
|
fRectShape.paint().setLooper(shadowLoopers[looper]);
|
|
canvas->resetMatrix();
|
|
canvas->translate(SkIntToScalar(looper*40), SkIntToScalar(0));
|
|
canvas->drawShape(&fRectShape);
|
|
fPaint.setLooper(shadowLoopers[looper]);
|
|
canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
|
|
canvas->drawPath(fCirclePath, fPaint);
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
static GM* MyFactory(void*) { return new ShadowsGM; }
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
}
|