OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { | 138 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { |
139 if (fBitmap.getPixels()) { | 139 if (fBitmap.getPixels()) { |
140 *info = fBitmap.info(); | 140 *info = fBitmap.info(); |
141 *rowBytes = fBitmap.rowBytes(); | 141 *rowBytes = fBitmap.rowBytes(); |
142 return fBitmap.getPixels(); | 142 return fBitmap.getPixels(); |
143 } | 143 } |
144 return NULL; | 144 return NULL; |
145 } | 145 } |
146 | 146 |
147 #include "SkConfig8888.h" | 147 #include "SkConfig8888.h" |
| 148 #include "SkPixelRef.h" |
148 | 149 |
149 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
xels, | 150 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
xels, |
150 size_t srcRowBytes, int x, int y) { | 151 size_t srcRowBytes, int x, int y) { |
151 // since we don't stop creating un-pixeled devices yet, check for no pixels
here | 152 // since we don't stop creating un-pixeled devices yet, check for no pixels
here |
152 if (NULL == fBitmap.getPixels()) { | 153 if (NULL == fBitmap.getPixels()) { |
153 return false; | 154 return false; |
154 } | 155 } |
155 | 156 |
156 const SkImageInfo dstInfo = fBitmap.info().makeWH(srcInfo.width(), srcInfo.h
eight()); | 157 const SkImageInfo dstInfo = fBitmap.info().makeWH(srcInfo.width(), srcInfo.h
eight()); |
157 | 158 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 255 } |
255 // recompute dst, based on the smaller tmpSrc | 256 // recompute dst, based on the smaller tmpSrc |
256 matrix.mapRect(&tmpDst, tmpSrc); | 257 matrix.mapRect(&tmpDst, tmpSrc); |
257 dstPtr = &tmpDst; | 258 dstPtr = &tmpDst; |
258 } | 259 } |
259 | 260 |
260 // since we may need to clamp to the borders of the src rect within | 261 // since we may need to clamp to the borders of the src rect within |
261 // the bitmap, we extract a subset. | 262 // the bitmap, we extract a subset. |
262 SkIRect srcIR; | 263 SkIRect srcIR; |
263 tmpSrc.roundOut(&srcIR); | 264 tmpSrc.roundOut(&srcIR); |
264 if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { | 265 if(bitmap.pixelRef()->getTexture()) { |
265 return; | 266 // Accelerated source canvas, don't use extractSubset but readPixels
to get the subset. |
| 267 // This way, the pixels are copied in CPU memory instead of GPU memo
ry. |
| 268 bitmap.pixelRef()->readPixels(&tmpBitmap, &srcIR); |
| 269 } else { |
| 270 if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { |
| 271 return; |
| 272 } |
266 } | 273 } |
267 bitmapPtr = &tmpBitmap; | 274 bitmapPtr = &tmpBitmap; |
268 | 275 |
269 // Since we did an extract, we need to adjust the matrix accordingly | 276 // Since we did an extract, we need to adjust the matrix accordingly |
270 SkScalar dx = 0, dy = 0; | 277 SkScalar dx = 0, dy = 0; |
271 if (srcIR.fLeft > 0) { | 278 if (srcIR.fLeft > 0) { |
272 dx = SkIntToScalar(srcIR.fLeft); | 279 dx = SkIntToScalar(srcIR.fLeft); |
273 } | 280 } |
274 if (srcIR.fTop > 0) { | 281 if (srcIR.fTop > 0) { |
275 dy = SkIntToScalar(srcIR.fTop); | 282 dy = SkIntToScalar(srcIR.fTop); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 paint.getStyle() != SkPaint::kFill_Style || | 396 paint.getStyle() != SkPaint::kFill_Style || |
390 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 397 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
391 // turn off lcd, but turn on kGenA8 | 398 // turn off lcd, but turn on kGenA8 |
392 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 399 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
393 flags->fFlags |= SkPaint::kGenA8FromLCD_Flag; | 400 flags->fFlags |= SkPaint::kGenA8FromLCD_Flag; |
394 return true; | 401 return true; |
395 } | 402 } |
396 // we're cool with the paint as is | 403 // we're cool with the paint as is |
397 return false; | 404 return false; |
398 } | 405 } |
OLD | NEW |