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

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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 tmp.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), 691 tmp.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(),
692 bounds.height()); 692 bounds.height());
693 if (this->readPixels(&tmp, bounds.fLeft, bounds.fTop)) { 693 if (this->readPixels(&tmp, bounds.fLeft, bounds.fTop)) {
694 bitmap->swap(tmp); 694 bitmap->swap(tmp);
695 return true; 695 return true;
696 } else { 696 } else {
697 return false; 697 return false;
698 } 698 }
699 } 699 }
700 700
701 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
701 void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y, 702 void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y,
702 Config8888 config8888) { 703 Config8888 config8888) {
703 SkBaseDevice* device = this->getDevice(); 704 SkBaseDevice* device = this->getDevice();
704 if (device) { 705 if (device) {
705 if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()), 706 if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()),
706 SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.h eight()))) { 707 SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.h eight()))) {
707 device->accessBitmap(true); 708 device->accessBitmap(true);
708 device->writePixels(bitmap, x, y, config8888); 709 device->writePixels(bitmap, x, y, config8888);
709 } 710 }
710 } 711 }
711 } 712 }
713 #endif
714
715 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) {
716 SkBitmap bm(bitmap);
717 bm.lockPixels();
718 if (bm.getPixels()) {
719 return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y) ;
720 }
721 return false;
722 }
723
724 bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size _t rowBytes,
725 int x, int y) {
726 switch (origInfo.colorType()) {
727 case kUnknown_SkColorType:
728 case kIndex_8_SkColorType:
729 return false;
730 default:
731 break;
732 }
733 if (NULL == pixels || rowBytes < origInfo.minRowBytes()) {
734 return false;
735 }
736
737 const SkISize size = this->getBaseLayerSize();
738 SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height() );
739 if (!target.intersect(0, 0, size.width(), size.height())) {
740 return false;
741 }
742
743 // should we call this->flush() for the device?
bsalomon 2014/03/06 17:48:12 I don't think so. GrContext knows to flush on a wr
reed1 2014/03/06 20:21:29 Done.
744 SkBaseDevice* device = this->getDevice();
745 if (!device) {
746 return false;
747 }
748
749 SkImageInfo info = origInfo;
750 // the intersect may have shrunk info's logical size
751 info.fWidth = target.width();
752 info.fHeight = target.height();
753
754 // if x or y are negative, then we have to adjust pixels
755 if (x > 0) {
756 x = 0;
757 }
758 if (y > 0) {
759 y = 0;
760 }
761 // here x,y are either 0 or negative
762 pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel());
763
764 // The device can assert that the requested area is always contained in its bounds
765 return device->writePixelsDirect(info, pixels, rowBytes, target.x(), target. y());
766 }
712 767
713 SkCanvas* SkCanvas::canvasForDrawIter() { 768 SkCanvas* SkCanvas::canvasForDrawIter() {
714 return this; 769 return this;
715 } 770 }
716 771
717 ////////////////////////////////////////////////////////////////////////////// 772 //////////////////////////////////////////////////////////////////////////////
718 773
719 void SkCanvas::updateDeviceCMCache() { 774 void SkCanvas::updateDeviceCMCache() {
720 if (fDeviceCMDirty) { 775 if (fDeviceCMDirty) {
721 const SkMatrix& totalMatrix = this->getTotalMatrix(); 776 const SkMatrix& totalMatrix = this->getTotalMatrix();
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 if (!bitmap.allocPixels(info)) { 2443 if (!bitmap.allocPixels(info)) {
2389 return NULL; 2444 return NULL;
2390 } 2445 }
2391 2446
2392 // should this functionality be moved into allocPixels()? 2447 // should this functionality be moved into allocPixels()?
2393 if (!bitmap.info().isOpaque()) { 2448 if (!bitmap.info().isOpaque()) {
2394 bitmap.eraseColor(0); 2449 bitmap.eraseColor(0);
2395 } 2450 }
2396 return SkNEW_ARGS(SkCanvas, (bitmap)); 2451 return SkNEW_ARGS(SkCanvas, (bitmap));
2397 } 2452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698