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

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

Issue 180113010: Add SkCanvas::writePixels that takes info+pixels directly (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | « include/gpu/SkGpuDevice.h ('k') | src/core/SkCanvas.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (kPMColor_SkColorType != subset.colorType()) { 192 if (kPMColor_SkColorType != subset.colorType()) {
193 // It'd be preferable to do this directly to bitmap. 193 // It'd be preferable to do this directly to bitmap.
194 subset.copyTo(&subset, kPMColor_SkColorType); 194 subset.copyTo(&subset, kPMColor_SkColorType);
195 } 195 }
196 SkAutoLockPixels alp(bitmap); 196 SkAutoLockPixels alp(bitmap);
197 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); 197 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels());
198 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); 198 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset);
199 return true; 199 return true;
200 } 200 }
201 201
202 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
202 void SkBitmapDevice::writePixels(const SkBitmap& bitmap, 203 void SkBitmapDevice::writePixels(const SkBitmap& bitmap,
203 int x, int y, 204 int x, int y,
204 SkCanvas::Config8888 config8888) { 205 SkCanvas::Config8888 config8888) {
205 if (bitmap.isNull() || bitmap.getTexture()) { 206 if (bitmap.isNull() || bitmap.getTexture()) {
206 return; 207 return;
207 } 208 }
208 const SkBitmap* sprite = &bitmap; 209 const SkBitmap* sprite = &bitmap;
209 // check whether we have to handle a config8888 that doesn't match SkPMColor 210 // check whether we have to handle a config8888 that doesn't match SkPMColor
210 if (SkBitmap::kARGB_8888_Config == bitmap.config() && 211 if (SkBitmap::kARGB_8888_Config == bitmap.config() &&
211 SkCanvas::kNative_Premul_Config8888 != config8888 && 212 SkCanvas::kNative_Premul_Config8888 != config8888 &&
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 SkPaint paint; 259 SkPaint paint;
259 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 260 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
260 SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height())); 261 SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height()));
261 SkDraw draw; 262 SkDraw draw;
262 draw.fRC = &clip; 263 draw.fRC = &clip;
263 draw.fClip = &clip.bwRgn(); 264 draw.fClip = &clip.bwRgn();
264 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap 265 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap
265 draw.fMatrix = &SkMatrix::I(); 266 draw.fMatrix = &SkMatrix::I();
266 this->drawSprite(draw, *sprite, x, y, paint); 267 this->drawSprite(draw, *sprite, x, y, paint);
267 } 268 }
269 #endif
270
271 static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow,
272 int rowCount) {
273 SkASSERT(bytesPerRow <= srcRB);
274 SkASSERT(bytesPerRow <= dstRB);
275 for (int i = 0; i < rowCount; ++i) {
276 memcpy(dst, src, bytesPerRow);
277 dst = (char*)dst + dstRB;
278 src = (const char*)src + srcRB;
279 }
280 }
281
282 static bool info2config8888(const SkImageInfo& info, SkCanvas::Config8888* confi g) {
283 bool pre;
284 switch (info.alphaType()) {
285 case kPremul_SkAlphaType:
286 case kOpaque_SkAlphaType:
287 pre = true;
288 break;
289 case kUnpremul_SkAlphaType:
290 pre = false;
291 break;
292 default:
293 return false;
294 }
295 switch (info.colorType()) {
296 case kRGBA_8888_SkColorType:
297 *config = pre ? SkCanvas::kRGBA_Premul_Config8888 : SkCanvas::kRGBA_ Unpremul_Config8888;
298 return true;
299 case kBGRA_8888_SkColorType:
300 *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_ Unpremul_Config8888;
301 return true;
302 default:
303 return false;
304 }
305 }
306
307 // TODO: make this guy real, and not rely on legacy config8888 utility
308 #include "SkConfig8888.h"
309 static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes,
310 const SkImageInfo& srcInfo, const void* srcPixels, size _t srcRowBytes) {
311 if (srcInfo.dimensions() != dstInfo.dimensions()) {
312 return false;
313 }
314 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) {
315 SkCanvas::Config8888 srcConfig, dstConfig;
316 if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, & dstConfig)) {
317 return false;
318 }
319 SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig,
320 (const uint32_t*)srcPixels, srcRowBytes, srcCo nfig,
321 srcInfo.width(), srcInfo.height());
322 return true;
323 }
324 if (srcInfo.colorType() == dstInfo.colorType()) {
325 switch (srcInfo.colorType()) {
326 case kRGB_565_SkColorType:
327 case kAlpha_8_SkColorType:
328 break;
329 case kARGB_4444_SkColorType:
330 if (srcInfo.alphaType() != dstInfo.alphaType()) {
331 return false;
332 }
333 break;
334 default:
335 return false;
336 }
337 rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes,
338 srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height()) ;
339 }
340 // TODO: add support for more conversions as needed
341 return false;
342 }
343
344 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi xels,
345 size_t srcRowBytes, int x, int y) {
346 SkImageInfo dstInfo = fBitmap.info();
347 dstInfo.fWidth = srcInfo.width();
348 dstInfo.fHeight = srcInfo.height();
349
350 void* dstPixels = fBitmap.getAddr(x, y);
351 size_t dstRowBytes = fBitmap.rowBytes();
352
353 if (write_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRow Bytes)) {
354 fBitmap.notifyPixelsChanged();
355 return true;
356 }
357 return false;
358 }
268 359
269 /////////////////////////////////////////////////////////////////////////////// 360 ///////////////////////////////////////////////////////////////////////////////
270 361
271 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 362 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
272 draw.drawPaint(paint); 363 draw.drawPaint(paint);
273 } 364 }
274 365
275 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count, 366 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count,
276 const SkPoint pts[], const SkPaint& paint) { 367 const SkPoint pts[], const SkPaint& paint) {
277 CHECK_FOR_ANNOTATION(paint); 368 CHECK_FOR_ANNOTATION(paint);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 paint.getStyle() != SkPaint::kFill_Style || 566 paint.getStyle() != SkPaint::kFill_Style ||
476 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 567 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
477 // turn off lcd 568 // turn off lcd
478 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 569 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
479 flags->fHinting = paint.getHinting(); 570 flags->fHinting = paint.getHinting();
480 return true; 571 return true;
481 } 572 }
482 // we're cool with the paint as is 573 // we're cool with the paint as is
483 return false; 574 return false;
484 } 575 }
OLDNEW
« no previous file with comments | « include/gpu/SkGpuDevice.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698