Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Side by Side Diff: gm/ninepatchstretch.cpp

Issue 1454933002: Initial implementation of GPU no filter NinePatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/gpu.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkSurface.h" 9 #include "SkSurface.h"
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 SkIRect fCenter; 59 SkIRect fCenter;
60 60
61 NinePatchStretchGM() {} 61 NinePatchStretchGM() {}
62 62
63 protected: 63 protected:
64 SkString onShortName() override { 64 SkString onShortName() override {
65 return SkString("ninepatch-stretch"); 65 return SkString("ninepatch-stretch");
66 } 66 }
67 67
68 SkISize onISize() override { 68 SkISize onISize() override {
69 return SkISize::Make(760, 400); 69 return SkISize::Make(760, 800);
70 } 70 }
71 71
72 void onDraw(SkCanvas* canvas) override { 72 void onDraw(SkCanvas* canvas) override {
73 if (nullptr == fBitmap.pixelRef()) { 73 if (nullptr == fBitmap.pixelRef()) {
74 fImage.reset(make_image(canvas, &fCenter)); 74 fImage.reset(make_image(canvas, &fCenter));
75 image_to_bitmap(fImage, &fBitmap); 75 image_to_bitmap(fImage, &fBitmap);
76 } 76 }
77 77
78 // amount of bm that should not be stretched (unless we have to) 78 // amount of bm that should not be stretched (unless we have to)
79 const SkScalar fixed = SkIntToScalar(fBitmap.width() - fCenter.width()); 79 const SkScalar fixed = SkIntToScalar(fBitmap.width() - fCenter.width());
80 80
81 const SkTSize<SkScalar> size[] = { 81 const SkTSize<SkScalar> size[] = {
82 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes 82 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes
83 { fixed * 4 / 5, fixed * 4 }, // shrink in X 83 { fixed * 4 / 5, fixed * 4 }, // shrink in X
84 { fixed * 4, fixed * 4 / 5 }, // shrink in Y 84 { fixed * 4, fixed * 4 / 5 }, // shrink in Y
85 { fixed * 4, fixed * 4 } 85 { fixed * 4, fixed * 4 }
86 }; 86 };
87 87
88 canvas->drawBitmap(fBitmap, 10, 10, nullptr); 88 canvas->drawBitmap(fBitmap, 10, 10, nullptr);
89 89
90 SkScalar x = SkIntToScalar(100); 90 SkScalar x = SkIntToScalar(100);
91 SkScalar y = SkIntToScalar(100); 91 SkScalar y = SkIntToScalar(100);
92 92
93 SkPaint paint; 93 SkPaint paint;
94 paint.setFilterQuality(kLow_SkFilterQuality); 94 for (int filter = 0; filter < 2; filter++) {
95 95 paint.setFilterQuality(filter == 0 ? kLow_SkFilterQuality : kNone_Sk FilterQuality);
96 for (int iy = 0; iy < 2; ++iy) { 96 canvas->translate(0, filter * SkIntToScalar(400));
97 for (int ix = 0; ix < 2; ++ix) { 97 for (int iy = 0; iy < 2; ++iy) {
98 int i = ix * 2 + iy; 98 for (int ix = 0; ix < 2; ++ix) {
99 SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed, 99 int i = ix * 2 + iy;
100 size[i].width(), size[i].height()); 100 SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed,
101 canvas->drawBitmapNine(fBitmap, fCenter, r, &paint); 101 size[i].width(), size[i].height( ));
102 canvas->drawImageNine(fImage, fCenter, r.makeOffset(360, 0), &pa int); 102 canvas->drawBitmapNine(fBitmap, fCenter, r, &paint);
103 103 canvas->drawImageNine(fImage, fCenter, r.makeOffset(360, 0), &paint);
104 }
104 } 105 }
105 } 106 }
106 } 107 }
107 108
108 private: 109 private:
109 typedef skiagm::GM INHERITED; 110 typedef skiagm::GM INHERITED;
110 }; 111 };
111 DEF_GM( return new NinePatchStretchGM; ) 112 DEF_GM( return new NinePatchStretchGM; )
112 113
OLDNEW
« no previous file with comments | « no previous file | gyp/gpu.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698