diff options
-rw-r--r-- | ui/gfx/canvas_direct2d.cc | 369 | ||||
-rw-r--r-- | ui/gfx/canvas_direct2d.h | 121 | ||||
-rw-r--r-- | ui/gfx/canvas_direct2d_unittest.cc | 332 | ||||
-rw-r--r-- | ui/ui.gyp | 2 | ||||
-rw-r--r-- | ui/ui_unittests.gypi | 1 |
5 files changed, 0 insertions, 825 deletions
diff --git a/ui/gfx/canvas_direct2d.cc b/ui/gfx/canvas_direct2d.cc deleted file mode 100644 index 5a61ace..0000000 --- a/ui/gfx/canvas_direct2d.cc +++ /dev/null @@ -1,369 +0,0 @@ -// Copyright (c) 2011 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 "ui/gfx/canvas_direct2d.h" - -#include "base/memory/scoped_ptr.h" -#include "ui/gfx/brush.h" -#include "ui/gfx/rect.h" - -namespace { - -// Converts a SkColor to a ColorF. -D2D1_COLOR_F SkColorToColorF(SkColor color) { - return D2D1::ColorF(static_cast<float>(SkColorGetR(color)) / 0xFF, - static_cast<float>(SkColorGetG(color)) / 0xFF, - static_cast<float>(SkColorGetB(color)) / 0xFF, - static_cast<float>(SkColorGetA(color)) / 0xFF); -} - -D2D1_RECT_F RectToRectF(int x, int y, int w, int h) { - return D2D1::RectF(static_cast<float>(x), static_cast<float>(y), - static_cast<float>(x + w), static_cast<float>(y + h)); -} - -D2D1_RECT_F RectToRectF(const gfx::Rect& rect) { - return RectToRectF(rect.x(), rect.y(), rect.width(), rect.height()); -} - -D2D1_POINT_2F PointToPoint2F(int x, int y) { - return D2D1::Point2F(static_cast<float>(x), static_cast<float>(y)); -} - -D2D1_BITMAP_INTERPOLATION_MODE FilterToInterpolationMode(bool filter) { - return filter ? D2D1_BITMAP_INTERPOLATION_MODE_LINEAR - : D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR; -} - -// Creates a Direct2D bitmap object from the contents of a SkBitmap. The caller -// is responsible for releasing this object. -ID2D1Bitmap* CreateD2D1BitmapFromSkBitmap(ID2D1RenderTarget* render_target, - const SkBitmap& bitmap) { - ID2D1Bitmap* d2d1_bitmap = NULL; - HRESULT hr = render_target->CreateBitmap( - D2D1::SizeU(bitmap.width(), bitmap.height()), - NULL, - NULL, - D2D1::BitmapProperties( - D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, - D2D1_ALPHA_MODE_IGNORE)), - &d2d1_bitmap); - if (FAILED(hr)) - return NULL; - bitmap.lockPixels(); - d2d1_bitmap->CopyFromMemory(NULL, bitmap.getPixels(), bitmap.rowBytes()); - bitmap.unlockPixels(); - return d2d1_bitmap; -} - -// Creates a Direct2D bitmap brush from the contents of a SkBitmap. The caller -// is responsible for releasing this object. -ID2D1Brush* CreateD2D1BrushFromSkBitmap(ID2D1RenderTarget* render_target, - const SkBitmap& bitmap, - D2D1_EXTEND_MODE extend_mode_x, - D2D1_EXTEND_MODE extend_mode_y) { - base::win::ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( - CreateD2D1BitmapFromSkBitmap(render_target, bitmap)); - - ID2D1BitmapBrush* brush = NULL; - render_target->CreateBitmapBrush( - d2d1_bitmap, - D2D1::BitmapBrushProperties(extend_mode_x, extend_mode_y), - D2D1::BrushProperties(), - &brush); - return brush; -} - -// A platform wrapper for a Direct2D brush that makes sure the underlying -// ID2D1Brush COM object is released when this object is destroyed. -class Direct2DBrush : public gfx::Brush { - public: - explicit Direct2DBrush(ID2D1Brush* brush) : brush_(brush) { - } - - ID2D1Brush* brush() const { return brush_.get(); } - - private: - base::win::ScopedComPtr<ID2D1Brush> brush_; - - DISALLOW_COPY_AND_ASSIGN(Direct2DBrush); -}; - - -} // namespace - -namespace gfx { - -// static -ID2D1Factory* CanvasDirect2D::d2d1_factory_ = NULL; - -//////////////////////////////////////////////////////////////////////////////// -// CanvasDirect2D, public: - -CanvasDirect2D::CanvasDirect2D(ID2D1RenderTarget* rt) : rt_(rt) { - // A RenderState entry is pushed onto the stack to track the clip count prior - // to any calls to Save*(). - state_.push(RenderState()); - rt_->BeginDraw(); -} - -CanvasDirect2D::~CanvasDirect2D() { - // Unwind any clips that were pushed outside of any Save*()/Restore() pairs. - int clip_count = state_.top().clip_count; - for (int i = 0; i < clip_count; ++i) - rt_->PopAxisAlignedClip(); - rt_->EndDraw(); -} - -// static -ID2D1Factory* CanvasDirect2D::GetD2D1Factory() { - if (!d2d1_factory_) - D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2d1_factory_); - return d2d1_factory_; -} - -//////////////////////////////////////////////////////////////////////////////// -// CanvasDirect2D, Canvas implementation: - -void CanvasDirect2D::Save() { - SaveInternal(NULL); -} - -void CanvasDirect2D::SaveLayerAlpha(uint8 alpha) { - SaveLayerAlpha(alpha, gfx::Rect()); -} - -void CanvasDirect2D::SaveLayerAlpha(uint8 alpha, - const gfx::Rect& layer_bounds) { - D2D1_RECT_F bounds = D2D1::InfiniteRect(); - if (!layer_bounds.IsEmpty()) - bounds = RectToRectF(layer_bounds); - ID2D1Layer* layer = NULL; - HRESULT hr = rt_->CreateLayer(NULL, &layer); - if (SUCCEEDED(hr)) { - rt_->PushLayer(D2D1::LayerParameters(bounds, - NULL, - D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, - D2D1::IdentityMatrix(), - static_cast<float>(alpha) / 0xFF, - NULL, - D2D1_LAYER_OPTIONS_NONE), - layer); - } - SaveInternal(layer); -} - -void CanvasDirect2D::Restore() { - ID2D1Layer* layer = state_.top().layer; - if (layer) { - rt_->PopLayer(); - layer->Release(); - } - - int clip_count = state_.top().clip_count; - for (int i = 0; i < clip_count; ++i) - rt_->PopAxisAlignedClip(); - - state_.pop(); - // The state_ stack should never be empty - we should always have at least one - // entry to hold a clip count when there is no active save/restore entry. - CHECK(!state_.empty()) << "Called Restore() once too often!"; - - rt_->RestoreDrawingState(drawing_state_block_); -} - -bool CanvasDirect2D::ClipRect(const gfx::Rect& rect) { - rt_->PushAxisAlignedClip(RectToRectF(rect), - D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); - // Increment the clip count so the call to PushAxisAlignedClip() can be - // balanced with a call to PopAxisAlignedClip in the next Restore(). - ++state_.top().clip_count; - return !rect.IsEmpty(); -} - -void CanvasDirect2D::Translate(const gfx::Point& point) { - D2D1_MATRIX_3X2_F raw; - rt_->GetTransform(&raw); - D2D1::Matrix3x2F transform(raw._11, raw._12, raw._21, raw._22, raw._31, - raw._32); - transform = D2D1::Matrix3x2F::Translation( - static_cast<float>(point.x()), static_cast<float>(point.y())) * transform; - rt_->SetTransform(transform); -} - -void CanvasDirect2D::Scale(int x_scale, int y_scale) { - D2D1_MATRIX_3X2_F raw; - rt_->GetTransform(&raw); - D2D1::Matrix3x2F transform(raw._11, raw._12, raw._21, raw._22, raw._31, - raw._32); - transform = D2D1::Matrix3x2F::Scale(static_cast<float>(x_scale), - static_cast<float>(y_scale)) * transform; - rt_->SetTransform(transform); -} - -void CanvasDirect2D::FillRect(const SkColor& color, const gfx::Rect& rect) { - base::win::ScopedComPtr<ID2D1SolidColorBrush> solid_brush; - rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); - rt_->FillRectangle(RectToRectF(rect), solid_brush); -} - -void CanvasDirect2D::FillRect(const SkColor& color, - const gfx::Rect& rect, - SkXfermode::Mode mode) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::FillRect(const gfx::Brush* brush, const gfx::Rect& rect) { - const Direct2DBrush* d2d_brush = static_cast<const Direct2DBrush*>(brush); - rt_->FillRectangle(RectToRectF(rect), d2d_brush->brush()); -} - -void CanvasDirect2D::DrawRectInt(const SkColor& color, - int x, int y, int w, int h) { - base::win::ScopedComPtr<ID2D1SolidColorBrush> solid_brush; - rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); - rt_->DrawRectangle(RectToRectF(x, y, w, h), solid_brush); -} - -void CanvasDirect2D::DrawRectInt(const SkColor& color, - int x, int y, int w, int h, - SkXfermode::Mode mode) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawRectInt(int x, int y, int w, int h, - const SkPaint& paint) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawLineInt(const SkColor& color, - int x1, int y1, - int x2, int y2) { - base::win::ScopedComPtr<ID2D1SolidColorBrush> solid_brush; - rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); - rt_->DrawLine(PointToPoint2F(x1, y1), PointToPoint2F(x2, y2), solid_brush); -} - -void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { - base::win::ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( - CreateD2D1BitmapFromSkBitmap(rt_, bitmap)); - rt_->DrawBitmap(d2d1_bitmap, - RectToRectF(x, y, bitmap.width(), bitmap.height()), - 1.0f, - D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, - RectToRectF(0, 0, bitmap.width(), bitmap.height())); -} - -void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, - int dest_w, int dest_h, - bool filter) { - base::win::ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( - CreateD2D1BitmapFromSkBitmap(rt_, bitmap)); - rt_->DrawBitmap(d2d1_bitmap, - RectToRectF(dest_x, dest_y, dest_w, dest_h), - 1.0f, - FilterToInterpolationMode(filter), - RectToRectF(src_x, src_y, src_w, src_h)); -} - -void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, - int dest_w, int dest_h, - bool filter, - const SkPaint& paint) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::DrawFocusRect(const gfx::Rect& rect) { - NOTIMPLEMENTED(); -} - -void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, - int x, int y, int w, int h) { - base::win::ScopedComPtr<ID2D1Brush> brush( - CreateD2D1BrushFromSkBitmap(rt_, bitmap, D2D1_EXTEND_MODE_WRAP, - D2D1_EXTEND_MODE_WRAP)); - rt_->FillRectangle(RectToRectF(x, y, w, h), brush); -} - -void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h) { - NOTIMPLEMENTED(); -} - -gfx::NativeDrawingContext CanvasDirect2D::BeginPlatformPaint() { - DCHECK(!interop_rt_.get()); - interop_rt_.QueryFrom(rt_); - HDC dc = NULL; - if (interop_rt_.get()) - interop_rt_->GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &dc); - return dc; -} - -void CanvasDirect2D::EndPlatformPaint() { - DCHECK(interop_rt_.get()); - interop_rt_->ReleaseDC(NULL); - interop_rt_.release(); -} - -void CanvasDirect2D::Transform(const ui::Transform& transform) { - NOTIMPLEMENTED(); -} - -ui::TextureID CanvasDirect2D::GetTextureID() { - NOTIMPLEMENTED(); - return 0; -} - -CanvasSkia* CanvasDirect2D::AsCanvasSkia() { - return NULL; -} - -const CanvasSkia* CanvasDirect2D::AsCanvasSkia() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// CanvasDirect2D, private: - -void CanvasDirect2D::SaveInternal(ID2D1Layer* layer) { - if (!drawing_state_block_) - GetD2D1Factory()->CreateDrawingStateBlock(drawing_state_block_.Receive()); - rt_->SaveDrawingState(drawing_state_block_.get()); - state_.push(RenderState(layer)); -} - -} // namespace gfx diff --git a/ui/gfx/canvas_direct2d.h b/ui/gfx/canvas_direct2d.h deleted file mode 100644 index c5e6ad8..0000000 --- a/ui/gfx/canvas_direct2d.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_GFX_CANVAS_DIRECT2D_H_ -#define UI_GFX_CANVAS_DIRECT2D_H_ -#pragma once - -#include <d2d1.h> - -#include <stack> - -#include "base/compiler_specific.h" -#include "base/win/scoped_comptr.h" -#include "ui/gfx/canvas.h" - -namespace gfx { - -class UI_EXPORT CanvasDirect2D : public Canvas { - public: - // Creates an empty Canvas. - explicit CanvasDirect2D(ID2D1RenderTarget* rt); - virtual ~CanvasDirect2D(); - - // Retrieves the application's D2D1 Factory. - static ID2D1Factory* GetD2D1Factory(); - - // Overridden from Canvas: - virtual void Save() OVERRIDE; - virtual void SaveLayerAlpha(uint8 alpha) OVERRIDE; - virtual void SaveLayerAlpha(uint8 alpha, - const gfx::Rect& layer_bounds) OVERRIDE; - virtual void Restore() OVERRIDE; - virtual bool ClipRect(const gfx::Rect& rect) OVERRIDE; - virtual void Translate(const gfx::Point& point) OVERRIDE; - virtual void Scale(int x_scale, int y_scale) OVERRIDE; - virtual void FillRect(const SkColor& color, const gfx::Rect& rect) OVERRIDE; - virtual void FillRect(const SkColor& color, - const gfx::Rect& rect, - SkXfermode::Mode mode) OVERRIDE; - virtual void FillRect(const gfx::Brush* brush, - const gfx::Rect& rect) OVERRIDE; - virtual void DrawRectInt(const SkColor& color, - int x, int y, int w, int h) OVERRIDE; - virtual void DrawRectInt(const SkColor& color, - int x, int y, int w, int h, - SkXfermode::Mode mode) OVERRIDE; - virtual void DrawRectInt(int x, int y, int w, int h, - const SkPaint& paint) OVERRIDE; - virtual void DrawLineInt(const SkColor& color, - int x1, int y1, - int x2, int y2) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int src_x, int src_y, int src_w, int src_h, - int dest_x, int dest_y, int dest_w, int dest_h, - bool filter, - const SkPaint& paint) OVERRIDE; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) OVERRIDE; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) OVERRIDE; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) OVERRIDE; - virtual void DrawFocusRect(const gfx::Rect& rect) OVERRIDE; - virtual void TileImageInt(const SkBitmap& bitmap, - int x, int y, int w, int h) OVERRIDE; - virtual void TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h) OVERRIDE; - virtual gfx::NativeDrawingContext BeginPlatformPaint() OVERRIDE; - virtual void EndPlatformPaint() OVERRIDE; - virtual void Transform(const ui::Transform& transform) OVERRIDE; - virtual ui::TextureID GetTextureID() OVERRIDE; - virtual CanvasSkia* AsCanvasSkia() OVERRIDE; - virtual const CanvasSkia* AsCanvasSkia() const OVERRIDE; - - private: - void SaveInternal(ID2D1Layer* layer); - - ID2D1RenderTarget* rt_; - base::win::ScopedComPtr<ID2D1GdiInteropRenderTarget> interop_rt_; - base::win::ScopedComPtr<ID2D1DrawingStateBlock> drawing_state_block_; - static ID2D1Factory* d2d1_factory_; - - // Every time Save* is called, a RenderState object is pushed onto the - // RenderState stack. - struct RenderState { - explicit RenderState(ID2D1Layer* layer) : layer(layer), clip_count(0) {} - RenderState() : layer(NULL), clip_count(0) {} - - // A D2D layer associated with this state, or NULL if there is no layer. - // The layer is created and owned by the Canvas. - ID2D1Layer* layer; - // The number of clip operations performed. This is used to balance calls to - // PushAxisAlignedClip with calls to PopAxisAlignedClip when Restore() is - // called. - int clip_count; - }; - std::stack<RenderState> state_; - - DISALLOW_COPY_AND_ASSIGN(CanvasDirect2D); -}; - -} // namespace gfx - -#endif // UI_GFX_CANVAS_DIRECT2D_H_ diff --git a/ui/gfx/canvas_direct2d_unittest.cc b/ui/gfx/canvas_direct2d_unittest.cc deleted file mode 100644 index 460599e..0000000 --- a/ui/gfx/canvas_direct2d_unittest.cc +++ /dev/null @@ -1,332 +0,0 @@ -// Copyright (c) 2011 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 "base/memory/ref_counted_memory.h" -#include "base/memory/scoped_ptr.h" -#include "base/win/resource_util.h" -#include "grit/gfx_resources.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/gfx/brush.h" -#include "ui/gfx/canvas_direct2d.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/win_util.h" - - -namespace { - -const char kVisibleModeFlag[] = "d2d-canvas-visible"; -const wchar_t kWindowClassName[] = L"GFXD2DTestWindowClass"; - -class TestWindow { - public: - static const int kWindowSize = 500; - static const int kWindowPosition = 10; - - TestWindow() : hwnd_(NULL) { - if (CommandLine::ForCurrentProcess()->HasSwitch(kVisibleModeFlag)) - Sleep(1000); - - RegisterMyClass(); - - hwnd_ = CreateWindowEx(0, kWindowClassName, NULL, - WS_OVERLAPPEDWINDOW, - kWindowPosition, kWindowPosition, - kWindowSize, kWindowSize, - NULL, NULL, NULL, this); - DCHECK(hwnd_); - - // 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()); - UnregisterMyClass(); - } - - HWND hwnd() const { return hwnd_; } - - ID2D1RenderTarget* rt() const { return rt_.get(); } - - 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; - } - - void RegisterMyClass() { - WNDCLASSEX class_ex; - class_ex.cbSize = sizeof(WNDCLASSEX); - class_ex.style = CS_DBLCLKS; - class_ex.lpfnWndProc = &DefWindowProc; - class_ex.cbClsExtra = 0; - class_ex.cbWndExtra = 0; - class_ex.hInstance = NULL; - class_ex.hIcon = NULL; - class_ex.hCursor = LoadCursor(NULL, IDC_ARROW); - class_ex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND); - class_ex.lpszMenuName = NULL; - class_ex.lpszClassName = kWindowClassName; - class_ex.hIconSm = class_ex.hIcon; - ATOM atom = RegisterClassEx(&class_ex); - DCHECK(atom); - } - - void UnregisterMyClass() { - ::UnregisterClass(kWindowClassName, NULL); - } - - HWND hwnd_; - - base::win::ScopedComPtr<ID2D1RenderTarget> rt_; - - DISALLOW_COPY_AND_ASSIGN(TestWindow); -}; - -// 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 = GetModuleHandle(NULL); - void* data_ptr; - size_t data_size; - if (base::win::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; -} - -bool CheckForD2DCompatibility() { - if (!gfx::Direct2dIsAvailable()) { - LOG(WARNING) << "Test is disabled as it requires either Windows 7 or " << - "Vista with Platform Update KB971644"; - return false; - } - return true; -} - -} // namespace - -TEST(CanvasDirect2D, CreateCanvas) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); -} - -TEST(CanvasDirect2D, SaveRestoreNesting) { - if (!CheckForD2DCompatibility()) - return; - 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) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - canvas.Save(); - canvas.FillRect(SK_ColorBLUE, gfx::Rect(20, 20, 100, 100)); - canvas.SaveLayerAlpha(127); - canvas.FillRect(SK_ColorRED, gfx::Rect(60, 60, 100, 100)); - canvas.Restore(); - canvas.Restore(); -} - -TEST(CanvasDirect2D, SaveLayerAlphaWithBounds) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - canvas.Save(); - canvas.FillRect(SK_ColorBLUE, gfx::Rect(20, 20, 100, 100)); - canvas.SaveLayerAlpha(127, gfx::Rect(60, 60, 50, 50)); - canvas.FillRect(SK_ColorRED, gfx::Rect(60, 60, 100, 100)); - canvas.Restore(); - canvas.Restore(); -} - -TEST(CanvasDirect2D, FillRect) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - canvas.FillRect(SK_ColorRED, gfx::Rect(20, 20, 100, 100)); -} - -TEST(CanvasDirect2D, ClipRect) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - canvas.FillRect(SK_ColorGREEN, gfx::Rect(0, 0, 500, 500)); - canvas.ClipRect(gfx::Rect(20, 20, 120, 120)); - canvas.FillRect(SK_ColorBLUE, gfx::Rect(0, 0, 500, 500)); -} - -TEST(CanvasDirect2D, ClipRectWithTranslate) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - // Repeat the same rendering as in ClipRect... - canvas.Save(); - canvas.FillRect(SK_ColorGREEN, gfx::Rect(0, 0, 500, 500)); - canvas.ClipRect(gfx::Rect(20, 20, 120, 120)); - canvas.FillRect(SK_ColorBLUE, gfx::Rect(0, 0, 500, 500)); - canvas.Restore(); - - // ... then translate, clip and fill again relative to the new origin. - canvas.Save(); - canvas.Translate(gfx::Point(150, 150)); - canvas.ClipRect(gfx::Rect(10, 10, 110, 110)); - canvas.FillRect(SK_ColorRED, gfx::Rect(0, 0, 500, 500)); - canvas.Restore(); -} - -TEST(CanvasDirect2D, ClipRectWithScale) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - // Repeat the same rendering as in ClipRect... - canvas.Save(); - canvas.FillRect(SK_ColorGREEN, gfx::Rect(0, 0, 500, 500)); - canvas.ClipRect(gfx::Rect(20, 20, 120, 120)); - canvas.FillRect(SK_ColorBLUE, gfx::Rect(0, 0, 500, 500)); - canvas.Restore(); - - // ... then translate and scale, clip and fill again relative to the new - // origin. - canvas.Save(); - canvas.Translate(gfx::Point(150, 150)); - canvas.Scale(2, 2); - canvas.ClipRect(gfx::Rect(10, 10, 110, 110)); - canvas.FillRect(SK_ColorRED, gfx::Rect(0, 0, 500, 500)); - canvas.Restore(); -} - -TEST(CanvasDirect2D, DrawRectInt) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - canvas.Save(); - canvas.DrawRectInt(SK_ColorRED, 10, 10, 200, 200); - canvas.Restore(); -} - -TEST(CanvasDirect2D, DrawLineInt) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - canvas.Save(); - canvas.DrawLineInt(SK_ColorRED, 10, 10, 210, 210); - canvas.Restore(); -} - -TEST(CanvasDirect2D, DrawBitmapInt) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - SkBitmap bitmap = LoadBitmapFromResources(IDR_BITMAP_BRUSH_IMAGE); - - canvas.Save(); - canvas.DrawBitmapInt(bitmap, 100, 100); - canvas.Restore(); -} - -TEST(CanvasDirect2D, DrawBitmapInt2) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - SkBitmap bitmap = LoadBitmapFromResources(IDR_BITMAP_BRUSH_IMAGE); - - canvas.Save(); - canvas.DrawBitmapInt(bitmap, 5, 5, 30, 30, 10, 10, 30, 30, false); - canvas.DrawBitmapInt(bitmap, 5, 5, 30, 30, 110, 110, 100, 100, true); - canvas.DrawBitmapInt(bitmap, 5, 5, 30, 30, 220, 220, 100, 100, false); - canvas.Restore(); -} - -TEST(CanvasDirect2D, TileImageInt) { - if (!CheckForD2DCompatibility()) - return; - TestWindow window; - gfx::CanvasDirect2D canvas(window.rt()); - - SkBitmap bitmap = LoadBitmapFromResources(IDR_BITMAP_BRUSH_IMAGE); - - canvas.Save(); - canvas.TileImageInt(bitmap, 10, 10, 300, 300); - canvas.Restore(); -} @@ -419,8 +419,6 @@ }], ['OS=="win"', { 'sources': [ - 'gfx/canvas_direct2d.cc', - 'gfx/canvas_direct2d.h', 'gfx/gdi_util.cc', 'gfx/gdi_util.h', 'gfx/icon_util.cc', diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index 6bef7e8..5dc86a6 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -94,7 +94,6 @@ 'base/dragdrop/os_exchange_data_win_unittest.cc', 'base/view_prop_unittest.cc', # TODO(brettw) re-enable this when the dependencies on WindowImpl are fixed! - 'gfx/canvas_direct2d_unittest.cc', 'gfx/icon_util_unittest.cc', 'gfx/native_theme_win_unittest.cc', ], |