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

Side by Side Diff: gm/xfermodes2.cpp

Issue 140593005: add legacy/helper allocN32Pixels, and convert gm to use it (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 | « gm/xfermodes.cpp ('k') | gm/xfermodes3.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 2013 Google Inc. 3 * Copyright 2013 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 "gm.h" 8 #include "gm.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkShader.h" 10 #include "SkShader.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 private: 87 private:
88 virtual void onOnceBeforeDraw() SK_OVERRIDE { 88 virtual void onOnceBeforeDraw() SK_OVERRIDE {
89 static const uint32_t kCheckData[] = { 89 static const uint32_t kCheckData[] = {
90 SkPackARGB32(0xFF, 0x40, 0x40, 0x40), 90 SkPackARGB32(0xFF, 0x40, 0x40, 0x40),
91 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0), 91 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0),
92 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0), 92 SkPackARGB32(0xFF, 0xD0, 0xD0, 0xD0),
93 SkPackARGB32(0xFF, 0x40, 0x40, 0x40) 93 SkPackARGB32(0xFF, 0x40, 0x40, 0x40)
94 }; 94 };
95 SkBitmap bg; 95 SkBitmap bg;
96 bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2, 0, kOpaque_SkAlphaType); 96 bg.allocN32Pixels(2, 2, true);
97 bg.allocPixels();
98 SkAutoLockPixels bgAlp(bg);
99 memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); 97 memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData));
100 98
101 fBG.reset(SkShader::CreateBitmapShader(bg, 99 fBG.reset(SkShader::CreateBitmapShader(bg,
102 SkShader::kRepeat_TileMode, 100 SkShader::kRepeat_TileMode,
103 SkShader::kRepeat_TileMode)); 101 SkShader::kRepeat_TileMode));
104 SkMatrix lm; 102 SkMatrix lm;
105 lm.setScale(SkIntToScalar(16), SkIntToScalar(16)); 103 lm.setScale(SkIntToScalar(16), SkIntToScalar(16));
106 fBG->setLocalMatrix(lm); 104 fBG->setLocalMatrix(lm);
107 105
108 SkBitmap dstBmp; 106 SkBitmap dstBmp;
109 dstBmp.setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize); 107 dstBmp.allocN32Pixels(kSize, kSize);
110 dstBmp.allocPixels();
111 SkAutoLockPixels dstAlp(dstBmp);
112 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels()); 108 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels());
113 109
114 for (int y = 0; y < kSize; ++y) { 110 for (int y = 0; y < kSize; ++y) {
115 int c = y * (1 << kShift); 111 int c = y * (1 << kShift);
116 SkPMColor rowColor = SkPackARGB32(c, c, 0, c/2); 112 SkPMColor rowColor = SkPackARGB32(c, c, 0, c/2);
117 for (int x = 0; x < kSize; ++x) { 113 for (int x = 0; x < kSize; ++x) {
118 pixels[kSize * y + x] = rowColor; 114 pixels[kSize * y + x] = rowColor;
119 } 115 }
120 } 116 }
121 fSrc.reset(SkShader::CreateBitmapShader(dstBmp, 117 fSrc.reset(SkShader::CreateBitmapShader(dstBmp,
122 SkShader::kClamp_TileMode, 118 SkShader::kClamp_TileMode,
123 SkShader::kClamp_TileMode)); 119 SkShader::kClamp_TileMode));
124 SkBitmap srcBmp; 120 SkBitmap srcBmp;
125 srcBmp.setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize); 121 srcBmp.allocN32Pixels(kSize, kSize);
126 srcBmp.allocPixels();
127 SkAutoLockPixels srcAlp(srcBmp);
128 pixels = reinterpret_cast<SkPMColor*>(srcBmp.getPixels()); 122 pixels = reinterpret_cast<SkPMColor*>(srcBmp.getPixels());
129 123
130 for (int x = 0; x < kSize; ++x) { 124 for (int x = 0; x < kSize; ++x) {
131 int c = x * (1 << kShift); 125 int c = x * (1 << kShift);
132 SkPMColor colColor = SkPackARGB32(c, 0, c, c/2); 126 SkPMColor colColor = SkPackARGB32(c, 0, c, c/2);
133 for (int y = 0; y < kSize; ++y) { 127 for (int y = 0; y < kSize; ++y) {
134 pixels[kSize * y + x] = colColor; 128 pixels[kSize * y + x] = colColor;
135 } 129 }
136 } 130 }
137 fDst.reset(SkShader::CreateBitmapShader(srcBmp, 131 fDst.reset(SkShader::CreateBitmapShader(srcBmp,
(...skipping 12 matching lines...) Expand all
150 144
151 typedef GM INHERITED; 145 typedef GM INHERITED;
152 }; 146 };
153 147
154 ////////////////////////////////////////////////////////////////////////////// 148 //////////////////////////////////////////////////////////////////////////////
155 149
156 static GM* MyFactory(void*) { return new Xfermodes2GM; } 150 static GM* MyFactory(void*) { return new Xfermodes2GM; }
157 static GMRegistry reg(MyFactory); 151 static GMRegistry reg(MyFactory);
158 152
159 } 153 }
OLDNEW
« no previous file with comments | « gm/xfermodes.cpp ('k') | gm/xfermodes3.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698