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

Side by Side Diff: samplecode/SampleTinyBitmap.cpp

Issue 26709002: 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;
16 const int N = 1; 17 const int N = 1;
18 SkColorTable* ctable = new SkColorTable(N);
17 19
18 SkPMColor c[N]; 20 SkPMColor* c = ctable->lockColors();
19 for (int i = 0; i < N; i++) { 21 for (int i = 0; i < N; i++) {
20 c[i] = SkPackARGB32(0x80, 0x80, 0, 0); 22 c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
21 } 23 }
22 SkColorTable* ctable = new SkColorTable(c, N); 24 ctable->unlockColors(true);
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
63 SkColorTable* ctable = bm->getColorTable(); 61 SkColorTable* ctable = bm->getColorTable();
64 if (ctable) { 62 if (ctable) {
65 ctable->setIsOpaque(isOpaque); 63 ctable->setIsOpaque(isOpaque);
66 } 64 }
67 #endif
68 } 65 }
69 66
70 virtual void onDrawContent(SkCanvas* canvas) { 67 virtual void onDrawContent(SkCanvas* canvas) {
71 SkShader* s = SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMo de, 68 SkShader* s = SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMo de,
72 SkShader::kMirror_TileMode); 69 SkShader::kMirror_TileMode);
73 SkPaint paint; 70 SkPaint paint;
74 paint.setShader(s)->unref(); 71 paint.setShader(s)->unref();
75 canvas->drawPaint(paint); 72 canvas->drawPaint(paint);
76 } 73 }
77 74
78 private: 75 private:
79 typedef SkView INHERITED; 76 typedef SkView INHERITED;
80 }; 77 };
81 78
82 ////////////////////////////////////////////////////////////////////////////// 79 //////////////////////////////////////////////////////////////////////////////
83 80
84 static SkView* MyFactory() { return new TinyBitmapView; } 81 static SkView* MyFactory() { return new TinyBitmapView; }
85 static SkViewRegister reg(MyFactory); 82 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