OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 bm->setImmutable(); | 53 bm->setImmutable(); |
54 return count; | 54 return count; |
55 } | 55 } |
56 | 56 |
57 class TallStretchedBitmapsGM : public skiagm::GM { | 57 class TallStretchedBitmapsGM : public skiagm::GM { |
58 public: | 58 public: |
59 TallStretchedBitmapsGM() {} | 59 TallStretchedBitmapsGM() {} |
60 | 60 |
61 protected: | 61 protected: |
62 SkString onShortName() SK_OVERRIDE { | 62 SkString onShortName() override { |
63 return SkString("tall_stretched_bitmaps"); | 63 return SkString("tall_stretched_bitmaps"); |
64 } | 64 } |
65 | 65 |
66 SkISize onISize() SK_OVERRIDE { | 66 SkISize onISize() override { |
67 return SkISize::Make(750, 750); | 67 return SkISize::Make(750, 750); |
68 } | 68 } |
69 | 69 |
70 void onOnceBeforeDraw() SK_OVERRIDE { | 70 void onOnceBeforeDraw() override { |
71 for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) { | 71 for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) { |
72 int h = SkToInt((4 + i) * 1024); | 72 int h = SkToInt((4 + i) * 1024); |
73 | 73 |
74 fTallBmps[i].fItemCnt = make_bm(&fTallBmps[i].fBmp, h); | 74 fTallBmps[i].fItemCnt = make_bm(&fTallBmps[i].fBmp, h); |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 78 void onDraw(SkCanvas* canvas) override { |
79 canvas->scale(1.3f, 1.3f); | 79 canvas->scale(1.3f, 1.3f); |
80 for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) { | 80 for (size_t i = 0; i < SK_ARRAY_COUNT(fTallBmps); ++i) { |
81 SkASSERT(fTallBmps[i].fItemCnt > 10); | 81 SkASSERT(fTallBmps[i].fItemCnt > 10); |
82 SkBitmap bmp = fTallBmps[i].fBmp; | 82 SkBitmap bmp = fTallBmps[i].fBmp; |
83 // Draw the last 10 elements of the bitmap. | 83 // Draw the last 10 elements of the bitmap. |
84 int startItem = fTallBmps[i].fItemCnt - 10; | 84 int startItem = fTallBmps[i].fItemCnt - 10; |
85 int itemHeight = bmp.height() / fTallBmps[i].fItemCnt; | 85 int itemHeight = bmp.height() / fTallBmps[i].fItemCnt; |
86 SkIRect subRect = SkIRect::MakeLTRB(0, startItem * itemHeight, | 86 SkIRect subRect = SkIRect::MakeLTRB(0, startItem * itemHeight, |
87 bmp.width(), bmp.height()); | 87 bmp.width(), bmp.height()); |
88 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bmp.width()), 10.f * i
temHeight); | 88 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(bmp.width()), 10.f * i
temHeight); |
89 SkPaint paint; | 89 SkPaint paint; |
90 paint.setFilterQuality(kLow_SkFilterQuality); | 90 paint.setFilterQuality(kLow_SkFilterQuality); |
91 canvas->drawBitmapRect(bmp, &subRect, dstRect, &paint); | 91 canvas->drawBitmapRect(bmp, &subRect, dstRect, &paint); |
92 canvas->translate(SkIntToScalar(bmp.width() + 10), 0); | 92 canvas->translate(SkIntToScalar(bmp.width() + 10), 0); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 struct { | 97 struct { |
98 SkBitmap fBmp; | 98 SkBitmap fBmp; |
99 int fItemCnt; | 99 int fItemCnt; |
100 } fTallBmps[8]; | 100 } fTallBmps[8]; |
101 typedef skiagm::GM INHERITED; | 101 typedef skiagm::GM INHERITED; |
102 }; | 102 }; |
103 | 103 |
104 ////////////////////////////////////////////////////////////////////////////// | 104 ////////////////////////////////////////////////////////////////////////////// |
105 | 105 |
106 DEF_GM(return SkNEW(TallStretchedBitmapsGM);) | 106 DEF_GM(return SkNEW(TallStretchedBitmapsGM);) |
107 | 107 |
OLD | NEW |