OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef GFX_CANVAS_DIRECT2D_H_ | 5 #ifndef GFX_CANVAS_DIRECT2D_H_ |
6 #define GFX_CANVAS_DIRECT2D_H_ | 6 #define GFX_CANVAS_DIRECT2D_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <d2d1.h> | 9 #include "ui/gfx/canvas_direct2d.h" |
10 | 10 // TODO(sail): remove this file once all includes have been updated. |
11 #include <stack> | |
12 | |
13 #include "base/scoped_comptr_win.h" | |
14 #include "gfx/canvas.h" | |
15 | |
16 namespace gfx { | |
17 | |
18 class CanvasDirect2D : public Canvas { | |
19 public: | |
20 // Creates an empty Canvas. | |
21 explicit CanvasDirect2D(ID2D1RenderTarget* rt); | |
22 virtual ~CanvasDirect2D(); | |
23 | |
24 // Retrieves the application's D2D1 Factory. | |
25 static ID2D1Factory* GetD2D1Factory(); | |
26 | |
27 // Overridden from Canvas: | |
28 virtual void Save(); | |
29 virtual void SaveLayerAlpha(uint8 alpha); | |
30 virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); | |
31 virtual void Restore(); | |
32 virtual bool ClipRectInt(int x, int y, int w, int h); | |
33 virtual void TranslateInt(int x, int y); | |
34 virtual void ScaleInt(int x, int y); | |
35 virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h); | |
36 virtual void FillRectInt(const SkColor& color, int x, int y, int w, int h, | |
37 SkXfermode::Mode mode); | |
38 virtual void FillRectInt(const gfx::Brush* brush, int x, int y, int w, int h); | |
39 virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h); | |
40 virtual void DrawRectInt(const SkColor& color, | |
41 int x, int y, int w, int h, | |
42 SkXfermode::Mode mode); | |
43 virtual void DrawRectInt(int x, int y, int w, int h, const SkPaint& paint); | |
44 virtual void DrawLineInt(const SkColor& color, | |
45 int x1, int y1, | |
46 int x2, int y2); | |
47 virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); | |
48 virtual void DrawBitmapInt(const SkBitmap& bitmap, | |
49 int x, int y, | |
50 const SkPaint& paint); | |
51 virtual void DrawBitmapInt(const SkBitmap& bitmap, | |
52 int src_x, int src_y, int src_w, int src_h, | |
53 int dest_x, int dest_y, int dest_w, int dest_h, | |
54 bool filter); | |
55 virtual void DrawBitmapInt(const SkBitmap& bitmap, | |
56 int src_x, int src_y, int src_w, int src_h, | |
57 int dest_x, int dest_y, int dest_w, int dest_h, | |
58 bool filter, | |
59 const SkPaint& paint); | |
60 virtual void DrawStringInt(const string16& text, | |
61 const gfx::Font& font, | |
62 const SkColor& color, | |
63 int x, int y, int w, int h); | |
64 virtual void DrawStringInt(const string16& text, | |
65 const gfx::Font& font, | |
66 const SkColor& color, | |
67 const gfx::Rect& display_rect); | |
68 virtual void DrawStringInt(const string16& text, | |
69 const gfx::Font& font, | |
70 const SkColor& color, | |
71 int x, int y, int w, int h, | |
72 int flags); | |
73 virtual void DrawFocusRect(int x, int y, int width, int height); | |
74 virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); | |
75 virtual void TileImageInt(const SkBitmap& bitmap, | |
76 int src_x, int src_y, | |
77 int dest_x, int dest_y, int w, int h); | |
78 virtual gfx::NativeDrawingContext BeginPlatformPaint(); | |
79 virtual void EndPlatformPaint(); | |
80 virtual CanvasSkia* AsCanvasSkia(); | |
81 virtual const CanvasSkia* AsCanvasSkia() const; | |
82 | |
83 private: | |
84 void SaveInternal(ID2D1Layer* layer); | |
85 | |
86 ID2D1RenderTarget* rt_; | |
87 ScopedComPtr<ID2D1GdiInteropRenderTarget> interop_rt_; | |
88 ScopedComPtr<ID2D1DrawingStateBlock> drawing_state_block_; | |
89 static ID2D1Factory* d2d1_factory_; | |
90 | |
91 // Every time Save* is called, a RenderState object is pushed onto the | |
92 // RenderState stack. | |
93 struct RenderState { | |
94 explicit RenderState(ID2D1Layer* layer) : layer(layer), clip_count(0) {} | |
95 RenderState() : layer(NULL), clip_count(0) {} | |
96 | |
97 // A D2D layer associated with this state, or NULL if there is no layer. | |
98 // The layer is created and owned by the Canvas. | |
99 ID2D1Layer* layer; | |
100 // The number of clip operations performed. This is used to balance calls to | |
101 // PushAxisAlignedClip with calls to PopAxisAlignedClip when Restore() is | |
102 // called. | |
103 int clip_count; | |
104 }; | |
105 std::stack<RenderState> state_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(CanvasDirect2D); | |
108 }; | |
109 | |
110 } // namespace gfx; | |
111 | 11 |
112 #endif // GFX_CANVAS_DIRECT2D_H_ | 12 #endif // GFX_CANVAS_DIRECT2D_H_ |
OLD | NEW |