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

Side by Side Diff: Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

Issue 7582010: Merge 92388 - Set graphics context current before canvas.toDataURL(). (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698