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-29 18:17:04 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-29 18:17:04 +0000
commit2caf4d005cb3b86b61ae559f08f2493e19129e3f (patch)
tree95e9eb1d2ec77fc179f5fdc26573db1449a5afb4 /gfx/canvas_direct2d_unittest.cc
parent797794bd42c10ff1dfecc25f91ec32a17d991b15 (diff)
downloadchromium_src-2caf4d005cb3b86b61ae559f08f2493e19129e3f.zip
chromium_src-2caf4d005cb3b86b61ae559f08f2493e19129e3f.tar.gz
chromium_src-2caf4d005cb3b86b61ae559f08f2493e19129e3f.tar.bz2
Add support for Radial Gradient Brush and Bitmap Brush to gfx::Canvas.
BUG=none TEST=see unittest Review URL: http://codereview.chromium.org/3058012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/canvas_direct2d_unittest.cc')
-rw-r--r--gfx/canvas_direct2d_unittest.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/gfx/canvas_direct2d_unittest.cc b/gfx/canvas_direct2d_unittest.cc
index d8c02c1..ff63302 100644
--- a/gfx/canvas_direct2d_unittest.cc
+++ b/gfx/canvas_direct2d_unittest.cc
@@ -8,13 +8,18 @@
#include <vssym32.h>
#include "base/command_line.h"
+#include "base/ref_counted_memory.h"
+#include "base/resource_util.h"
#include "base/scoped_ptr.h"
#include "gfx/canvas_direct2d.h"
#include "gfx/canvas_skia.h"
+#include "gfx/codec/png_codec.h"
#include "gfx/native_theme_win.h"
#include "gfx/window_impl.h"
+#include "grit/gfx_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
+
namespace {
class TestWindow : public gfx::WindowImpl {
@@ -71,6 +76,27 @@ class TestWindow : public gfx::WindowImpl {
// static
const wchar_t* TestWindow::kVisibleModeFlag = L"d2d-canvas-visible";
+// Loads a png data blob from the data resources associated with this
+// executable, decodes it and returns a SkBitmap.
+SkBitmap LoadBitmapFromResources(int resource_id) {
+ SkBitmap bitmap;
+
+ HINSTANCE resource_instance = _AtlBaseModule.GetResourceInstance();
+ void* data_ptr;
+ size_t data_size;
+ if (base::GetDataResourceFromModule(resource_instance, resource_id, &data_ptr,
+ &data_size)) {
+ scoped_refptr<RefCountedMemory> memory(new RefCountedStaticMemory(
+ reinterpret_cast<const unsigned char*>(data_ptr), data_size));
+ if (!memory)
+ return bitmap;
+
+ if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap))
+ NOTREACHED() << "Unable to decode theme image resource " << resource_id;
+ }
+ return bitmap;
+}
+
} // namespace
TEST(CanvasDirect2D, CreateCanvas) {
@@ -221,3 +247,37 @@ TEST(CanvasDirect2D, CreateLinearGradientBrush) {
canvas.FillRectInt(brush.get(), 0, 0, 500, 500);
canvas.Restore();
}
+
+TEST(CanvasDirect2D, CreateRadialGradientBrush) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ canvas.Save();
+ SkColor colors[] = { SK_ColorBLUE, SK_ColorGREEN };
+ float positions[] = { 0.0f, 1.0f };
+ scoped_ptr<gfx::Brush> brush(canvas.CreateRadialGradientBrush(
+ gfx::Point(200, 200),
+ 100.0f,
+ colors,
+ positions,
+ 2,
+ gfx::Canvas::TileMode_Clamp));
+ canvas.FillRectInt(brush.get(), 0, 0, 500, 500);
+ canvas.Restore();
+}
+
+TEST(CanvasDirect2D, CreateBitmapBrush) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ SkBitmap bitmap = LoadBitmapFromResources(IDR_BITMAP_BRUSH_IMAGE);
+
+ canvas.Save();
+ scoped_ptr<gfx::Brush> brush(canvas.CreateBitmapBrush(
+ bitmap,
+ gfx::Canvas::TileMode_Mirror,
+ gfx::Canvas::TileMode_Mirror));
+ canvas.FillRectInt(brush.get(), 0, 0, 500, 500);
+ canvas.Restore();
+}
+