summaryrefslogtreecommitdiffstats
path: root/gfx/canvas_direct2d_unittest.cc
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 19:48:35 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 19:48:35 +0000
commit7ee62626cfe9952c2e2c7f34f91f128b1cea8835 (patch)
tree0d87619ba52572e89956a763edfae023730b7348 /gfx/canvas_direct2d_unittest.cc
parent1280270eea827aca9b676aced264a25a26efa36a (diff)
downloadchromium_src-7ee62626cfe9952c2e2c7f34f91f128b1cea8835.zip
chromium_src-7ee62626cfe9952c2e2c7f34f91f128b1cea8835.tar.gz
chromium_src-7ee62626cfe9952c2e2c7f34f91f128b1cea8835.tar.bz2
Start implementing Direct2D Canvas. Implements Save/Restore methods, FillRectInt and BeginPlatformPaint/EndPlatformPaint.http://crbug.com/48583TEST=see unittest
Review URL: http://codereview.chromium.org/2939001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51996 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/canvas_direct2d_unittest.cc')
-rw-r--r--gfx/canvas_direct2d_unittest.cc156
1 files changed, 156 insertions, 0 deletions
diff --git a/gfx/canvas_direct2d_unittest.cc b/gfx/canvas_direct2d_unittest.cc
new file mode 100644
index 0000000..0b5ce0f
--- /dev/null
+++ b/gfx/canvas_direct2d_unittest.cc
@@ -0,0 +1,156 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <windows.h>
+#include <uxtheme.h>
+#include <vsstyle.h>
+#include <vssym32.h>
+
+#include "base/command_line.h"
+#include "gfx/canvas_direct2d.h"
+#include "gfx/canvas_skia.h"
+#include "gfx/native_theme_win.h"
+#include "gfx/window_impl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class TestWindow : public gfx::WindowImpl {
+ public:
+ static const int kWindowSize = 500;
+ static const int kWindowPosition = 10;
+
+ static const wchar_t* kVisibleModeFlag;
+
+ TestWindow() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kVisibleModeFlag))
+ Sleep(1000);
+
+ // Create the window.
+ Init(NULL,
+ gfx::Rect(kWindowPosition, kWindowPosition, kWindowSize, kWindowSize));
+
+ // Initialize the RenderTarget for the window.
+ rt_ = MakeHWNDRenderTarget();
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kVisibleModeFlag))
+ ShowWindow(hwnd(), SW_SHOW);
+ }
+ virtual ~TestWindow() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kVisibleModeFlag))
+ Sleep(1000);
+ DestroyWindow(hwnd());
+ }
+
+ ID2D1RenderTarget* rt() const { return rt_.get(); }
+
+ BEGIN_MSG_MAP_EX(TestWindow)
+ END_MSG_MAP()
+
+ private:
+ ID2D1RenderTarget* MakeHWNDRenderTarget() {
+ D2D1_RENDER_TARGET_PROPERTIES rt_properties =
+ D2D1::RenderTargetProperties();
+ rt_properties.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
+
+ ID2D1HwndRenderTarget* rt = NULL;
+ gfx::CanvasDirect2D::GetD2D1Factory()->CreateHwndRenderTarget(
+ rt_properties,
+ D2D1::HwndRenderTargetProperties(hwnd(), D2D1::SizeU(500, 500)),
+ &rt);
+ return rt;
+ }
+
+ ScopedComPtr<ID2D1RenderTarget> rt_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWindow);
+};
+
+// static
+const wchar_t* TestWindow::kVisibleModeFlag = L"d2d-canvas-visible";
+
+} // namespace
+
+TEST(CanvasDirect2D, CreateCanvas) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+}
+
+TEST(CanvasDirect2D, SaveRestoreNesting) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ // Simple.
+ canvas.Save();
+ canvas.Restore();
+
+ // Nested.
+ canvas.Save();
+ canvas.Save();
+ canvas.Restore();
+ canvas.Restore();
+
+ // Simple alpha.
+ canvas.SaveLayerAlpha(127);
+ canvas.Restore();
+
+ // Alpha with sub-rect.
+ canvas.SaveLayerAlpha(127, gfx::Rect(20, 20, 100, 100));
+ canvas.Restore();
+
+ // Nested alpha.
+ canvas.Save();
+ canvas.SaveLayerAlpha(127);
+ canvas.Save();
+ canvas.Restore();
+ canvas.Restore();
+ canvas.Restore();
+}
+
+TEST(CanvasDirect2D, SaveLayerAlpha) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ canvas.Save();
+ canvas.FillRectInt(SK_ColorBLUE, 20, 20, 100, 100);
+ canvas.SaveLayerAlpha(127);
+ canvas.FillRectInt(SK_ColorRED, 60, 60, 100, 100);
+ canvas.Restore();
+ canvas.Restore();
+}
+
+TEST(CanvasDirect2D, SaveLayerAlphaWithBounds) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ canvas.Save();
+ canvas.FillRectInt(SK_ColorBLUE, 20, 20, 100, 100);
+ canvas.SaveLayerAlpha(127, gfx::Rect(60, 60, 50, 50));
+ canvas.FillRectInt(SK_ColorRED, 60, 60, 100, 100);
+ canvas.Restore();
+ canvas.Restore();
+}
+
+TEST(CanvasDirect2D, FillRect) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ canvas.FillRectInt(SK_ColorRED, 20, 20, 100, 100);
+}
+
+TEST(CanvasDirect2D, PlatformPainting) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ gfx::NativeDrawingContext dc = canvas.BeginPlatformPaint();
+
+ // Use the system theme engine to draw a native button. This only works on a
+ // GDI device context.
+ RECT r = { 20, 20, 220, 80 };
+ gfx::NativeTheme::instance()->PaintButton(
+ dc, BP_PUSHBUTTON, PBS_NORMAL, DFCS_BUTTONPUSH, &r);
+
+ canvas.EndPlatformPaint();
+}
+