2014-12-09 17:00:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFilterQuality.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkTo.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2014-12-09 17:00:49 +00:00
|
|
|
|
|
|
|
int make_bm(SkBitmap* bm, int height) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kRadius = 22;
|
|
|
|
constexpr int kMargin = 8;
|
|
|
|
constexpr SkScalar kStartAngle = 0;
|
|
|
|
constexpr SkScalar kDAngle = 25;
|
|
|
|
constexpr SkScalar kSweep = 320;
|
|
|
|
constexpr SkScalar kThickness = 8;
|
2014-12-09 17:00:49 +00:00
|
|
|
|
|
|
|
int count = (height / (2 * kRadius + kMargin));
|
|
|
|
height = count * (2 * kRadius + kMargin);
|
|
|
|
|
|
|
|
bm->allocN32Pixels(2 * (kRadius + kMargin), height);
|
|
|
|
SkRandom random;
|
|
|
|
|
|
|
|
SkCanvas wholeCanvas(*bm);
|
|
|
|
wholeCanvas.clear(0x00000000);
|
|
|
|
|
|
|
|
SkScalar angle = kStartAngle;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
SkPaint paint;
|
|
|
|
// The sw rasterizer disables AA for large canvii. So we make a small canvas for each draw.
|
|
|
|
SkBitmap smallBM;
|
|
|
|
SkIRect subRect = SkIRect::MakeXYWH(0, i * (kMargin + 2 * kRadius),
|
|
|
|
2 * kRadius + kMargin, 2 * kRadius + kMargin);
|
|
|
|
bm->extractSubset(&smallBM, subRect);
|
|
|
|
SkCanvas canvas(smallBM);
|
|
|
|
canvas.translate(kMargin + kRadius, kMargin + kRadius);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(random.nextU() | 0xFF000000);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(kThickness);
|
|
|
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
SkScalar radius = kRadius - kThickness / 2;
|
|
|
|
SkRect bounds = SkRect::MakeLTRB(-radius, -radius, radius, radius);
|
|
|
|
|
|
|
|
canvas.drawArc(bounds, angle, kSweep, false, paint);
|
|
|
|
angle += kDAngle;
|
|
|
|
}
|
|
|
|
bm->setImmutable();
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TallStretchedBitmapsGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
TallStretchedBitmapsGM() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-12-09 17:00:49 +00:00
|
|
|
return SkString("tall_stretched_bitmaps");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2016-04-11 14:46:38 +00:00
|
|
|
return SkISize::Make(730, 690);
|
2014-12-09 17:00:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-12-09 17:00:49 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) {
|
2014-12-12 16:51:38 +00:00
|
|
|
int h = SkToInt((4 + i) * 1024);
|
2014-12-09 17:00:49 +00:00
|
|
|
|
|
|
|
fTallBmps[i].fItemCnt = make_bm(&fTallBmps[i].fBmp, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-12-09 17:00:49 +00:00
|
|
|
canvas->scale(1.3f, 1.3f);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) {
|
|
|
|
SkASSERT(fTallBmps[i].fItemCnt > 10);
|
|
|
|
SkBitmap bmp = fTallBmps[i].fBmp;
|
|
|
|
// Draw the last 10 elements of the bitmap.
|
|
|
|
int startItem = fTallBmps[i].fItemCnt - 10;
|
|
|
|
int itemHeight = bmp.height() / fTallBmps[i].fItemCnt;
|
|
|
|
SkIRect subRect = SkIRect::MakeLTRB(0, startItem * itemHeight,
|
|
|
|
bmp.width(), bmp.height());
|
|
|
|
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bmp.width()), 10.f * itemHeight);
|
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
2015-07-17 14:09:43 +00:00
|
|
|
canvas->drawBitmapRect(bmp, subRect, dstRect, &paint);
|
2014-12-09 17:00:49 +00:00
|
|
|
canvas->translate(SkIntToScalar(bmp.width() + 10), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct {
|
|
|
|
SkBitmap fBmp;
|
|
|
|
int fItemCnt;
|
|
|
|
} fTallBmps[8];
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2014-12-09 17:00:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new TallStretchedBitmapsGM;)
|