| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/canvas_direct2d.h" | 5 #include "ui/gfx/canvas_direct2d.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "ui/gfx/brush.h" | 8 #include "ui/gfx/brush.h" |
| 9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 bitmap.unlockPixels(); | 56 bitmap.unlockPixels(); |
| 57 return d2d1_bitmap; | 57 return d2d1_bitmap; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Creates a Direct2D bitmap brush from the contents of a SkBitmap. The caller | 60 // Creates a Direct2D bitmap brush from the contents of a SkBitmap. The caller |
| 61 // is responsible for releasing this object. | 61 // is responsible for releasing this object. |
| 62 ID2D1Brush* CreateD2D1BrushFromSkBitmap(ID2D1RenderTarget* render_target, | 62 ID2D1Brush* CreateD2D1BrushFromSkBitmap(ID2D1RenderTarget* render_target, |
| 63 const SkBitmap& bitmap, | 63 const SkBitmap& bitmap, |
| 64 D2D1_EXTEND_MODE extend_mode_x, | 64 D2D1_EXTEND_MODE extend_mode_x, |
| 65 D2D1_EXTEND_MODE extend_mode_y) { | 65 D2D1_EXTEND_MODE extend_mode_y) { |
| 66 ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( | 66 base::win::ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( |
| 67 CreateD2D1BitmapFromSkBitmap(render_target, bitmap)); | 67 CreateD2D1BitmapFromSkBitmap(render_target, bitmap)); |
| 68 | 68 |
| 69 ID2D1BitmapBrush* brush = NULL; | 69 ID2D1BitmapBrush* brush = NULL; |
| 70 render_target->CreateBitmapBrush( | 70 render_target->CreateBitmapBrush( |
| 71 d2d1_bitmap, | 71 d2d1_bitmap, |
| 72 D2D1::BitmapBrushProperties(extend_mode_x, extend_mode_y), | 72 D2D1::BitmapBrushProperties(extend_mode_x, extend_mode_y), |
| 73 D2D1::BrushProperties(), | 73 D2D1::BrushProperties(), |
| 74 &brush); | 74 &brush); |
| 75 return brush; | 75 return brush; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // A platform wrapper for a Direct2D brush that makes sure the underlying | 78 // A platform wrapper for a Direct2D brush that makes sure the underlying |
| 79 // ID2D1Brush COM object is released when this object is destroyed. | 79 // ID2D1Brush COM object is released when this object is destroyed. |
| 80 class Direct2DBrush : public gfx::Brush { | 80 class Direct2DBrush : public gfx::Brush { |
| 81 public: | 81 public: |
| 82 explicit Direct2DBrush(ID2D1Brush* brush) : brush_(brush) { | 82 explicit Direct2DBrush(ID2D1Brush* brush) : brush_(brush) { |
| 83 } | 83 } |
| 84 | 84 |
| 85 ID2D1Brush* brush() const { return brush_.get(); } | 85 ID2D1Brush* brush() const { return brush_.get(); } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 ScopedComPtr<ID2D1Brush> brush_; | 88 base::win::ScopedComPtr<ID2D1Brush> brush_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(Direct2DBrush); | 90 DISALLOW_COPY_AND_ASSIGN(Direct2DBrush); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 | 93 |
| 94 } // namespace | 94 } // namespace |
| 95 | 95 |
| 96 namespace gfx { | 96 namespace gfx { |
| 97 | 97 |
| 98 // static | 98 // static |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 rt_->GetTransform(&raw); | 197 rt_->GetTransform(&raw); |
| 198 D2D1::Matrix3x2F transform(raw._11, raw._12, raw._21, raw._22, raw._31, | 198 D2D1::Matrix3x2F transform(raw._11, raw._12, raw._21, raw._22, raw._31, |
| 199 raw._32); | 199 raw._32); |
| 200 transform = D2D1::Matrix3x2F::Scale(static_cast<float>(x), | 200 transform = D2D1::Matrix3x2F::Scale(static_cast<float>(x), |
| 201 static_cast<float>(y)) * transform; | 201 static_cast<float>(y)) * transform; |
| 202 rt_->SetTransform(transform); | 202 rt_->SetTransform(transform); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void CanvasDirect2D::FillRectInt(const SkColor& color, | 205 void CanvasDirect2D::FillRectInt(const SkColor& color, |
| 206 int x, int y, int w, int h) { | 206 int x, int y, int w, int h) { |
| 207 ScopedComPtr<ID2D1SolidColorBrush> solid_brush; | 207 base::win::ScopedComPtr<ID2D1SolidColorBrush> solid_brush; |
| 208 rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); | 208 rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); |
| 209 rt_->FillRectangle(RectToRectF(x, y, w, h), solid_brush); | 209 rt_->FillRectangle(RectToRectF(x, y, w, h), solid_brush); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void CanvasDirect2D::FillRectInt(const SkColor& color, | 212 void CanvasDirect2D::FillRectInt(const SkColor& color, |
| 213 int x, int y, int w, int h, | 213 int x, int y, int w, int h, |
| 214 SkXfermode::Mode mode) { | 214 SkXfermode::Mode mode) { |
| 215 NOTIMPLEMENTED(); | 215 NOTIMPLEMENTED(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void CanvasDirect2D::FillRectInt(const gfx::Brush* brush, | 218 void CanvasDirect2D::FillRectInt(const gfx::Brush* brush, |
| 219 int x, int y, int w, int h) { | 219 int x, int y, int w, int h) { |
| 220 const Direct2DBrush* d2d_brush = static_cast<const Direct2DBrush*>(brush); | 220 const Direct2DBrush* d2d_brush = static_cast<const Direct2DBrush*>(brush); |
| 221 rt_->FillRectangle(RectToRectF(x, y, w, h), d2d_brush->brush()); | 221 rt_->FillRectangle(RectToRectF(x, y, w, h), d2d_brush->brush()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void CanvasDirect2D::DrawRectInt(const SkColor& color, | 224 void CanvasDirect2D::DrawRectInt(const SkColor& color, |
| 225 int x, int y, int w, int h) { | 225 int x, int y, int w, int h) { |
| 226 ScopedComPtr<ID2D1SolidColorBrush> solid_brush; | 226 base::win::ScopedComPtr<ID2D1SolidColorBrush> solid_brush; |
| 227 rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); | 227 rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); |
| 228 rt_->DrawRectangle(RectToRectF(x, y, w, h), solid_brush); | 228 rt_->DrawRectangle(RectToRectF(x, y, w, h), solid_brush); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void CanvasDirect2D::DrawRectInt(const SkColor& color, | 231 void CanvasDirect2D::DrawRectInt(const SkColor& color, |
| 232 int x, int y, int w, int h, | 232 int x, int y, int w, int h, |
| 233 SkXfermode::Mode mode) { | 233 SkXfermode::Mode mode) { |
| 234 NOTIMPLEMENTED(); | 234 NOTIMPLEMENTED(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void CanvasDirect2D::DrawRectInt(int x, int y, int w, int h, | 237 void CanvasDirect2D::DrawRectInt(int x, int y, int w, int h, |
| 238 const SkPaint& paint) { | 238 const SkPaint& paint) { |
| 239 NOTIMPLEMENTED(); | 239 NOTIMPLEMENTED(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void CanvasDirect2D::DrawLineInt(const SkColor& color, | 242 void CanvasDirect2D::DrawLineInt(const SkColor& color, |
| 243 int x1, int y1, | 243 int x1, int y1, |
| 244 int x2, int y2) { | 244 int x2, int y2) { |
| 245 ScopedComPtr<ID2D1SolidColorBrush> solid_brush; | 245 base::win::ScopedComPtr<ID2D1SolidColorBrush> solid_brush; |
| 246 rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); | 246 rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive()); |
| 247 rt_->DrawLine(PointToPoint2F(x1, y1), PointToPoint2F(x2, y2), solid_brush); | 247 rt_->DrawLine(PointToPoint2F(x1, y1), PointToPoint2F(x2, y2), solid_brush); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { | 250 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { |
| 251 ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( | 251 base::win::ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( |
| 252 CreateD2D1BitmapFromSkBitmap(rt_, bitmap)); | 252 CreateD2D1BitmapFromSkBitmap(rt_, bitmap)); |
| 253 rt_->DrawBitmap(d2d1_bitmap, | 253 rt_->DrawBitmap(d2d1_bitmap, |
| 254 RectToRectF(x, y, bitmap.width(), bitmap.height()), | 254 RectToRectF(x, y, bitmap.width(), bitmap.height()), |
| 255 1.0f, | 255 1.0f, |
| 256 D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, | 256 D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, |
| 257 RectToRectF(0, 0, bitmap.width(), bitmap.height())); | 257 RectToRectF(0, 0, bitmap.width(), bitmap.height())); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, | 260 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, |
| 261 int x, int y, | 261 int x, int y, |
| 262 const SkPaint& paint) { | 262 const SkPaint& paint) { |
| 263 NOTIMPLEMENTED(); | 263 NOTIMPLEMENTED(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, | 266 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, |
| 267 int src_x, int src_y, int src_w, int src_h, | 267 int src_x, int src_y, int src_w, int src_h, |
| 268 int dest_x, int dest_y, | 268 int dest_x, int dest_y, |
| 269 int dest_w, int dest_h, | 269 int dest_w, int dest_h, |
| 270 bool filter) { | 270 bool filter) { |
| 271 ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( | 271 base::win::ScopedComPtr<ID2D1Bitmap> d2d1_bitmap( |
| 272 CreateD2D1BitmapFromSkBitmap(rt_, bitmap)); | 272 CreateD2D1BitmapFromSkBitmap(rt_, bitmap)); |
| 273 rt_->DrawBitmap(d2d1_bitmap, | 273 rt_->DrawBitmap(d2d1_bitmap, |
| 274 RectToRectF(dest_x, dest_y, dest_w, dest_h), | 274 RectToRectF(dest_x, dest_y, dest_w, dest_h), |
| 275 1.0f, | 275 1.0f, |
| 276 FilterToInterpolationMode(filter), | 276 FilterToInterpolationMode(filter), |
| 277 RectToRectF(src_x, src_y, src_w, src_h)); | 277 RectToRectF(src_x, src_y, src_w, src_h)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, | 280 void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, |
| 281 int src_x, int src_y, int src_w, int src_h, | 281 int src_x, int src_y, int src_w, int src_h, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 307 int flags) { | 307 int flags) { |
| 308 NOTIMPLEMENTED(); | 308 NOTIMPLEMENTED(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void CanvasDirect2D::DrawFocusRect(int x, int y, int width, int height) { | 311 void CanvasDirect2D::DrawFocusRect(int x, int y, int width, int height) { |
| 312 NOTIMPLEMENTED(); | 312 NOTIMPLEMENTED(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, | 315 void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, |
| 316 int x, int y, int w, int h) { | 316 int x, int y, int w, int h) { |
| 317 ScopedComPtr<ID2D1Brush> brush( | 317 base::win::ScopedComPtr<ID2D1Brush> brush( |
| 318 CreateD2D1BrushFromSkBitmap(rt_, bitmap, D2D1_EXTEND_MODE_WRAP, | 318 CreateD2D1BrushFromSkBitmap(rt_, bitmap, D2D1_EXTEND_MODE_WRAP, |
| 319 D2D1_EXTEND_MODE_WRAP)); | 319 D2D1_EXTEND_MODE_WRAP)); |
| 320 rt_->FillRectangle(RectToRectF(x, y, w, h), brush); | 320 rt_->FillRectangle(RectToRectF(x, y, w, h), brush); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, | 323 void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, |
| 324 int src_x, int src_y, | 324 int src_x, int src_y, |
| 325 int dest_x, int dest_y, int w, int h) { | 325 int dest_x, int dest_y, int w, int h) { |
| 326 NOTIMPLEMENTED(); | 326 NOTIMPLEMENTED(); |
| 327 } | 327 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // CanvasDirect2D, private: | 362 // CanvasDirect2D, private: |
| 363 | 363 |
| 364 void CanvasDirect2D::SaveInternal(ID2D1Layer* layer) { | 364 void CanvasDirect2D::SaveInternal(ID2D1Layer* layer) { |
| 365 if (!drawing_state_block_) | 365 if (!drawing_state_block_) |
| 366 GetD2D1Factory()->CreateDrawingStateBlock(drawing_state_block_.Receive()); | 366 GetD2D1Factory()->CreateDrawingStateBlock(drawing_state_block_.Receive()); |
| 367 rt_->SaveDrawingState(drawing_state_block_.get()); | 367 rt_->SaveDrawingState(drawing_state_block_.get()); |
| 368 state_.push(RenderState(layer)); | 368 state_.push(RenderState(layer)); |
| 369 } | 369 } |
| 370 | 370 |
| 371 } // namespace gfx | 371 } // namespace gfx |
| OLD | NEW |