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

Side by Side Diff: gm/ninepatchstretch.cpp

Issue 144543003: Remove GetGr() hack. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | samplecode/SampleApp.cpp » ('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 9
10 #if SK_SUPPORT_GPU 10 static void make_bitmap(SkBitmap* bitmap, SkIRect* center) {
11 #include "SkGpuDevice.h"
12 #else
13 class GrContext;
14 #endif
15
16 static void make_bitmap(SkBitmap* bitmap, GrContext* ctx, SkIRect* center) {
17 SkBaseDevice* dev;
18
19 const int kFixed = 28; 11 const int kFixed = 28;
20 const int kStretchy = 8; 12 const int kStretchy = 8;
21 const int kSize = 2*kFixed + kStretchy; 13 const int kSize = 2*kFixed + kStretchy;
22 14
23 #if SK_SUPPORT_GPU 15 bitmap->setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize);
24 if (ctx) { 16 bitmap->allocPixels();
25 dev = new SkGpuDevice(ctx, SkBitmap::kARGB_8888_Config, kSize, kSize); 17 SkBaseDevice* dev = new SkBitmapDevice(*bitmap);
26 *bitmap = dev->accessBitmap(false);
27 } else
28 #endif
29 {
30 bitmap->setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize);
31 bitmap->allocPixels();
32 dev = new SkBitmapDevice(*bitmap);
33 }
34 18
35 SkCanvas canvas(dev); 19 SkCanvas canvas(dev);
36 dev->unref(); 20 dev->unref();
37 canvas.clear(SK_ColorTRANSPARENT); 21 canvas.clear(SK_ColorTRANSPARENT);
38 22
39 SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize)); 23 SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize));
40 const SkScalar strokeWidth = SkIntToScalar(6); 24 const SkScalar strokeWidth = SkIntToScalar(6);
41 const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2; 25 const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2;
42 26
43 center->setXYWH(kFixed, kFixed, kStretchy, kStretchy); 27 center->setXYWH(kFixed, kFixed, kStretchy, kStretchy);
(...skipping 24 matching lines...) Expand all
68 return SkString("ninepatch-stretch"); 52 return SkString("ninepatch-stretch");
69 } 53 }
70 54
71 virtual SkISize onISize() { 55 virtual SkISize onISize() {
72 return make_isize(400, 400); 56 return make_isize(400, 400);
73 } 57 }
74 58
75 virtual void onDraw(SkCanvas* canvas) { 59 virtual void onDraw(SkCanvas* canvas) {
76 SkBitmap bm; 60 SkBitmap bm;
77 SkIRect center; 61 SkIRect center;
78 make_bitmap(&bm, NULL /*SampleCode::GetGr()*/, &center); 62 make_bitmap(&bm, &center);
79 63
80 // amount of bm that should not be stretched (unless we have to) 64 // amount of bm that should not be stretched (unless we have to)
81 const SkScalar fixed = SkIntToScalar(bm.width() - center.width()); 65 const SkScalar fixed = SkIntToScalar(bm.width() - center.width());
82 66
83 const SkTSize<SkScalar> size[] = { 67 const SkTSize<SkScalar> size[] = {
84 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes 68 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes
85 { fixed * 4 / 5, fixed * 4 }, // shrink in X 69 { fixed * 4 / 5, fixed * 4 }, // shrink in X
86 { fixed * 4, fixed * 4 / 5 }, // shrink in Y 70 { fixed * 4, fixed * 4 / 5 }, // shrink in Y
87 { fixed * 4, fixed * 4 } 71 { fixed * 4, fixed * 4 }
88 }; 72 };
(...skipping 19 matching lines...) Expand all
108 private: 92 private:
109 typedef GM INHERITED; 93 typedef GM INHERITED;
110 }; 94 };
111 95
112 ////////////////////////////////////////////////////////////////////////////// 96 //////////////////////////////////////////////////////////////////////////////
113 97
114 static GM* MyFactory(void*) { return new NinePatchStretchGM; } 98 static GM* MyFactory(void*) { return new NinePatchStretchGM; }
115 static GMRegistry reg(MyFactory); 99 static GMRegistry reg(MyFactory);
116 100
117 } 101 }
OLDNEW
« no previous file with comments | « no previous file | samplecode/SampleApp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698