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

Side by Side Diff: samplecode/SampleTinyBitmap.cpp

Issue 26572006: Revert "Revert "change SkColorTable to be immutable"" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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/SampleDitherBitmap.cpp ('k') | src/core/SkBitmap.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 "SkShader.h" 10 #include "SkShader.h"
11 #include "SkView.h" 11 #include "SkView.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkUtils.h" 13 #include "SkUtils.h"
14 14
15 static SkBitmap make_bitmap() { 15 static SkBitmap make_bitmap() {
16 SkBitmap bm;
17 const int N = 1; 16 const int N = 1;
18 SkColorTable* ctable = new SkColorTable(N);
19 17
20 SkPMColor* c = ctable->lockColors(); 18 SkPMColor c[N];
21 for (int i = 0; i < N; i++) { 19 for (int i = 0; i < N; i++) {
22 c[i] = SkPackARGB32(0x80, 0x80, 0, 0); 20 c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
23 } 21 }
24 ctable->unlockColors(true); 22 SkColorTable* ctable = new SkColorTable(c, N);
23
24 SkBitmap bm;
25 bm.setConfig(SkBitmap::kIndex8_Config, 1, 1); 25 bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
26 bm.allocPixels(ctable); 26 bm.allocPixels(ctable);
27 ctable->unref(); 27 ctable->unref();
28 28
29 bm.lockPixels(); 29 bm.lockPixels();
30 for (int y = 0; y < bm.height(); y++) { 30 for (int y = 0; y < bm.height(); y++) {
31 uint8_t* p = bm.getAddr8(0, y); 31 uint8_t* p = bm.getAddr8(0, y);
32 for (int x = 0; x < bm.width(); x++) { 32 for (int x = 0; x < bm.width(); x++) {
33 p[x] = 0; 33 p[x] = 0;
34 } 34 }
(...skipping 16 matching lines...) Expand all
51 if (SampleCode::TitleQ(*evt)) { 51 if (SampleCode::TitleQ(*evt)) {
52 SampleCode::TitleR(evt, "TinyBitmap"); 52 SampleCode::TitleR(evt, "TinyBitmap");
53 return true; 53 return true;
54 } 54 }
55 return this->INHERITED::onQuery(evt); 55 return this->INHERITED::onQuery(evt);
56 } 56 }
57 57
58 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { 58 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
59 SkAutoLockPixels alp(*bm); // needed for ctable 59 SkAutoLockPixels alp(*bm); // needed for ctable
60 bm->setIsOpaque(isOpaque); 60 bm->setIsOpaque(isOpaque);
61 #if 0
62 // TODO - I think we just want to not allow this anymore
61 SkColorTable* ctable = bm->getColorTable(); 63 SkColorTable* ctable = bm->getColorTable();
62 if (ctable) { 64 if (ctable) {
63 ctable->setIsOpaque(isOpaque); 65 ctable->setIsOpaque(isOpaque);
64 } 66 }
67 #endif
65 } 68 }
66 69
67 virtual void onDrawContent(SkCanvas* canvas) { 70 virtual void onDrawContent(SkCanvas* canvas) {
68 SkShader* s = SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMo de, 71 SkShader* s = SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMo de,
69 SkShader::kMirror_TileMode); 72 SkShader::kMirror_TileMode);
70 SkPaint paint; 73 SkPaint paint;
71 paint.setShader(s)->unref(); 74 paint.setShader(s)->unref();
72 canvas->drawPaint(paint); 75 canvas->drawPaint(paint);
73 } 76 }
74 77
75 private: 78 private:
76 typedef SkView INHERITED; 79 typedef SkView INHERITED;
77 }; 80 };
78 81
79 ////////////////////////////////////////////////////////////////////////////// 82 //////////////////////////////////////////////////////////////////////////////
80 83
81 static SkView* MyFactory() { return new TinyBitmapView; } 84 static SkView* MyFactory() { return new TinyBitmapView; }
82 static SkViewRegister reg(MyFactory); 85 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleDitherBitmap.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698