update srcmode GM to include aa/bw and gradients
add 'G' key to sampleapp, to toggle showing the GM's bounds as an overlay
git-svn-id: http://skia.googlecode.com/svn/trunk@6431 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp
index 3aa1b57..5ac102e 100644
--- a/gm/srcmode.cpp
+++ b/gm/srcmode.cpp
@@ -7,10 +7,23 @@
#include "gm.h"
#include "SkCanvas.h"
+#include "SkGradientShader.h"
-#define W SkIntToScalar(100)
+#define W SkIntToScalar(80)
#define H SkIntToScalar(60)
+typedef void (*PaintProc)(SkPaint*);
+
+static void identity_paintproc(SkPaint* paint) {}
+static void gradient_paintproc(SkPaint* paint) {
+ const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
+ const SkPoint pts[] = { { 0, 0 }, { W, H } };
+ SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL,
+ SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
+ paint->setShader(s)->unref();
+}
+
typedef void (*Proc)(SkCanvas*, const SkPaint&);
static void draw_hair(SkCanvas* canvas, const SkPaint& paint) {
@@ -36,7 +49,7 @@
static void draw_text(SkCanvas* canvas, const SkPaint& paint) {
SkPaint p(paint);
p.setTextSize(H/4);
- canvas->drawText("Hamburgefons", 12, 0, H*2/3, p);
+ canvas->drawText("Hamburge", 8, 0, H*2/3, p);
}
class SrcModeGM : public skiagm::GM {
@@ -52,14 +65,13 @@
}
virtual SkISize onISize() {
- return SkISize::Make(640, 480);
+ return SkISize::Make(640, 760);
}
virtual void onDraw(SkCanvas* canvas) {
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
SkPaint paint;
- paint.setAntiAlias(true);
paint.setColor(0x80FF0000);
const Proc procs[] = {
@@ -70,15 +82,28 @@
SkXfermode::kSrcOver_Mode, SkXfermode::kSrc_Mode, SkXfermode::kClear_Mode
};
- for (size_t x = 0; x < SK_ARRAY_COUNT(modes); ++x) {
- paint.setXfermodeMode(modes[x]);
+ const PaintProc paintProcs[] = {
+ identity_paintproc, gradient_paintproc
+ };
+
+ for (int aa = 0; aa <= 1; ++aa) {
+ paint.setAntiAlias(SkToBool(aa));
canvas->save();
- for (size_t y = 0; y < SK_ARRAY_COUNT(procs); ++y) {
- procs[y](canvas, paint);
- canvas->translate(0, H * 5 / 4);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(paintProcs); ++i) {
+ paintProcs[i](&paint);
+ for (size_t x = 0; x < SK_ARRAY_COUNT(modes); ++x) {
+ paint.setXfermodeMode(modes[x]);
+ canvas->save();
+ for (size_t y = 0; y < SK_ARRAY_COUNT(procs); ++y) {
+ procs[y](canvas, paint);
+ canvas->translate(0, H * 5 / 4);
+ }
+ canvas->restore();
+ canvas->translate(W * 5 / 4, 0);
+ }
}
canvas->restore();
- canvas->translate(W * 5 / 4, 0);
+ canvas->translate(0, (H * 5 / 4) * SK_ARRAY_COUNT(procs));
}
}
diff --git a/samplecode/GMSampleView.h b/samplecode/GMSampleView.h
index 0b224a5..5c7729a 100644
--- a/samplecode/GMSampleView.h
+++ b/samplecode/GMSampleView.h
@@ -15,16 +15,23 @@
class GMSampleView : public SampleView {
private:
+ bool fShowSize;
typedef skiagm::GM GM;
public:
GMSampleView(GM* gm)
- : fGM(gm) {}
+ : fGM(gm), fShowSize(false) {}
virtual ~GMSampleView() {
delete fGM;
}
+ static SkEvent* NewShowSizeEvt(bool doShowSize) {
+ SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize"));
+ evt->setFast32(doShowSize);
+ return evt;
+ }
+
protected:
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
@@ -35,9 +42,28 @@
}
return this->INHERITED::onQuery(evt);
}
+
+ virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE {
+ if (evt.isType("GMSampleView::showSize")) {
+ fShowSize = SkToBool(evt.getFast32());
+ return true;
+ }
+ return this->INHERITED::onEvent(evt);
+ }
virtual void onDrawContent(SkCanvas* canvas) {
- fGM->drawContent(canvas);
+ {
+ SkAutoCanvasRestore acr(canvas, fShowSize);
+ fGM->drawContent(canvas);
+ }
+ if (fShowSize) {
+ SkISize size = fGM->getISize();
+ SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
+ SkIntToScalar(size.height()));
+ SkPaint paint;
+ paint.setColor(0x40FF8833);
+ canvas->drawRect(r, paint);
+ }
}
virtual void onDrawBackground(SkCanvas* canvas) {
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 5ff1b4e..c94a772 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -92,6 +92,8 @@
static SampleWindow* gSampleWindow;
+static bool gShowGMBounds;
+
static void postEventToSink(SkEvent* evt, SkEventSink* sink) {
evt->setTargetID(sink->getSinkID())->post();
}
@@ -1731,6 +1733,8 @@
}
#endif
+//extern bool gIgnoreFastBlurRect;
+
bool SampleWindow::onHandleChar(SkUnichar uni) {
{
SkView* view = curr_view(this);
@@ -1773,6 +1777,11 @@
}
switch (uni) {
+ case 'B':
+// gIgnoreFastBlurRect = !gIgnoreFastBlurRect;
+ this->inval(NULL);
+ break;
+
case 'f':
// only
toggleFPS();
@@ -1781,6 +1790,12 @@
fRequestGrabImage = true;
this->inval(NULL);
break;
+ case 'G':
+ gShowGMBounds = !gShowGMBounds;
+ postEventToSink(GMSampleView::NewShowSizeEvt(gShowGMBounds),
+ curr_view(this));
+ this->inval(NULL);
+ break;
case 'i':
this->zoomIn();
break;