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

Unified Diff: ui/gfx/image/image_family.cc

Issue 2707993005: Avoid returning a shallow copy of gfx::Image from gfx::ImageFamily::CreateExact (Closed)
Patch Set: +comment Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_family.cc
diff --git a/ui/gfx/image/image_family.cc b/ui/gfx/image/image_family.cc
index af0c2bf3675b367d9c78c7a428f38d0ddd4d2f77..b9d28bddd9df387e8b7fbc99544379de6b95e79a 100644
--- a/ui/gfx/image/image_family.cc
+++ b/ui/gfx/image/image_family.cc
@@ -117,8 +117,14 @@ gfx::Image ImageFamily::CreateExact(int width, int height) const {
if (!image)
return gfx::Image();
- if (image->Width() == width && image->Height() == height)
- return gfx::Image(*image);
+ if (image->Width() == width && image->Height() == height) {
+ // Make a copy at gfx::ImageSkia level, so that resulting image's ref count
+ // is not racy to |image|. Since this function can run on a different thread
+ // than the thread |image| created on, we should not touch the
+ // non-thread-safe ref count in gfx::Image here.
+ std::unique_ptr<gfx::ImageSkia> image_skia(image->CopyImageSkia());
+ return gfx::Image(*image_skia);
+ }
SkBitmap bitmap = image->AsBitmap();
SkBitmap resized_bitmap = skia::ImageOperations::Resize(
« 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