OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |