2012-07-30 14:40:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 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"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2012-09-28 17:24:44 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2012-07-30 14:40:01 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class DrawBitmapMatrixGM : public GM {
|
|
|
|
public:
|
|
|
|
DrawBitmapMatrixGM() {}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:40:01 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
|
|
|
return SkString("drawbitmapmatrix");
|
|
|
|
}
|
|
|
|
|
2014-06-10 06:59:03 +00:00
|
|
|
virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(1024, 256); }
|
2012-07-30 14:40:01 +00:00
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkBitmap bm;
|
|
|
|
this->setupBitmap(&bm);
|
|
|
|
|
|
|
|
// Draw normally.
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setDither(true);
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
|
|
|
|
|
|
|
// Draw stretched horizontally and squished vertically.
|
|
|
|
canvas->translate(SkIntToScalar(bm.width() + 5), 0);
|
|
|
|
matrix.setScale(SkIntToScalar(2), SK_ScalarHalf);
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
|
|
|
|
|
|
|
// Draw rotated
|
|
|
|
canvas->translate(SkIntToScalar(bm.width()*2 + 5), 0);
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2),
|
|
|
|
SkIntToScalar(bm.height() / 2));
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, SkIntToScalar(10));
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// Draw with perspective
|
|
|
|
canvas->translate(SkIntToScalar(bm.width() + 15), 0);
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setPerspX(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
|
|
|
|
matrix.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
|
|
|
|
|
|
|
// Draw with skew
|
|
|
|
canvas->translate(SkIntToScalar(bm.width() + 5), 0);
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setSkew(SkIntToScalar(2), SkIntToScalar(2));
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
|
|
|
|
|
|
|
// Draw with sin/cos
|
|
|
|
canvas->translate(SkIntToScalar(bm.width() * 4), 0);
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setSinCos(SK_ScalarHalf, SkIntToScalar(2));
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
2012-09-28 17:24:44 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// test the following code path:
|
|
|
|
// SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter()
|
|
|
|
SkPaint paint;
|
|
|
|
|
2013-10-31 17:28:30 +00:00
|
|
|
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
|
2012-09-28 17:24:44 +00:00
|
|
|
|
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(5),
|
2012-09-28 17:24:44 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag |
|
|
|
|
SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
|
|
|
|
paint.setMaskFilter(mf)->unref();
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(bm.width()*2 + 20), 0);
|
|
|
|
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setRotate(SkIntToScalar(45), SkIntToScalar(bm.width() / 2),
|
|
|
|
SkIntToScalar(bm.height() / 2));
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, SkIntToScalar(20));
|
|
|
|
canvas->drawBitmapMatrix(bm, matrix, &paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:40:01 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
void setupBitmap(SkBitmap* bm) {
|
|
|
|
SkASSERT(bm);
|
|
|
|
static const int SIZE = 64;
|
2014-01-25 16:46:20 +00:00
|
|
|
bm->allocN32Pixels(SIZE, SIZE);
|
2012-07-30 14:40:01 +00:00
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
canvas.drawPaint(paint);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkRect rect = SkRect::MakeWH(SkIntToScalar(SIZE), SkIntToScalar(SIZE));
|
|
|
|
SkPath path;
|
|
|
|
path.addOval(rect);
|
|
|
|
canvas.drawPath(path, paint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new DrawBitmapMatrixGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|