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