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

Side by Side Diff: gm/verylargebitmap.cpp

Issue 1313543004: switch over to using images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | no next file » | 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 2012 Google Inc. 2 * Copyright 2012 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"
11 #include "SkPath.h" 11 #include "SkPath.h"
12 #include "SkSurface.h"
12 13
13 static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) { 14 static SkImage* make_image(int width, int height, SkColor colors[2]) {
14 bm->allocN32Pixels(width, height); 15 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, height) );
15 SkCanvas canvas(*bm); 16
16 SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2}; 17 const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 };
17 SkScalar radius = 40; 18 const SkScalar radius = 40;
18 SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nu llptr, 2, 19 SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nu llptr, 2,
19 SkShader::kMirror_TileMode ); 20 SkShader::kMirror_TileMode );
20 SkPaint paint; 21 SkPaint paint;
21 paint.setShader(shader)->unref(); 22 paint.setShader(shader)->unref();
22 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 23 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
23 canvas.drawPaint(paint); 24 surface->getCanvas()->drawPaint(paint);
24 bm->setImmutable(); 25 return surface->newImageSnapshot();
25 } 26 }
26 27
27 static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) { 28 static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2 ]) {
28 SkBitmap bm; 29 SkAutoTUnref<SkImage> image(make_image(width, height, colors));
29 make_bm(&bm, width, height, colors);
30 30
31 SkPaint paint; 31 SkPaint paint;
32 SkRect r; 32 SkRect r;
33 SkIRect ir; 33 SkIRect ir;
34 34
35 paint.setStyle(SkPaint::kStroke_Style); 35 paint.setStyle(SkPaint::kStroke_Style);
36 36
37 ir.set(0, 0, 128, 128); 37 ir.set(0, 0, 128, 128);
38 r.set(ir); 38 r.set(ir);
39 39
40 canvas->save(); 40 canvas->save();
41 canvas->clipRect(r); 41 canvas->clipRect(r);
42 canvas->drawBitmap(bm, 0, 0, nullptr); 42 canvas->drawImage(image, 0, 0, nullptr);
43 canvas->restore(); 43 canvas->restore();
44 canvas->drawRect(r, paint); 44 canvas->drawRect(r, paint);
45 45
46 r.offset(SkIntToScalar(150), 0); 46 r.offset(SkIntToScalar(150), 0);
47 // exercises extract bitmap, but not shader 47 canvas->drawImageRect(image, ir, r, nullptr);
48 canvas->drawBitmapRect(bm, ir, r, nullptr);
49 canvas->drawRect(r, paint); 48 canvas->drawRect(r, paint);
50 49
51 r.offset(SkIntToScalar(150), 0); 50 r.offset(SkIntToScalar(150), 0);
52 // exercises bitmapshader 51 canvas->drawImageRect(image, r, nullptr);
53 canvas->drawBitmapRect(bm, r, nullptr);
54 canvas->drawRect(r, paint); 52 canvas->drawRect(r, paint);
55 } 53 }
56 54
57 class VeryLargeBitmapGM : public skiagm::GM { 55 class VeryLargeBitmapGM : public skiagm::GM {
58 public: 56 public:
59 VeryLargeBitmapGM() {} 57 VeryLargeBitmapGM() {}
60 58
61 protected: 59 protected:
62 SkString onShortName() override { 60 SkString onShortName() override {
63 return SkString("verylargebitmap"); 61 return SkString("verylargebitmap");
64 } 62 }
65 63
66 SkISize onISize() override { 64 SkISize onISize() override {
67 return SkISize::Make(500, 600); 65 return SkISize::Make(500, 600);
68 } 66 }
69 67
70 void onDraw(SkCanvas* canvas) override { 68 void onDraw(SkCanvas* canvas) override {
71 int veryBig = 65*1024; // 64K < size 69 int veryBig = 65*1024; // 64K < size
72 int big = 33*1024; // 32K < size < 64K 70 int big = 33*1024; // 32K < size < 64K
73 // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons. 71 // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons.
74 int medium = 5*1024; 72 int medium = 5*1024;
75 int small = 150; 73 int small = 150;
76 74
77 SkColor colors[2]; 75 SkColor colors[2];
78 76
79 canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); 77 canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
80 colors[0] = SK_ColorRED; 78 colors[0] = SK_ColorRED;
81 colors[1] = SK_ColorGREEN; 79 colors[1] = SK_ColorGREEN;
82 show_bm(canvas, small, small, colors); 80 show_image(canvas, small, small, colors);
83 canvas->translate(0, SkIntToScalar(150)); 81 canvas->translate(0, SkIntToScalar(150));
84 82
85 colors[0] = SK_ColorBLUE; 83 colors[0] = SK_ColorBLUE;
86 colors[1] = SK_ColorMAGENTA; 84 colors[1] = SK_ColorMAGENTA;
87 show_bm(canvas, big, small, colors); 85 show_image(canvas, big, small, colors);
88 canvas->translate(0, SkIntToScalar(150)); 86 canvas->translate(0, SkIntToScalar(150));
89 87
90 colors[0] = SK_ColorMAGENTA; 88 colors[0] = SK_ColorMAGENTA;
91 colors[1] = SK_ColorYELLOW; 89 colors[1] = SK_ColorYELLOW;
92 show_bm(canvas, medium, medium, colors); 90 show_image(canvas, medium, medium, colors);
93 canvas->translate(0, SkIntToScalar(150)); 91 canvas->translate(0, SkIntToScalar(150));
94 92
95 colors[0] = SK_ColorGREEN; 93 colors[0] = SK_ColorGREEN;
96 colors[1] = SK_ColorYELLOW; 94 colors[1] = SK_ColorYELLOW;
97 // as of this writing, the raster code will fail to draw the scaled vers ion 95 // as of this writing, the raster code will fail to draw the scaled vers ion
98 // since it has a 64K limit on x,y coordinates... (but gpu should succee d) 96 // since it has a 64K limit on x,y coordinates... (but gpu should succee d)
99 show_bm(canvas, veryBig, small, colors); 97 show_image(canvas, veryBig, small, colors);
100 } 98 }
101 99
102 private: 100 private:
103 typedef skiagm::GM INHERITED; 101 typedef skiagm::GM INHERITED;
104 }; 102 };
103 DEF_GM( return new VeryLargeBitmapGM; )
105 104
106 //////////////////////////////////////////////////////////////////////////////
107
108 static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
109 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698