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

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

Issue 510423005: make allocPixels throw on failure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 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/SkBitmapDevice.cpp ('k') | src/core/SkPictureShader.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 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
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 8
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return device; 561 return device;
562 } 562 }
563 563
564 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { 564 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) {
565 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) { 565 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) {
566 return false; 566 return false;
567 } 567 }
568 568
569 bool weAllocated = false; 569 bool weAllocated = false;
570 if (NULL == bitmap->pixelRef()) { 570 if (NULL == bitmap->pixelRef()) {
571 if (!bitmap->allocPixels()) { 571 if (!bitmap->tryAllocPixels()) {
572 return false; 572 return false;
573 } 573 }
574 weAllocated = true; 574 weAllocated = true;
575 } 575 }
576 576
577 SkBitmap bm(*bitmap); 577 SkBitmap bm(*bitmap);
578 bm.lockPixels(); 578 bm.lockPixels();
579 if (bm.getPixels() && this->readPixels(bm.info(), bm.getPixels(), bm.rowByte s(), x, y)) { 579 if (bm.getPixels() && this->readPixels(bm.info(), bm.getPixels(), bm.rowByte s(), x, y)) {
580 return true; 580 return true;
581 } 581 }
582 582
583 if (weAllocated) { 583 if (weAllocated) {
584 bitmap->setPixelRef(NULL); 584 bitmap->setPixelRef(NULL);
585 } 585 }
586 return false; 586 return false;
587 } 587 }
588 588
589 bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { 589 bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
590 SkIRect r = srcRect; 590 SkIRect r = srcRect;
591 const SkISize size = this->getBaseLayerSize(); 591 const SkISize size = this->getBaseLayerSize();
592 if (!r.intersect(0, 0, size.width(), size.height())) { 592 if (!r.intersect(0, 0, size.width(), size.height())) {
593 bitmap->reset(); 593 bitmap->reset();
594 return false; 594 return false;
595 } 595 }
596 596
597 if (!bitmap->allocN32Pixels(r.width(), r.height())) { 597 if (!bitmap->tryAllocN32Pixels(r.width(), r.height())) {
598 // bitmap will already be reset. 598 // bitmap will already be reset.
599 return false; 599 return false;
600 } 600 }
601 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), r.x(), r.y())) { 601 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), r.x(), r.y())) {
602 bitmap->reset(); 602 bitmap->reset();
603 return false; 603 return false;
604 } 604 }
605 return true; 605 return true;
606 } 606 }
607 607
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 999
1000 void* SkCanvas::onAccessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) { 1000 void* SkCanvas::onAccessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) {
1001 SkBaseDevice* dev = this->getTopDevice(); 1001 SkBaseDevice* dev = this->getTopDevice();
1002 return dev ? dev->accessPixels(info, rowBytes) : NULL; 1002 return dev ? dev->accessPixels(info, rowBytes) : NULL;
1003 } 1003 }
1004 1004
1005 SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { 1005 SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) {
1006 fAddr = canvas->peekPixels(&fInfo, &fRowBytes); 1006 fAddr = canvas->peekPixels(&fInfo, &fRowBytes);
1007 if (NULL == fAddr) { 1007 if (NULL == fAddr) {
1008 fInfo = canvas->imageInfo(); 1008 fInfo = canvas->imageInfo();
1009 if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.allocPixels(fI nfo)) { 1009 if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels (fInfo)) {
1010 return; // failure, fAddr is NULL 1010 return; // failure, fAddr is NULL
1011 } 1011 }
1012 if (!canvas->readPixels(&fBitmap, 0, 0)) { 1012 if (!canvas->readPixels(&fBitmap, 0, 0)) {
1013 return; // failure, fAddr is NULL 1013 return; // failure, fAddr is NULL
1014 } 1014 }
1015 fAddr = fBitmap.getPixels(); 1015 fAddr = fBitmap.getPixels();
1016 fRowBytes = fBitmap.rowBytes(); 1016 fRowBytes = fBitmap.rowBytes();
1017 } 1017 }
1018 SkASSERT(fAddr); // success 1018 SkASSERT(fAddr); // success
1019 } 1019 }
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
2528 2528
2529 return true; 2529 return true;
2530 } 2530 }
2531 2531
2532 SkCanvas* SkCanvas::NewRaster(const SkImageInfo& info) { 2532 SkCanvas* SkCanvas::NewRaster(const SkImageInfo& info) {
2533 if (!supported_for_raster_canvas(info)) { 2533 if (!supported_for_raster_canvas(info)) {
2534 return NULL; 2534 return NULL;
2535 } 2535 }
2536 2536
2537 SkBitmap bitmap; 2537 SkBitmap bitmap;
2538 if (!bitmap.allocPixels(info)) { 2538 if (!bitmap.tryAllocPixels(info)) {
2539 return NULL; 2539 return NULL;
2540 } 2540 }
2541 2541
2542 // should this functionality be moved into allocPixels()? 2542 // should this functionality be moved into allocPixels()?
2543 if (!bitmap.info().isOpaque()) { 2543 if (!bitmap.info().isOpaque()) {
2544 bitmap.eraseColor(0); 2544 bitmap.eraseColor(0);
2545 } 2545 }
2546 return SkNEW_ARGS(SkCanvas, (bitmap)); 2546 return SkNEW_ARGS(SkCanvas, (bitmap));
2547 } 2547 }
2548 2548
(...skipping 27 matching lines...) Expand all
2576 } 2576 }
2577 2577
2578 if (NULL != matrix) { 2578 if (NULL != matrix) {
2579 canvas->concat(*matrix); 2579 canvas->concat(*matrix);
2580 } 2580 }
2581 } 2581 }
2582 2582
2583 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2583 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2584 fCanvas->restoreToCount(fSaveCount); 2584 fCanvas->restoreToCount(fSaveCount);
2585 } 2585 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkPictureShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698