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

Side by Side Diff: src/core/SkCanvas.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 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
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 8
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 SkBaseDevice* device = this->getDevice(); 703 SkBaseDevice* device = this->getDevice();
704 if (device) { 704 if (device) {
705 if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()), 705 if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()),
706 SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.h eight()))) { 706 SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.h eight()))) {
707 device->accessBitmap(true); 707 device->accessBitmap(true);
708 device->writePixels(bitmap, x, y, config8888); 708 device->writePixels(bitmap, x, y, config8888);
709 } 709 }
710 } 710 }
711 } 711 }
712 712
713 bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size _t rowBytes,
714 int x, int y) {
715 switch (origInfo.colorType()) {
716 case kUnknown_SkColorType:
717 case kIndex_8_SkColorType:
718 return false;
719 default:
720 break;
721 }
722 if (NULL == pixels || rowBytes < origInfo.minRowBytes()) {
723 return false;
724 }
725
726 const SkISize size = this->getBaseLayerSize();
727 SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height() );
728 if (!target.intersect(0, 0, size.width(), size.height())) {
729 return false;
730 }
731
732 // should we call this->flush() for the device?
733 SkBaseDevice* device = this->getDevice();
734 if (!device) {
735 return false;
736 }
737
738 SkImageInfo info = origInfo;
739 // the intersect may have shrunk info's logical size
740 info.fWidth = target.width();
741 info.fHeight = target.height();
742
743 // if x or y are negative, then we have to adjust pixels
744 if (x > 0) {
745 x = 0;
746 }
747 if (y > 0) {
748 y = 0;
749 }
750 // here x,y are either 0 or negative
751 pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel());
752
753 // The device can assert that the requested area is always contained in its bounds
754 return device->writePixelsDirect(info, pixels, rowBytes, target.x(), target. y());
755 }
756
713 SkCanvas* SkCanvas::canvasForDrawIter() { 757 SkCanvas* SkCanvas::canvasForDrawIter() {
714 return this; 758 return this;
715 } 759 }
716 760
717 ////////////////////////////////////////////////////////////////////////////// 761 //////////////////////////////////////////////////////////////////////////////
718 762
719 void SkCanvas::updateDeviceCMCache() { 763 void SkCanvas::updateDeviceCMCache() {
720 if (fDeviceCMDirty) { 764 if (fDeviceCMDirty) {
721 const SkMatrix& totalMatrix = this->getTotalMatrix(); 765 const SkMatrix& totalMatrix = this->getTotalMatrix();
722 const SkRasterClip& totalClip = *fMCRec->fRasterClip; 766 const SkRasterClip& totalClip = *fMCRec->fRasterClip;
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 if (!bitmap.allocPixels(info)) { 2432 if (!bitmap.allocPixels(info)) {
2389 return NULL; 2433 return NULL;
2390 } 2434 }
2391 2435
2392 // should this functionality be moved into allocPixels()? 2436 // should this functionality be moved into allocPixels()?
2393 if (!bitmap.info().isOpaque()) { 2437 if (!bitmap.info().isOpaque()) {
2394 bitmap.eraseColor(0); 2438 bitmap.eraseColor(0);
2395 } 2439 }
2396 return SkNEW_ARGS(SkCanvas, (bitmap)); 2440 return SkNEW_ARGS(SkCanvas, (bitmap));
2397 } 2441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698