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

Side by Side Diff: src/core/SkPixmap.cpp

Issue 1157303008: Revert of move erase into SkPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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 | « src/core/SkBitmap.cpp ('k') | 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 2015 Google Inc. 2 * Copyright 2015 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 "SkColorPriv.h"
9 #include "SkConfig8888.h" 8 #include "SkConfig8888.h"
10 #include "SkMask.h" 9 #include "SkMask.h"
11 #include "SkPixmap.h" 10 #include "SkPixmap.h"
12 #include "SkUtils.h"
13 11
14 void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) { 12 void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) {
15 SkASSERT(pm.addr() != NULL); 13 SkASSERT(pm.addr() != NULL);
16 14
17 this->unlock(); 15 this->unlock();
18 fPixmap = pm; 16 fPixmap = pm;
19 fUnlockProc = unlock; 17 fUnlockProc = unlock;
20 fUnlockContext = ctx; 18 fUnlockContext = ctx;
21 fIsLocked = true; 19 fIsLocked = true;
22 } 20 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 98 }
101 // here x,y are either 0 or negative 99 // here x,y are either 0 or negative
102 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); 100 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel());
103 101
104 const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.hei ght()); 102 const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.hei ght());
105 const void* srcPixels = this->addr(srcR.x(), srcR.y()); 103 const void* srcPixels = this->addr(srcR.x(), srcR.y());
106 return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, 104 return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB,
107 srcInfo, srcPixels, this->rowBytes(), this->c table()); 105 srcInfo, srcPixels, this->rowBytes(), this->c table());
108 } 106 }
109 107
110 static uint16_t pack_8888_to_4444(unsigned a, unsigned r, unsigned g, unsigned b ) {
111 unsigned pixel = (SkA32To4444(a) << SK_A4444_SHIFT) |
112 (SkR32To4444(r) << SK_R4444_SHIFT) |
113 (SkG32To4444(g) << SK_G4444_SHIFT) |
114 (SkB32To4444(b) << SK_B4444_SHIFT);
115 return SkToU16(pixel);
116 }
117
118 bool SkPixmap::erase(SkColor color, const SkIRect& inArea) const {
119 if (NULL == fPixels) {
120 return false;
121 }
122 SkIRect area;
123 if (!area.intersect(this->bounds(), inArea)) {
124 return false;
125 }
126
127 U8CPU a = SkColorGetA(color);
128 U8CPU r = SkColorGetR(color);
129 U8CPU g = SkColorGetG(color);
130 U8CPU b = SkColorGetB(color);
131
132 int height = area.height();
133 const int width = area.width();
134 const int rowBytes = this->rowBytes();
135
136 switch (this->colorType()) {
137 case kGray_8_SkColorType: {
138 if (255 != a) {
139 r = SkMulDiv255Round(r, a);
140 g = SkMulDiv255Round(g, a);
141 b = SkMulDiv255Round(b, a);
142 }
143 int gray = SkComputeLuminance(r, g, b);
144 uint8_t* p = this->writable_addr8(area.fLeft, area.fTop);
145 while (--height >= 0) {
146 memset(p, gray, width);
147 p += rowBytes;
148 }
149 break;
150 }
151 case kAlpha_8_SkColorType: {
152 uint8_t* p = this->writable_addr8(area.fLeft, area.fTop);
153 while (--height >= 0) {
154 memset(p, a, width);
155 p += rowBytes;
156 }
157 break;
158 }
159 case kARGB_4444_SkColorType:
160 case kRGB_565_SkColorType: {
161 uint16_t* p = this->writable_addr16(area.fLeft, area.fTop);
162 uint16_t v;
163
164 // make rgb premultiplied
165 if (255 != a) {
166 r = SkAlphaMul(r, a);
167 g = SkAlphaMul(g, a);
168 b = SkAlphaMul(b, a);
169 }
170
171 if (kARGB_4444_SkColorType == this->colorType()) {
172 v = pack_8888_to_4444(a, r, g, b);
173 } else {
174 v = SkPackRGB16(r >> (8 - SK_R16_BITS),
175 g >> (8 - SK_G16_BITS),
176 b >> (8 - SK_B16_BITS));
177 }
178 while (--height >= 0) {
179 sk_memset16(p, v, width);
180 p = (uint16_t*)((char*)p + rowBytes);
181 }
182 break;
183 }
184 case kBGRA_8888_SkColorType:
185 case kRGBA_8888_SkColorType: {
186 uint32_t* p = this->writable_addr32(area.fLeft, area.fTop);
187
188 if (255 != a && kPremul_SkAlphaType == this->alphaType()) {
189 r = SkAlphaMul(r, a);
190 g = SkAlphaMul(g, a);
191 b = SkAlphaMul(b, a);
192 }
193 uint32_t v = kRGBA_8888_SkColorType == this->colorType() ?
194 SkPackARGB_as_RGBA(a, r, g, b) : SkPackARGB_as_BGRA(a, r, g, b);
195
196 while (--height >= 0) {
197 sk_memset32(p, v, width);
198 p = (uint32_t*)((char*)p + rowBytes);
199 }
200 break;
201 }
202 default:
203 return false; // no change, so don't call notifyPixelsChanged()
204 }
205 return true;
206 }
207
208 //////////////////////////////////////////////////////////////////////////////// ////////////////// 108 //////////////////////////////////////////////////////////////////////////////// //////////////////
209 109
210 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(NULL) {} 110 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(NULL) {}
211 111
212 SkAutoPixmapStorage::~SkAutoPixmapStorage() { 112 SkAutoPixmapStorage::~SkAutoPixmapStorage() {
213 this->freeStorage(); 113 sk_free(fStorage);
214 } 114 }
215 115
216 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) { 116 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
217 this->freeStorage(); 117 if (fStorage) {
118 sk_free(fStorage);
119 fStorage = NULL;
120 }
218 121
219 size_t rb = info.minRowBytes(); 122 size_t rb = info.minRowBytes();
220 size_t size = info.getSafeSize(rb); 123 size_t size = info.getSafeSize(rb);
221 if (0 == size) { 124 if (0 == size) {
222 return false; 125 return false;
223 } 126 }
224 void* pixels = sk_malloc_flags(size, 0); 127 fStorage = sk_malloc_flags(size, 0);
225 if (NULL == pixels) { 128 if (NULL == fStorage) {
226 return false; 129 return false;
227 } 130 }
228 this->reset(info, pixels, rb); 131 this->reset(info, fStorage, rb);
229 fStorage = pixels;
230 return true; 132 return true;
231 } 133 }
232 134
233 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { 135 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
234 if (!this->tryAlloc(info)) { 136 if (!this->tryAlloc(info)) {
235 sk_throw(); 137 sk_throw();
236 } 138 }
237 } 139 }
OLDNEW
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698