| 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 // Because the unit tests for gfx::Image are spread across multiple |   5 // Because the unit tests for gfx::Image are spread across multiple | 
|   6 // implementation files, this header contains the reusable components. |   6 // implementation files, this header contains the reusable components. | 
|   7  |   7  | 
|   8 #ifndef UI_GFX_IMAGE_UNITTEST_H_ |  | 
|   9 #define UI_GFX_IMAGE_UNITTEST_H_ |  | 
|  10  |  | 
|  11 #include "base/memory/scoped_ptr.h" |   8 #include "base/memory/scoped_ptr.h" | 
 |   9 #include "ui/gfx/image_unittest_util.h" | 
|  12 #include "testing/gtest/include/gtest/gtest.h" |  10 #include "testing/gtest/include/gtest/gtest.h" | 
|  13 #include "third_party/skia/include/core/SkBitmap.h" |  11 #include "third_party/skia/include/core/SkBitmap.h" | 
|  14  |  12  | 
|  15 #if defined(OS_LINUX) |  13 #if defined(OS_LINUX) | 
|  16 #include "ui/gfx/gtk_util.h" |  14 #include "ui/gfx/gtk_util.h" | 
|  17 #elif defined(OS_MACOSX) |  15 #elif defined(OS_MACOSX) | 
|  18 #include "base/mac/mac_util.h" |  16 #include "base/mac/mac_util.h" | 
|  19 #include "skia/ext/skia_utils_mac.h" |  17 #include "skia/ext/skia_utils_mac.h" | 
|  20 #endif |  18 #endif | 
|  21  |  19  | 
|  22 namespace gfx { |  20 namespace gfx { | 
|  23 namespace test { |  21 namespace test { | 
|  24  |  22  | 
|  25 #if defined(OS_MACOSX) |  23 SkBitmap* CreateBitmap(int width, int height) { | 
|  26 typedef NSImage* PlatformImage; |  | 
|  27 #elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |  | 
|  28 typedef GdkPixbuf* PlatformImage; |  | 
|  29 #else |  | 
|  30 typedef const SkBitmap* PlatformImage; |  | 
|  31 #endif |  | 
|  32  |  | 
|  33 SkBitmap* CreateBitmap() { |  | 
|  34   SkBitmap* bitmap = new SkBitmap(); |  24   SkBitmap* bitmap = new SkBitmap(); | 
|  35   bitmap->setConfig(SkBitmap::kARGB_8888_Config, 25, 25); |  25   bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 
|  36   bitmap->allocPixels(); |  26   bitmap->allocPixels(); | 
|  37   bitmap->eraseRGB(255, 0, 0); |  27   bitmap->eraseRGB(255, 0, 0); | 
|  38   return bitmap; |  28   return bitmap; | 
|  39 } |  29 } | 
|  40  |  30  | 
|  41 PlatformImage CreatePlatformImage() { |  31 PlatformImage CreatePlatformImage() { | 
|  42   scoped_ptr<SkBitmap> bitmap(CreateBitmap()); |  32   scoped_ptr<SkBitmap> bitmap(CreateBitmap(25, 25)); | 
|  43 #if defined(OS_MACOSX) |  33 #if defined(OS_MACOSX) | 
|  44   NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get())); |  34   NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get())); | 
|  45   base::mac::NSObjectRetain(image); |  35   base::mac::NSObjectRetain(image); | 
|  46   return image; |  36   return image; | 
|  47 #elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |  37 #elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 
|  48   return gfx::GdkPixbufFromSkBitmap(bitmap.get()); |  38   return gfx::GdkPixbufFromSkBitmap(bitmap.get()); | 
|  49 #else |  39 #else | 
|  50   return bitmap.release(); |  40   return bitmap.release(); | 
|  51 #endif |  41 #endif | 
|  52 } |  42 } | 
|  53  |  43  | 
|  54 gfx::Image::RepresentationType GetPlatformRepresentationType() { |  44 gfx::Image::RepresentationType GetPlatformRepresentationType() { | 
|  55 #if defined(OS_MACOSX) |  45 #if defined(OS_MACOSX) | 
|  56   return gfx::Image::kNSImageRep; |  46   return gfx::Image::kNSImageRep; | 
|  57 #elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |  47 #elif defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 
|  58   return gfx::Image::kGdkPixbufRep; |  48   return gfx::Image::kGdkPixbufRep; | 
|  59 #else |  49 #else | 
|  60   return gfx::Image::kSkBitmapRep; |  50   return gfx::Image::kSkBitmapRep; | 
|  61 #endif |  51 #endif | 
|  62 } |  52 } | 
|  63  |  53  | 
|  64 }  // namespace test |  54 }  // namespace test | 
|  65 }  // namespace gfx |  55 }  // namespace gfx | 
|  66  |  | 
|  67 #endif  // UI_GFX_IMAGE_UNITTEST_H_ |  | 
| OLD | NEW |