OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "gm.h" |
| 9 #include "SkCanvas.h" |
| 10 #include "SkGradientShader.h" |
| 11 #include "SkPath.h" |
| 12 |
| 13 int make_bm(SkBitmap* bm, int height) { |
| 14 static const int kRadius = 22; |
| 15 static const int kMargin = 8; |
| 16 static const SkScalar kStartAngle = 0; |
| 17 static const SkScalar kDAngle = 25; |
| 18 static const SkScalar kSweep = 320; |
| 19 static const SkScalar kThickness = 8; |
| 20 |
| 21 int count = (height / (2 * kRadius + kMargin)); |
| 22 height = count * (2 * kRadius + kMargin); |
| 23 |
| 24 bm->allocN32Pixels(2 * (kRadius + kMargin), height); |
| 25 SkRandom random; |
| 26 |
| 27 SkCanvas wholeCanvas(*bm); |
| 28 wholeCanvas.clear(0x00000000); |
| 29 |
| 30 SkScalar angle = kStartAngle; |
| 31 for (int i = 0; i < count; ++i) { |
| 32 SkPaint paint; |
| 33 // The sw rasterizer disables AA for large canvii. So we make a small ca
nvas for each draw. |
| 34 SkBitmap smallBM; |
| 35 SkIRect subRect = SkIRect::MakeXYWH(0, i * (kMargin + 2 * kRadius), |
| 36 2 * kRadius + kMargin, 2 * kRadius +
kMargin); |
| 37 bm->extractSubset(&smallBM, subRect); |
| 38 SkCanvas canvas(smallBM); |
| 39 canvas.translate(kMargin + kRadius, kMargin + kRadius); |
| 40 |
| 41 paint.setAntiAlias(true); |
| 42 paint.setColor(random.nextU() | 0xFF000000); |
| 43 paint.setStyle(SkPaint::kStroke_Style); |
| 44 paint.setStrokeWidth(kThickness); |
| 45 paint.setStrokeCap(SkPaint::kRound_Cap); |
| 46 SkScalar radius = kRadius - kThickness / 2; |
| 47 SkRect bounds = SkRect::MakeLTRB(-radius, -radius, radius, radius); |
| 48 |
| 49 canvas.drawArc(bounds, angle, kSweep, false, paint); |
| 50 angle += kDAngle; |
| 51 } |
| 52 bm->setImmutable(); |
| 53 return count; |
| 54 } |
| 55 |
| 56 class TallStretchedBitmapsGM : public skiagm::GM { |
| 57 public: |
| 58 TallStretchedBitmapsGM() {} |
| 59 |
| 60 protected: |
| 61 SkString onShortName() SK_OVERRIDE { |
| 62 return SkString("tall_stretched_bitmaps"); |
| 63 } |
| 64 |
| 65 SkISize onISize() SK_OVERRIDE { |
| 66 return SkISize::Make(750, 750); |
| 67 } |
| 68 |
| 69 void onOnceBeforeDraw() SK_OVERRIDE { |
| 70 for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) { |
| 71 int h = (4 + i) * 1024; |
| 72 |
| 73 fTallBmps[i].fItemCnt = make_bm(&fTallBmps[i].fBmp, h); |
| 74 } |
| 75 } |
| 76 |
| 77 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 78 canvas->scale(1.3f, 1.3f); |
| 79 for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) { |
| 80 SkASSERT(fTallBmps[i].fItemCnt > 10); |
| 81 SkBitmap bmp = fTallBmps[i].fBmp; |
| 82 // Draw the last 10 elements of the bitmap. |
| 83 int startItem = fTallBmps[i].fItemCnt - 10; |
| 84 int itemHeight = bmp.height() / fTallBmps[i].fItemCnt; |
| 85 SkIRect subRect = SkIRect::MakeLTRB(0, startItem * itemHeight, |
| 86 bmp.width(), bmp.height()); |
| 87 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bmp.width()), 10.f * i
temHeight); |
| 88 SkPaint paint; |
| 89 paint.setFilterLevel(SkPaint::kLow_FilterLevel); |
| 90 canvas->drawBitmapRect(bmp, &subRect, dstRect, &paint); |
| 91 canvas->translate(SkIntToScalar(bmp.width() + 10), 0); |
| 92 } |
| 93 } |
| 94 |
| 95 uint32_t onGetFlags() SK_OVERRIDE { |
| 96 // This GM causes issues in replay modes. |
| 97 return kSkipTiled_Flag | kNoBBH_Flag | kSkipPicture_Flag; |
| 98 } |
| 99 |
| 100 private: |
| 101 struct { |
| 102 SkBitmap fBmp; |
| 103 int fItemCnt; |
| 104 } fTallBmps[8]; |
| 105 typedef skiagm::GM INHERITED; |
| 106 }; |
| 107 |
| 108 ////////////////////////////////////////////////////////////////////////////// |
| 109 |
| 110 DEF_GM(return SkNEW(TallStretchedBitmapsGM);) |
| 111 |
OLD | NEW |