OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 354 } |
355 | 355 |
356 Vector<char> base64Data; | 356 Vector<char> base64Data; |
357 base64Encode(*reinterpret_cast<Vector<char>*>(&encodedImage), base64Data); | 357 base64Encode(*reinterpret_cast<Vector<char>*>(&encodedImage), base64Data); |
358 | 358 |
359 return "data:" + mimeType + ";base64," + base64Data; | 359 return "data:" + mimeType + ";base64," + base64Data; |
360 } | 360 } |
361 | 361 |
362 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
st | 362 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
st |
363 { | 363 { |
| 364 m_context->platformContext()->makeGrContextCurrent(); |
364 SkDevice* device = context()->platformContext()->canvas()->getDevice(); | 365 SkDevice* device = context()->platformContext()->canvas()->getDevice(); |
365 SkBitmap bitmap = device->accessBitmap(false); | 366 return ImageToDataURL(device->accessBitmap(false), mimeType, quality); |
366 | |
367 // if we can't see the pixels directly, call readPixels() to get a copy. | |
368 // this could happen if the device is backed by a GPU. | |
369 bitmap.lockPixels(); // balanced by our destructor, or explicitly if getPixe
ls() fails | |
370 if (!bitmap.getPixels()) { | |
371 bitmap.unlockPixels(); | |
372 SkIRect bounds = SkIRect::MakeWH(device->width(), device->height()); | |
373 if (!device->readPixels(bounds, &bitmap)) | |
374 return "data:,"; | |
375 } | |
376 | |
377 return ImageToDataURL(bitmap, mimeType, quality); | |
378 } | 367 } |
379 | 368 |
380 String ImageDataToDataURL(const ImageData& source, const String& mimeType, const
double* quality) | 369 String ImageDataToDataURL(const ImageData& source, const String& mimeType, const
double* quality) |
381 { | 370 { |
382 return ImageToDataURL(source, mimeType, quality); | 371 return ImageToDataURL(source, mimeType, quality); |
383 } | 372 } |
384 | 373 |
385 } // namespace WebCore | 374 } // namespace WebCore |
OLD | NEW |