| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <uxtheme.h> | 6 #include <uxtheme.h> |
| 7 #include <vsstyle.h> | 7 #include <vsstyle.h> |
| 8 #include <vssym32.h> | 8 #include <vssym32.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/ref_counted_memory.h" |
| 12 #include "base/resource_util.h" |
| 11 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 12 #include "gfx/canvas_direct2d.h" | 14 #include "gfx/canvas_direct2d.h" |
| 13 #include "gfx/canvas_skia.h" | 15 #include "gfx/canvas_skia.h" |
| 16 #include "gfx/codec/png_codec.h" |
| 14 #include "gfx/native_theme_win.h" | 17 #include "gfx/native_theme_win.h" |
| 15 #include "gfx/window_impl.h" | 18 #include "gfx/window_impl.h" |
| 19 #include "grit/gfx_resources.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 21 |
| 22 |
| 18 namespace { | 23 namespace { |
| 19 | 24 |
| 20 class TestWindow : public gfx::WindowImpl { | 25 class TestWindow : public gfx::WindowImpl { |
| 21 public: | 26 public: |
| 22 static const int kWindowSize = 500; | 27 static const int kWindowSize = 500; |
| 23 static const int kWindowPosition = 10; | 28 static const int kWindowPosition = 10; |
| 24 | 29 |
| 25 static const wchar_t* kVisibleModeFlag; | 30 static const wchar_t* kVisibleModeFlag; |
| 26 | 31 |
| 27 TestWindow() { | 32 TestWindow() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 69 } |
| 65 | 70 |
| 66 ScopedComPtr<ID2D1RenderTarget> rt_; | 71 ScopedComPtr<ID2D1RenderTarget> rt_; |
| 67 | 72 |
| 68 DISALLOW_COPY_AND_ASSIGN(TestWindow); | 73 DISALLOW_COPY_AND_ASSIGN(TestWindow); |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 // static | 76 // static |
| 72 const wchar_t* TestWindow::kVisibleModeFlag = L"d2d-canvas-visible"; | 77 const wchar_t* TestWindow::kVisibleModeFlag = L"d2d-canvas-visible"; |
| 73 | 78 |
| 79 // Loads a png data blob from the data resources associated with this |
| 80 // executable, decodes it and returns a SkBitmap. |
| 81 SkBitmap LoadBitmapFromResources(int resource_id) { |
| 82 SkBitmap bitmap; |
| 83 |
| 84 HINSTANCE resource_instance = _AtlBaseModule.GetResourceInstance(); |
| 85 void* data_ptr; |
| 86 size_t data_size; |
| 87 if (base::GetDataResourceFromModule(resource_instance, resource_id, &data_ptr, |
| 88 &data_size)) { |
| 89 scoped_refptr<RefCountedMemory> memory(new RefCountedStaticMemory( |
| 90 reinterpret_cast<const unsigned char*>(data_ptr), data_size)); |
| 91 if (!memory) |
| 92 return bitmap; |
| 93 |
| 94 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) |
| 95 NOTREACHED() << "Unable to decode theme image resource " << resource_id; |
| 96 } |
| 97 return bitmap; |
| 98 } |
| 99 |
| 74 } // namespace | 100 } // namespace |
| 75 | 101 |
| 76 TEST(CanvasDirect2D, CreateCanvas) { | 102 TEST(CanvasDirect2D, CreateCanvas) { |
| 77 TestWindow window; | 103 TestWindow window; |
| 78 gfx::CanvasDirect2D canvas(window.rt()); | 104 gfx::CanvasDirect2D canvas(window.rt()); |
| 79 } | 105 } |
| 80 | 106 |
| 81 TEST(CanvasDirect2D, SaveRestoreNesting) { | 107 TEST(CanvasDirect2D, SaveRestoreNesting) { |
| 82 TestWindow window; | 108 TestWindow window; |
| 83 gfx::CanvasDirect2D canvas(window.rt()); | 109 gfx::CanvasDirect2D canvas(window.rt()); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 scoped_ptr<gfx::Brush> brush(canvas.CreateLinearGradientBrush( | 240 scoped_ptr<gfx::Brush> brush(canvas.CreateLinearGradientBrush( |
| 215 gfx::Point(0, 0), | 241 gfx::Point(0, 0), |
| 216 gfx::Point(100, 0), | 242 gfx::Point(100, 0), |
| 217 colors, | 243 colors, |
| 218 positions, | 244 positions, |
| 219 2, | 245 2, |
| 220 gfx::Canvas::TileMode_Clamp)); | 246 gfx::Canvas::TileMode_Clamp)); |
| 221 canvas.FillRectInt(brush.get(), 0, 0, 500, 500); | 247 canvas.FillRectInt(brush.get(), 0, 0, 500, 500); |
| 222 canvas.Restore(); | 248 canvas.Restore(); |
| 223 } | 249 } |
| 250 |
| 251 TEST(CanvasDirect2D, CreateRadialGradientBrush) { |
| 252 TestWindow window; |
| 253 gfx::CanvasDirect2D canvas(window.rt()); |
| 254 |
| 255 canvas.Save(); |
| 256 SkColor colors[] = { SK_ColorBLUE, SK_ColorGREEN }; |
| 257 float positions[] = { 0.0f, 1.0f }; |
| 258 scoped_ptr<gfx::Brush> brush(canvas.CreateRadialGradientBrush( |
| 259 gfx::Point(200, 200), |
| 260 100.0f, |
| 261 colors, |
| 262 positions, |
| 263 2, |
| 264 gfx::Canvas::TileMode_Clamp)); |
| 265 canvas.FillRectInt(brush.get(), 0, 0, 500, 500); |
| 266 canvas.Restore(); |
| 267 } |
| 268 |
| 269 TEST(CanvasDirect2D, CreateBitmapBrush) { |
| 270 TestWindow window; |
| 271 gfx::CanvasDirect2D canvas(window.rt()); |
| 272 |
| 273 SkBitmap bitmap = LoadBitmapFromResources(IDR_BITMAP_BRUSH_IMAGE); |
| 274 |
| 275 canvas.Save(); |
| 276 scoped_ptr<gfx::Brush> brush(canvas.CreateBitmapBrush( |
| 277 bitmap, |
| 278 gfx::Canvas::TileMode_Mirror, |
| 279 gfx::Canvas::TileMode_Mirror)); |
| 280 canvas.FillRectInt(brush.get(), 0, 0, 500, 500); |
| 281 canvas.Restore(); |
| 282 } |
| 283 |
| OLD | NEW |