Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Unified Diff: gfx/canvas_direct2d_unittest.cc

Issue 3058012: Add support for Radial Gradient Brush and Bitmap Brush to gfx::Canvas.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gfx/canvas_direct2d.cc ('k') | gfx/canvas_skia.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gfx/canvas_direct2d_unittest.cc
===================================================================
--- gfx/canvas_direct2d_unittest.cc (revision 54142)
+++ gfx/canvas_direct2d_unittest.cc (working copy)
@@ -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 @@
// 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 @@
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();
+}
+
« no previous file with comments | « gfx/canvas_direct2d.cc ('k') | gfx/canvas_skia.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698