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

Side by Side Diff: samplecode/SampleDitherBitmap.cpp

Issue 132513003: SampleApp Cleanup (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: final rebase 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 | « samplecode/SampleApp.cpp ('k') | samplecode/SampleEncode.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 19 matching lines...) Expand all
30 30
31 SkPaint p; 31 SkPaint p;
32 p.setShader(s)->unref(); 32 p.setShader(s)->unref();
33 draw_rect(canvas, r, p); 33 draw_rect(canvas, r, p);
34 34
35 canvas->translate(0, SkIntToScalar(40)); 35 canvas->translate(0, SkIntToScalar(40));
36 p.setDither(true); 36 p.setDither(true);
37 draw_rect(canvas, r, p); 37 draw_rect(canvas, r, p);
38 } 38 }
39 39
40 static void test_pathregion() { 40 static bool test_pathregion() {
41 SkPath path; 41 SkPath path;
42 SkRegion region; 42 SkRegion region;
43 path.moveTo(25071800.f, -141823808.f); 43 path.moveTo(25071800.f, -141823808.f);
44 path.lineTo(25075500.f, -141824000.f); 44 path.lineTo(25075500.f, -141824000.f);
45 path.lineTo(25075400.f, -141827712.f); 45 path.lineTo(25075400.f, -141827712.f);
46 path.lineTo(25071810.f, -141827600.f); 46 path.lineTo(25071810.f, -141827600.f);
47 path.close(); 47 path.close();
48 48
49 SkIRect bounds; 49 SkIRect bounds;
50 path.getBounds().round(&bounds); 50 path.getBounds().round(&bounds);
51 SkRegion clip(bounds); 51 SkRegion clip(bounds);
52 bool result = region.setPath(path, clip); // <-- !! DOWN !! 52 return region.setPath(path, clip); // <-- !! DOWN !!
53 SkDebugf("----- result %d\n", result);
54 } 53 }
55 54
56 static SkBitmap make_bitmap() { 55 static SkBitmap make_bitmap() {
57 SkPMColor c[256]; 56 SkPMColor c[256];
58 for (int i = 0; i < 256; i++) { 57 for (int i = 0; i < 256; i++) {
59 c[i] = SkPackARGB32(0xFF, i, 0, 0); 58 c[i] = SkPackARGB32(0xFF, i, 0, 0);
60 } 59 }
61 SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType); 60 SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType);
62 61
63 SkBitmap bm; 62 SkBitmap bm;
64 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32); 63 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32);
65 bm.allocPixels(ctable); 64 bm.allocPixels(ctable);
66 ctable->unref(); 65 ctable->unref();
67 66
68 bm.lockPixels(); 67 bm.lockPixels();
69 for (int y = 0; y < bm.height(); y++) { 68 for (int y = 0; y < bm.height(); y++) {
70 uint8_t* p = bm.getAddr8(0, y); 69 uint8_t* p = bm.getAddr8(0, y);
71 for (int x = 0; x < 256; x++) { 70 for (int x = 0; x < 256; x++) {
72 p[x] = x; 71 p[x] = x;
73 } 72 }
74 } 73 }
75 bm.unlockPixels(); 74 bm.unlockPixels();
76 return bm; 75 return bm;
77 } 76 }
78 77
79 class DitherBitmapView : public SampleView { 78 class DitherBitmapView : public SampleView {
80 SkBitmap fBM8; 79 SkBitmap fBM8;
81 SkBitmap fBM32; 80 SkBitmap fBM32;
81 bool fResult;
82 public: 82 public:
83 DitherBitmapView() { 83 DitherBitmapView() {
84 test_pathregion(); 84 fResult = test_pathregion();
85 fBM8 = make_bitmap(); 85 fBM8 = make_bitmap();
86 fBM8.copyTo(&fBM32, SkBitmap::kARGB_8888_Config); 86 fBM8.copyTo(&fBM32, SkBitmap::kARGB_8888_Config);
87 87
88 this->setBGColor(0xFFDDDDDD); 88 this->setBGColor(0xFFDDDDDD);
89 } 89 }
90 90
91 protected: 91 protected:
92 // overrides from SkEventSink 92 // overrides from SkEventSink
93 virtual bool onQuery(SkEvent* evt) { 93 virtual bool onQuery(SkEvent* evt) {
94 if (SampleCode::TitleQ(*evt)) { 94 if (SampleCode::TitleQ(*evt)) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 virtual void onDrawContent(SkCanvas* canvas) { 132 virtual void onDrawContent(SkCanvas* canvas) {
133 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 133 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
134 134
135 draw2(canvas, fBM8); 135 draw2(canvas, fBM8);
136 canvas->translate(0, SkIntToScalar(fBM8.height() *3)); 136 canvas->translate(0, SkIntToScalar(fBM8.height() *3));
137 draw2(canvas, fBM32); 137 draw2(canvas, fBM32);
138 138
139 canvas->translate(0, SkIntToScalar(fBM8.height() *3)); 139 canvas->translate(0, SkIntToScalar(fBM8.height() *3));
140 draw_gradient(canvas); 140 draw_gradient(canvas);
141
142 char resultTrue[] = "SkRegion::setPath returned true";
143 char resultFalse[] = "SkRegion::setPath returned false";
144 SkPaint p;
145 if (fResult)
146 canvas->drawText(resultTrue, sizeof(resultTrue) - 1, 0, 50, p);
147 else
148 canvas->drawText(resultFalse, sizeof(resultFalse) - 1, 0, 50, p);
141 } 149 }
142 150
143 private: 151 private:
144 typedef SampleView INHERITED; 152 typedef SampleView INHERITED;
145 }; 153 };
146 154
147 ////////////////////////////////////////////////////////////////////////////// 155 //////////////////////////////////////////////////////////////////////////////
148 156
149 static SkView* MyFactory() { return new DitherBitmapView; } 157 static SkView* MyFactory() { return new DitherBitmapView; }
150 static SkViewRegister reg(MyFactory); 158 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | samplecode/SampleEncode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698