skia2/gm/anisotropic.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

115 lines
3.7 KiB
C++

/*
* Copyright 2015 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"
namespace skiagm {
// This GM exercises HighQuality anisotropic filtering.
class AnisotropicGM : public GM {
public:
AnisotropicGM() : fFilterQuality(kHigh_SkFilterQuality) {
this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
}
protected:
SkString onShortName() override { return SkString("anisotropic_hq"); }
SkISize onISize() override {
return SkISize::Make(2*kImageSize + 3*kSpacer,
kNumVertImages*kImageSize + (kNumVertImages+1)*kSpacer);
}
// Create an image consisting of lines radiating from its center
void onOnceBeforeDraw() override {
static const int kNumLines = 100;
static const SkScalar kAngleStep = 360.0f / kNumLines;
static const int kInnerOffset = 10;
fBM.allocN32Pixels(kImageSize, kImageSize, true);
SkCanvas canvas(fBM);
canvas.clear(SK_ColorWHITE);
SkPaint p;
p.setAntiAlias(true);
SkScalar angle = 0.0f, sin, cos;
canvas.translate(kImageSize/2.0f, kImageSize/2.0f);
for (int i = 0; i < kNumLines; ++i, angle += kAngleStep) {
sin = SkScalarSinCos(angle, &cos);
canvas.drawLine(cos * kInnerOffset, sin * kInnerOffset,
cos * kImageSize/2, sin * kImageSize/2, p);
}
}
void draw(SkCanvas* canvas, int x, int y, int xSize, int ySize) {
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(xSize), SkIntToScalar(ySize));
SkPaint p;
p.setFilterQuality(fFilterQuality);
canvas->drawBitmapRect(fBM, r, &p);
}
void onDraw(SkCanvas* canvas) override {
SkScalar gScales[] = { 0.9f, 0.8f, 0.75f, 0.6f, 0.5f, 0.4f, 0.25f, 0.2f, 0.1f };
SkASSERT(kNumVertImages-1 == (int)SK_ARRAY_COUNT(gScales)/2);
// Minimize vertically
for (int i = 0; i < (int)SK_ARRAY_COUNT(gScales); ++i) {
int height = SkScalarFloorToInt(fBM.height() * gScales[i]);
int yOff;
if (i <= (int)SK_ARRAY_COUNT(gScales)/2) {
yOff = kSpacer + i * (fBM.height() + kSpacer);
} else {
// Position the more highly squashed images with their less squashed counterparts
yOff = (SK_ARRAY_COUNT(gScales) - i) * (fBM.height() + kSpacer) - height;
}
this->draw(canvas, kSpacer, yOff, fBM.width(), height);
}
// Minimize horizontally
for (int i = 0; i < (int)SK_ARRAY_COUNT(gScales); ++i) {
int width = SkScalarFloorToInt(fBM.width() * gScales[i]);
int xOff, yOff;
if (i <= (int)SK_ARRAY_COUNT(gScales)/2) {
xOff = fBM.width() + 2*kSpacer;
yOff = kSpacer + i * (fBM.height() + kSpacer);
} else {
// Position the more highly squashed images with their less squashed counterparts
xOff = fBM.width() + 2*kSpacer + fBM.width() - width;
yOff = kSpacer + (SK_ARRAY_COUNT(gScales) - i - 1) * (fBM.height() + kSpacer);
}
this->draw(canvas, xOff, yOff, width, fBM.height());
}
}
private:
static const int kImageSize = 256;
static const int kSpacer = 10;
static const int kNumVertImages = 5;
SkBitmap fBM;
SkFilterQuality fFilterQuality;
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return SkNEW(AnisotropicGM); )
}