skia2/gm/bigmatrix.cpp
caryclark 65cdba6ba7 Revert of Revert of make gm background colors 565 compatible (patchset #1 id:1 of https://codereview.chromium.org/1184123002/)
Reason for revert:
underlying problem with portable refs deleted more than once fixed

Original issue's description:
> Revert of make gm background colors 565 compatible (patchset #2 id:20001 of https://codereview.chromium.org/1176243006/)
>
> Reason for revert:
> breaks many bots with refcnt error
>
> Original issue's description:
> > make gm background colors 565 compatible
> >
> > Change a batch of GM tests to convert their background color
> > so that it is representable in 8888 and 565.
> >
> > Enable portable text in those same tests to minimize platform
> > differences.
> >
> > In a couple of bitmap tests, use portable typefaces instead of
> > choosing 'Times' which may or may not be available on the platform.
> >
> > R=borenet@google.com
> >
> > Committed: https://skia.googlesource.com/skia/+/be7f768a357aefb39c42d24b81b24d647bb6ab70
>
> TBR=borenet@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/0bdb08b1ba8fbd18c4838f86a23f1ef4b3a3bfdf

TBR=borenet@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1182403003
2015-06-15 06:51:08 -07:00

96 lines
2.7 KiB
C++

/*
* 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 "SkColorPriv.h"
#include "SkShader.h"
namespace skiagm {
class BigMatrixGM : public GM {
public:
BigMatrixGM() {
this->setBGColor(sk_tool_utils::color_to_565(0xFF66AA99));
}
protected:
virtual SkString onShortName() {
return SkString("bigmatrix");
}
virtual SkISize onISize() {
return SkISize::Make(50, 50);
}
virtual void onDraw(SkCanvas* canvas) {
SkMatrix m;
m.reset();
m.setRotate(33 * SK_Scalar1);
m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
canvas->concat(m);
SkPaint paint;
paint.setColor(SK_ColorRED);
paint.setAntiAlias(true);
bool success = m.invert(&m);
SkASSERT(success);
(void) success; // silence compiler :(
SkPath path;
SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
SkScalar small = 1 / (500 * SK_Scalar1);
m.mapPoints(&pt, 1);
path.addCircle(pt.fX, pt.fY, small);
canvas->drawPath(path, paint);
pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
m.mapPoints(&pt, 1);
SkRect rect = {pt.fX - small, pt.fY - small,
pt.fX + small, pt.fY + small};
canvas->drawRect(rect, paint);
SkBitmap bmp;
bmp.allocN32Pixels(2, 2);
uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
m.mapPoints(&pt, 1);
SkMatrix s;
s.reset();
s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
SkShader* shader = SkShader::CreateBitmapShader(
bmp,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode,
&s);
paint.setShader(shader)->unref();
paint.setAntiAlias(false);
paint.setFilterQuality(kLow_SkFilterQuality);
rect.setLTRB(pt.fX - small, pt.fY - small,
pt.fX + small, pt.fY + small);
canvas->drawRect(rect, paint);
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new BigMatrixGM; }
static GMRegistry reg(MyFactory);
}