| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/image.h" | 5 #include "ui/gfx/image.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 #if defined(OS_LINUX) | 9 #if defined(OS_LINUX) |
| 10 #include <gdk-pixbuf/gdk-pixbuf.h> | 10 #include <gdk-pixbuf/gdk-pixbuf.h> |
| 11 #include <glib-object.h> | 11 #include <glib-object.h> |
| 12 #include "ui/gfx/canvas_skia.h" | 12 #include "ui/gfx/canvas_skia.h" |
| 13 #include "ui/gfx/gtk_util.h" | 13 #include "ui/gfx/gtk_util.h" |
| 14 #elif defined(OS_MACOSX) | 14 #elif defined(OS_MACOSX) |
| 15 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
| 16 #include "skia/ext/skia_utils_mac.h" | 16 #include "skia/ext/skia_utils_mac.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace ui { | |
| 20 namespace gfx { | 19 namespace gfx { |
| 21 | 20 |
| 22 namespace internal { | 21 namespace internal { |
| 23 | 22 |
| 24 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
| 25 // This is a wrapper around gfx::NSImageToSkBitmap() because this cross-platform | 24 // This is a wrapper around gfx::NSImageToSkBitmap() because this cross-platform |
| 26 // file cannot include the [square brackets] of ObjC. | 25 // file cannot include the [square brackets] of ObjC. |
| 27 const SkBitmap* NSImageToSkBitmap(NSImage* image); | 26 const SkBitmap* NSImageToSkBitmap(NSImage* image); |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
| 31 const SkBitmap* GdkPixbufToSkBitmap(GdkPixbuf* pixbuf) { | 30 const SkBitmap* GdkPixbufToSkBitmap(GdkPixbuf* pixbuf) { |
| 32 ::gfx::CanvasSkia canvas(gdk_pixbuf_get_width(pixbuf), | 31 gfx::CanvasSkia canvas(gdk_pixbuf_get_width(pixbuf), |
| 33 gdk_pixbuf_get_height(pixbuf), | 32 gdk_pixbuf_get_height(pixbuf), |
| 34 false); | 33 false); |
| 35 canvas.DrawGdkPixbuf(pixbuf, 0, 0); | 34 canvas.DrawGdkPixbuf(pixbuf, 0, 0); |
| 36 return new SkBitmap(canvas.ExtractBitmap()); | 35 return new SkBitmap(canvas.ExtractBitmap()); |
| 37 } | 36 } |
| 38 #endif | 37 #endif |
| 39 | 38 |
| 40 class SkBitmapRep; | 39 class SkBitmapRep; |
| 41 class GdkPixbufRep; | 40 class GdkPixbufRep; |
| 42 class NSImageRep; | 41 class NSImageRep; |
| 43 | 42 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 244 } |
| 246 NOTREACHED(); | 245 NOTREACHED(); |
| 247 } | 246 } |
| 248 | 247 |
| 249 // Handle Skia-to-native conversions. | 248 // Handle Skia-to-native conversions. |
| 250 if (default_rep->type() == Image::kSkBitmapRep) { | 249 if (default_rep->type() == Image::kSkBitmapRep) { |
| 251 internal::SkBitmapRep* skia_rep = default_rep->AsSkBitmapRep(); | 250 internal::SkBitmapRep* skia_rep = default_rep->AsSkBitmapRep(); |
| 252 internal::ImageRep* native_rep = NULL; | 251 internal::ImageRep* native_rep = NULL; |
| 253 #if defined(OS_LINUX) | 252 #if defined(OS_LINUX) |
| 254 if (rep_type == Image::kGdkPixbufRep) { | 253 if (rep_type == Image::kGdkPixbufRep) { |
| 255 GdkPixbuf* pixbuf = ::gfx::GdkPixbufFromSkBitmap(skia_rep->bitmap()); | 254 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_rep->bitmap()); |
| 256 native_rep = new internal::GdkPixbufRep(pixbuf); | 255 native_rep = new internal::GdkPixbufRep(pixbuf); |
| 257 } | 256 } |
| 258 #elif defined(OS_MACOSX) | 257 #elif defined(OS_MACOSX) |
| 259 if (rep_type == Image::kNSImageRep) { | 258 if (rep_type == Image::kNSImageRep) { |
| 260 NSImage* image = ::gfx::SkBitmapToNSImage(*(skia_rep->bitmap())); | 259 NSImage* image = gfx::SkBitmapToNSImage(*(skia_rep->bitmap())); |
| 261 base::mac::NSObjectRetain(image); | 260 base::mac::NSObjectRetain(image); |
| 262 native_rep = new internal::NSImageRep(image); | 261 native_rep = new internal::NSImageRep(image); |
| 263 } | 262 } |
| 264 #endif | 263 #endif |
| 265 if (native_rep) { | 264 if (native_rep) { |
| 266 AddRepresentation(native_rep); | 265 AddRepresentation(native_rep); |
| 267 return native_rep; | 266 return native_rep; |
| 268 } | 267 } |
| 269 NOTREACHED(); | 268 NOTREACHED(); |
| 270 } | 269 } |
| 271 | 270 |
| 272 // Something went seriously wrong... | 271 // Something went seriously wrong... |
| 273 return NULL; | 272 return NULL; |
| 274 } | 273 } |
| 275 | 274 |
| 276 void Image::AddRepresentation(internal::ImageRep* rep) { | 275 void Image::AddRepresentation(internal::ImageRep* rep) { |
| 277 representations_.insert(std::make_pair(rep->type(), rep)); | 276 representations_.insert(std::make_pair(rep->type(), rep)); |
| 278 } | 277 } |
| 279 | 278 |
| 280 } // namespace gfx | 279 } // namespace gfx |
| 281 } // namespace ui | |
| OLD | NEW |