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

Side by Side Diff: src/image/SkImage.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/gpu/SkGrPixelRef.cpp ('k') | src/images/SkDecodingImageGenerator.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 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImagePriv.h" 10 #include "SkImagePriv.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 bool SkImage_Base::onReadPixels(SkBitmap* bitmap, const SkIRect& subset) const { 110 bool SkImage_Base::onReadPixels(SkBitmap* bitmap, const SkIRect& subset) const {
111 if (bitmap->pixelRef()) { 111 if (bitmap->pixelRef()) {
112 const SkImageInfo info = bitmap->info(); 112 const SkImageInfo info = bitmap->info();
113 if (kUnknown_SkColorType == info.colorType()) { 113 if (kUnknown_SkColorType == info.colorType()) {
114 return false; 114 return false;
115 } 115 }
116 if (!raster_canvas_supports(info)) { 116 if (!raster_canvas_supports(info)) {
117 return false; 117 return false;
118 } 118 }
119 } else { 119 } else {
120 const SkImageInfo info = SkImageInfo::MakeN32Premul(subset.width(), subs et.height());
121 SkBitmap tmp; 120 SkBitmap tmp;
122 if (!tmp.allocPixels(info)) { 121 if (!tmp.tryAllocN32Pixels(subset.width(), subset.height())) {
123 return false; 122 return false;
124 } 123 }
125 *bitmap = tmp; 124 *bitmap = tmp;
126 } 125 }
127 126
128 SkRect srcR, dstR; 127 SkRect srcR, dstR;
129 srcR.set(subset); 128 srcR.set(subset);
130 dstR = srcR; 129 dstR = srcR;
131 dstR.offset(-dstR.left(), -dstR.top()); 130 dstR.offset(-dstR.left(), -dstR.top());
132 131
133 SkCanvas canvas(*bitmap); 132 SkCanvas canvas(*bitmap);
134 133
135 SkPaint paint; 134 SkPaint paint;
136 paint.setXfermodeMode(SkXfermode::kClear_Mode); 135 paint.setXfermodeMode(SkXfermode::kClear_Mode);
137 canvas.drawRect(dstR, paint); 136 canvas.drawRect(dstR, paint);
138 137
139 const_cast<SkImage_Base*>(this)->onDrawRectToRect(&canvas, &srcR, dstR, NULL ); 138 const_cast<SkImage_Base*>(this)->onDrawRectToRect(&canvas, &srcR, dstR, NULL );
140 return true; 139 return true;
141 } 140 }
OLDNEW
« no previous file with comments | « src/gpu/SkGrPixelRef.cpp ('k') | src/images/SkDecodingImageGenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698