a90c680386
- Rename TileGrid -> Quilt to avoid the name overload. - Tag all failing GMs with kSkipTiled_Flag. You may be wondering, do any GMs pass? Yes, some do! And that trends towards all of them as we increase --quiltTile. Two GMs only fail in --quilt mode in 565. Otherwise all GMs which fail are skipped, and those which don't fail aren't. (The 8888 variants of those two GMs are skipped even though they pass.) BUG=skia:2477 R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/256373002 git-svn-id: http://skia.googlecode.com/svn/trunk@14457 2bbb7eff-a529-9590-31e7-b0007b416f81
124 lines
3.2 KiB
C++
124 lines
3.2 KiB
C++
|
|
/*
|
|
* Copyright 2013 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#include "gm.h"
|
|
|
|
#include "SkBitmap.h"
|
|
#include "SkPaint.h"
|
|
#include "SkShader.h"
|
|
|
|
namespace skiagm {
|
|
|
|
static void draw_bm(SkBitmap* bm) {
|
|
SkPaint bluePaint;
|
|
bluePaint.setColor(SK_ColorBLUE);
|
|
|
|
bm->allocN32Pixels(20, 20);
|
|
bm->eraseColor(SK_ColorRED);
|
|
|
|
SkCanvas canvas(*bm);
|
|
canvas.drawCircle(10, 10, 5, bluePaint);
|
|
}
|
|
|
|
static void draw_mask(SkBitmap* bm) {
|
|
SkPaint circlePaint;
|
|
circlePaint.setColor(SK_ColorBLACK);
|
|
|
|
bm->allocPixels(SkImageInfo::MakeA8(20, 20));
|
|
bm->eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
SkCanvas canvas(*bm);
|
|
canvas.drawCircle(10, 10, 10, circlePaint);
|
|
}
|
|
|
|
static void adopt_shader(SkPaint* paint, SkShader* shader) {
|
|
paint->setShader(shader);
|
|
SkSafeUnref(shader);
|
|
}
|
|
|
|
class BitmapShaderGM : public GM {
|
|
public:
|
|
|
|
BitmapShaderGM() {
|
|
this->setBGColor(SK_ColorGRAY);
|
|
draw_bm(&fBitmap);
|
|
draw_mask(&fMask);
|
|
}
|
|
|
|
protected:
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
return kSkipTiled_Flag;
|
|
}
|
|
|
|
virtual SkString onShortName() {
|
|
return SkString("bitmapshaders");
|
|
}
|
|
|
|
virtual SkISize onISize() {
|
|
return SkISize::Make(150, 100);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
SkPaint paint;
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
SkMatrix s;
|
|
s.reset();
|
|
if (1 == i) {
|
|
s.setScale(1.5f, 1.5f);
|
|
s.postTranslate(2, 2);
|
|
}
|
|
|
|
canvas->save();
|
|
adopt_shader(&paint, SkShader::CreateBitmapShader(fBitmap, SkShader::kClamp_TileMode,
|
|
SkShader::kClamp_TileMode, &s));
|
|
|
|
// draw the shader with a bitmap mask
|
|
canvas->drawBitmap(fMask, 0, 0, &paint);
|
|
canvas->drawBitmap(fMask, 30, 0, &paint);
|
|
|
|
canvas->translate(0, 25);
|
|
|
|
canvas->drawCircle(10, 10, 10, paint);
|
|
canvas->drawCircle(40, 10, 10, paint); // no blue circle expected
|
|
|
|
canvas->translate(0, 25);
|
|
|
|
// clear the shader, colorized by a solid color with a bitmap mask
|
|
paint.setShader(NULL);
|
|
paint.setColor(SK_ColorGREEN);
|
|
canvas->drawBitmap(fMask, 0, 0, &paint);
|
|
canvas->drawBitmap(fMask, 30, 0, &paint);
|
|
|
|
canvas->translate(0, 25);
|
|
|
|
adopt_shader(&paint, SkShader::CreateBitmapShader(fMask, SkShader::kRepeat_TileMode,
|
|
SkShader::kRepeat_TileMode, &s));
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
// draw the mask using the shader and a color
|
|
canvas->drawRect(SkRect::MakeXYWH(0, 0, 20, 20), paint);
|
|
canvas->drawRect(SkRect::MakeXYWH(30, 0, 20, 20), paint);
|
|
canvas->restore();
|
|
canvas->translate(60, 0);
|
|
}
|
|
}
|
|
|
|
private:
|
|
SkBitmap fBitmap;
|
|
SkBitmap fMask;
|
|
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
static GM* MyFactory(void*) { return new BitmapShaderGM; }
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
}
|