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

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
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 259 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
260 SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height())); 260 SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height()));
261 SkDraw draw; 261 SkDraw draw;
262 draw.fRC = &clip; 262 draw.fRC = &clip;
263 draw.fClip = &clip.bwRgn(); 263 draw.fClip = &clip.bwRgn();
264 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap 264 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap
265 draw.fMatrix = &SkMatrix::I(); 265 draw.fMatrix = &SkMatrix::I();
266 this->drawSprite(draw, *sprite, x, y, paint); 266 this->drawSprite(draw, *sprite, x, y, paint);
267 } 267 }
268 268
269 static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow,
270 int rowCount) {
271 SkASSERT(bytesPerRow <= srcRB);
272 SkASSERT(bytesPerRow <= dstRB);
273 for (int i = 0; i < rowCount; ++i) {
274 memcpy(dst, src, bytesPerRow);
275 dst = (char*)dst + dstRB;
276 src = (const char*)src + srcRB;
277 }
278 }
279
280 static bool info2config8888(const SkImageInfo& info, SkCanvas::Config8888* confi g) {
281 bool pre;
282 switch (info.alphaType()) {
283 case kPremul_SkAlphaType:
284 case kOpaque_SkAlphaType:
285 pre = true;
286 break;
287 case kUnpremul_SkAlphaType:
288 pre = false;
289 break;
290 default:
291 return false;
292 }
293 switch (info.colorType()) {
294 case kRGBA_8888_SkColorType:
295 *config = pre ? SkCanvas::kRGBA_Premul_Config8888 : SkCanvas::kRGBA_ Unpremul_Config8888;
296 return true;
297 case kBGRA_8888_SkColorType:
298 *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_ Unpremul_Config8888;
299 return true;
300 default:
301 return false;
302 }
303 }
304
305 // TODO: make this guy real, and not rely on legacy config8888 utility
306 #include "SkConfig8888.h"
307 static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes,
308 const SkImageInfo& srcInfo, const void* srcPixels, size _t srcRowBytes) {
309 if (srcInfo.dimensions() != dstInfo.dimensions()) {
310 return false;
311 }
312 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) {
313 SkCanvas::Config8888 srcConfig, dstConfig;
314 if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, & dstConfig)) {
315 return false;
316 }
317 SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig,
318 (const uint32_t*)srcPixels, srcRowBytes, srcCo nfig,
319 srcInfo.width(), srcInfo.height());
320 return true;
321 }
322 if (srcInfo.colorType() == dstInfo.colorType()) {
323 switch (srcInfo.colorType()) {
324 case kRGB_565_SkColorType:
325 case kAlpha_8_SkColorType:
326 break;
327 case kARGB_4444_SkColorType:
328 if (srcInfo.alphaType() != dstInfo.alphaType()) {
329 return false;
330 }
331 break;
332 default:
333 return false;
334 }
335 rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes,
336 srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height()) ;
337 }
338 // TODO: add support for more conversions as needed
339 return false;
340 }
341
342 bool SkBitmapDevice::onWritePixelsDirect(const SkImageInfo& srcInfo, const void* srcPixels,
343 size_t srcRowBytes, int x, int y) {
344 SkImageInfo dstInfo = fBitmap.info();
345 dstInfo.fWidth = srcInfo.width();
346 dstInfo.fHeight = srcInfo.height();
347
348 void* dstPixels = fBitmap.getAddr(x, y);
349 size_t dstRowBytes = fBitmap.rowBytes();
350
351 return write_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, src RowBytes);
352 }
353
269 /////////////////////////////////////////////////////////////////////////////// 354 ///////////////////////////////////////////////////////////////////////////////
270 355
271 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 356 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
272 draw.drawPaint(paint); 357 draw.drawPaint(paint);
273 } 358 }
274 359
275 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count, 360 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count,
276 const SkPoint pts[], const SkPaint& paint) { 361 const SkPoint pts[], const SkPaint& paint) {
277 CHECK_FOR_ANNOTATION(paint); 362 CHECK_FOR_ANNOTATION(paint);
278 draw.drawPoints(mode, count, pts, paint); 363 draw.drawPoints(mode, count, pts, paint);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 paint.getStyle() != SkPaint::kFill_Style || 560 paint.getStyle() != SkPaint::kFill_Style ||
476 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 561 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
477 // turn off lcd 562 // turn off lcd
478 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 563 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
479 flags->fHinting = paint.getHinting(); 564 flags->fHinting = paint.getHinting();
480 return true; 565 return true;
481 } 566 }
482 // we're cool with the paint as is 567 // we're cool with the paint as is
483 return false; 568 return false;
484 } 569 }
OLDNEW
« include/core/SkCanvas.h ('K') | « include/gpu/SkGpuDevice.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698