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

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

Issue 199413013: add new readPixels with direct memory parameters (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 * 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& sr c, 166 bool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& sr c,
167 const SkImageFilter::Context& ctx, SkBitmap* re sult, 167 const SkImageFilter::Context& ctx, SkBitmap* re sult,
168 SkIPoint* offset) { 168 SkIPoint* offset) {
169 return false; 169 return false;
170 } 170 }
171 171
172 bool SkBitmapDevice::allowImageFilter(const SkImageFilter*) { 172 bool SkBitmapDevice::allowImageFilter(const SkImageFilter*) {
173 return true; 173 return true;
174 } 174 }
175 175
176 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG
176 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, 177 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap,
177 int x, int y, 178 int x, int y,
178 SkCanvas::Config8888 config8888) { 179 SkCanvas::Config8888 config8888) {
179 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); 180 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
180 SkASSERT(!bitmap.isNull()); 181 SkASSERT(!bitmap.isNull());
181 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma keXYWH(x, y, 182 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma keXYWH(x, y,
182 bitmap .width(), 183 bitmap .width(),
183 bitmap .height()))); 184 bitmap .height())));
184 185
185 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height()); 186 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.height());
186 const SkBitmap& src = this->accessBitmap(false); 187 const SkBitmap& src = this->accessBitmap(false);
187 188
188 SkBitmap subset; 189 SkBitmap subset;
189 if (!src.extractSubset(&subset, srcRect)) { 190 if (!src.extractSubset(&subset, srcRect)) {
190 return false; 191 return false;
191 } 192 }
192 if (kPMColor_SkColorType != subset.colorType()) { 193 if (kPMColor_SkColorType != subset.colorType()) {
193 // It'd be preferable to do this directly to bitmap. 194 // It'd be preferable to do this directly to bitmap.
194 subset.copyTo(&subset, kPMColor_SkColorType); 195 subset.copyTo(&subset, kPMColor_SkColorType);
195 } 196 }
196 SkAutoLockPixels alp(bitmap); 197 SkAutoLockPixels alp(bitmap);
197 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); 198 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels());
198 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); 199 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset);
199 return true; 200 return true;
200 } 201 }
202 #endif
201 203
202 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG 204 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
203 void SkBitmapDevice::writePixels(const SkBitmap& bitmap, 205 void SkBitmapDevice::writePixels(const SkBitmap& bitmap,
204 int x, int y, 206 int x, int y,
205 SkCanvas::Config8888 config8888) { 207 SkCanvas::Config8888 config8888) {
206 if (bitmap.isNull() || bitmap.getTexture()) { 208 if (bitmap.isNull() || bitmap.getTexture()) {
207 return; 209 return;
208 } 210 }
209 const SkBitmap* sprite = &bitmap; 211 const SkBitmap* sprite = &bitmap;
210 // check whether we have to handle a config8888 that doesn't match SkPMColor 212 // check whether we have to handle a config8888 that doesn't match SkPMColor
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 case kBGRA_8888_SkColorType: 310 case kBGRA_8888_SkColorType:
309 *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_ Unpremul_Config8888; 311 *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_ Unpremul_Config8888;
310 return true; 312 return true;
311 default: 313 default:
312 return false; 314 return false;
313 } 315 }
314 } 316 }
315 317
316 // TODO: make this guy real, and not rely on legacy config8888 utility 318 // TODO: make this guy real, and not rely on legacy config8888 utility
317 #include "SkConfig8888.h" 319 #include "SkConfig8888.h"
318 static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes, 320 static bool copy_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstR owBytes,
319 const SkImageInfo& srcInfo, const void* srcPixels, size _t srcRowBytes) { 321 const SkImageInfo& srcInfo, const void* srcPixels, size_ t srcRowBytes) {
320 if (srcInfo.dimensions() != dstInfo.dimensions()) { 322 if (srcInfo.dimensions() != dstInfo.dimensions()) {
321 return false; 323 return false;
322 } 324 }
323 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { 325 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) {
324 SkCanvas::Config8888 srcConfig, dstConfig; 326 SkCanvas::Config8888 srcConfig, dstConfig;
325 if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, & dstConfig)) { 327 if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, & dstConfig)) {
326 return false; 328 return false;
327 } 329 }
328 SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig, 330 SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig,
329 (const uint32_t*)srcPixels, srcRowBytes, srcCo nfig, 331 (const uint32_t*)srcPixels, srcRowBytes, srcCo nfig,
(...skipping 27 matching lines...) Expand all
357 return false; 359 return false;
358 } 360 }
359 361
360 SkImageInfo dstInfo = fBitmap.info(); 362 SkImageInfo dstInfo = fBitmap.info();
361 dstInfo.fWidth = srcInfo.width(); 363 dstInfo.fWidth = srcInfo.width();
362 dstInfo.fHeight = srcInfo.height(); 364 dstInfo.fHeight = srcInfo.height();
363 365
364 void* dstPixels = fBitmap.getAddr(x, y); 366 void* dstPixels = fBitmap.getAddr(x, y);
365 size_t dstRowBytes = fBitmap.rowBytes(); 367 size_t dstRowBytes = fBitmap.rowBytes();
366 368
367 if (write_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRow Bytes)) { 369 if (copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowB ytes)) {
368 fBitmap.notifyPixelsChanged(); 370 fBitmap.notifyPixelsChanged();
369 return true; 371 return true;
370 } 372 }
371 return false; 373 return false;
372 } 374 }
373 375
376 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
377 int x, int y) {
378 // since we don't stop creating un-pixeled devices yet, check for no pixels here
379 if (NULL == fBitmap.getPixels()) {
380 return false;
381 }
382
383 SkImageInfo srcInfo = fBitmap.info();
384
385 // perhaps can relax these in the future
386 if (4 != dstInfo.bytesPerPixel()) {
387 return false;
388 }
389 if (4 != srcInfo.bytesPerPixel()) {
390 return false;
391 }
392
393 srcInfo.fWidth = dstInfo.width();
394 srcInfo.fHeight = dstInfo.height();
395
396 const void* srcPixels = fBitmap.getAddr(x, y);
397 const size_t srcRowBytes = fBitmap.rowBytes();
398
399 return copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcR owBytes);
400 }
401
374 /////////////////////////////////////////////////////////////////////////////// 402 ///////////////////////////////////////////////////////////////////////////////
375 403
376 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 404 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
377 draw.drawPaint(paint); 405 draw.drawPaint(paint);
378 } 406 }
379 407
380 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count, 408 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count,
381 const SkPoint pts[], const SkPaint& paint) { 409 const SkPoint pts[], const SkPaint& paint) {
382 CHECK_FOR_ANNOTATION(paint); 410 CHECK_FOR_ANNOTATION(paint);
383 draw.drawPoints(mode, count, pts, paint); 411 draw.drawPoints(mode, count, pts, paint);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 paint.getStyle() != SkPaint::kFill_Style || 608 paint.getStyle() != SkPaint::kFill_Style ||
581 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 609 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
582 // turn off lcd 610 // turn off lcd
583 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 611 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
584 flags->fHinting = paint.getHinting(); 612 flags->fHinting = paint.getHinting();
585 return true; 613 return true;
586 } 614 }
587 // we're cool with the paint as is 615 // we're cool with the paint as is
588 return false; 616 return false;
589 } 617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698