String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const { SkDevice* device = context()->platformContext()->canvas()->getDevice(); SkBitmap bitmap = device->accessBitmap(false); // if we can't see the pixels directly, call readPixels() to get a copy. // this could happen if the device is backed by a GPU. bitmap.lockPixels(); // balanced by our destructor, or explicitly if getPixels() fails if (!bitmap.getPixels()) { bitmap.unlockPixels(); SkIRect bounds = SkIRect::MakeWH(device->width(), device->height()); if (!device->readPixels(bounds, &bitmap)) return "data:,"; } return ImageToDataURL(bitmap, mimeType, quality); }
String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const { ASSERT(context() && context()->platformContext()); // Request for canvas bitmap; conversion required. if (context()->platformContext()->isRecording()) context()->platformContext()->convertToNonRecording(); // CAPPFIX_WEB_WEBGL SkCanvas* canvas = imageBufferCanvas(this); // CAPPFIX_WEB_WEBGL_END SkDevice* device = canvas->getDevice(); SkBitmap bitmap = device->accessBitmap(false); // if we can't see the pixels directly, call readPixels() to get a copy. // this could happen if the device is backed by a GPU. bitmap.lockPixels(); // balanced by our destructor, or explicitly if getPixels() fails if (!bitmap.getPixels()) { bitmap.unlockPixels(); SkIRect bounds = SkIRect::MakeWH(device->width(), device->height()); if (!canvas->readPixels(bounds, &bitmap)) return "data:,"; } return ImageToDataURL(bitmap, mimeType, quality); }
String ImageDataToDataURL(const ImageData& source, const String& mimeType, const double* quality) { return ImageToDataURL(source, mimeType, quality); }
String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const { m_context->platformContext()->makeGrContextCurrent(); SkDevice* device = context()->platformContext()->canvas()->getDevice(); return ImageToDataURL(device->accessBitmap(false), mimeType, quality); }