Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / inc / FGrp_CanvasImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrp_CanvasImpl.h
20  * @brief       This is the header file for the _CanvasImpl class.
21  *
22  * This header file contains the declarations of the %_CanvasImpl class.
23  *
24  */
25
26 #ifndef _FGRP_INTERNAL_CANVASIMPL_H_
27 #define _FGRP_INTERNAL_CANVASIMPL_H_
28
29
30 #include <FBaseObject.h>
31 #include <FGrpCanvasCommon.h>
32 #include <FBaseColArrayListT.h>
33
34
35 namespace Tizen { namespace Base { namespace Collection
36 {
37 class IList;
38 }}} // Tizen::Base::Collection
39
40 namespace Tizen { namespace Ui { namespace Animations
41 {
42 class _VisualElementCanvas;
43 }}} // Tizen::Ui::Animations
44
45 namespace Tizen { namespace Graphics
46 {
47 class Point;
48 class Dimension;
49 class Rectangle;
50 class FloatPoint;
51 class FloatDimension;
52 class FloatRectangle;
53 class Color;
54 class BufferInfo;
55 class Bitmap;
56 class Canvas;
57 class Font;
58 class EnrichedText;
59
60 class _BitmapImpl;
61 class _Canvas;
62
63
64 // * @enum      BitmapDrawingQuality
65 // *
66 // * Defines the bitmap drawing quality.
67 // *
68 // * @since 2.0
69
70 enum BitmapDrawingQuality
71 {
72         BITMAP_DRAWING_QUALITY_LOW, // The low-quality but high-performance
73         BITMAP_DRAWING_QUALITY_MID, // The mid-quality
74         BITMAP_DRAWING_QUALITY_HIGH // The high-quality but low-performance
75 };
76
77 enum TextOrigin
78 {
79         TEXT_ORIGIN_LEFT_TOP,
80         TEXT_ORIGIN_BASELINE
81 };
82
83 /* For test, CR not approved */
84 enum BlendingMode
85 {
86         BLENDING_MODE_CLEAR, // [0, 0]
87         BLENDING_MODE_SRC, // [Sa, Sc]
88         BLENDING_MODE_DST, // [Da, Dc]
89         BLENDING_MODE_SRC_OVER, // [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
90         BLENDING_MODE_DST_OVER, // [Sa + (1 - Sa)*Da, Rc = Dc + (1 - Da)*Sc]
91         BLENDING_MODE_SRC_IN, // [Sa * Da, Sc * Da]
92         BLENDING_MODE_DST_IN, // [Sa * Da, Sa * Dc]
93         BLENDING_MODE_SRC_OUT, // [Sa * (1 - Da), Sc * (1 - Da)]
94         BLENDING_MODE_DST_OUT, // [Da * (1 - Sa), Dc * (1 - Sa)]
95         BLENDING_MODE_SRC_ATOP, // [Da, Sc * Da + (1 - Sa) * Dc]
96         BLENDING_MODE_DST_ATOP, // [Sa, Sa * Dc + Sc * (1 - Da)]
97         BLENDING_MODE_DST_XOR, // [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
98         BLENDING_MODE_ADD,
99         BLENDING_MODE_SATURATE, // Saturate(S + D)
100         // Pixman extension 1
101         BLENDING_MODE_MULTIPLY, // [Sa * Da, Sc * Dc]
102         BLENDING_MODE_SCREEN, // [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
103         BLENDING_MODE_OVERLAY,
104         BLENDING_MODE_DARKEN, // [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]
105         BLENDING_MODE_LIGHTEN, // [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]
106         // Pixman extension 2
107         BLENDING_MODE_COLOR_DODGE,
108         BLENDING_MODE_COLOR_BURN,
109         BLENDING_MODE_HARD_LIGHT,
110         BLENDING_MODE_SOFT_LIGHT,
111         BLENDING_MODE_DIFFERENCE,
112         BLENDING_MODE_EXCLUSION
113 };
114
115 class _OSP_EXPORT_ _CanvasImpl
116         : public Tizen::Base::Object
117 {
118 public:
119         _CanvasImpl(void);
120         virtual ~_CanvasImpl(void);
121
122         result Construct(void);
123         result Construct(const Rectangle& rect);
124         result Construct(Handle windowHandle, const Rectangle& rect);
125         result Construct(const BufferInfo& bufferInfo);
126
127         bool IsConstructed(void) const;
128
129         result Clear(void);
130         result Clear(const Rectangle& rect);
131
132         result Copy(const Point& destPoint, const _CanvasImpl& srcCanvas, const Rectangle& srcRect);
133         result Copy(const Rectangle& destRect, const _CanvasImpl& srcCanvas, const Rectangle& srcRect);
134         result Copy(const Point& destPoint, const _CanvasImpl& srcCanvas, const Rectangle& srcRect, BlendingMode blendingMode);
135
136         result CopyEx(const Point& destPoint, const _CanvasImpl& srcCanvas, const Rectangle& srcRect);
137
138         LineStyle GetLineStyle(void) const;
139         int GetLineWidth(void) const;
140         result SetLineStyle(LineStyle style);
141         result SetLineWidth(int width);
142
143         result GetDashPattern(Tizen::Base::Collection::IListT<int>& pattern, int& offset);
144         result SetDashPattern(const Tizen::Base::Collection::IListT<int>& pattern, int offset);
145
146         result SetDrawingQuality(BitmapDrawingQuality quality);
147         BitmapDrawingQuality GetDrawingQuality(void) const;
148
149         result SetBlendingMode(BlendingMode blendingMode);
150         BlendingMode GetBlendingMode(void) const;
151
152         result GetPixel(const Point& point, Color& color) const;
153
154         result SetPixel(const Point& point);
155         result SetPixel(const FloatPoint& point); // floating-point version
156
157         result DrawRectangle(const Rectangle& rect);
158         result DrawRectangle(const FloatRectangle& rect); // floating-point version
159         result FillRectangle(const Color& color, const Rectangle& rect);
160         result FillRectangle(const Color& color, const FloatRectangle& rect); // floating-point version
161
162         result DrawRoundRectangle(const Rectangle& rect, const Dimension& arcDim);
163         result DrawRoundRectangle(const FloatRectangle& rect, const FloatDimension& arcDim); // floating-point version
164         result FillRoundRectangle(const Color& color, const Rectangle& rect, const Dimension& arcDim);
165         result FillRoundRectangle(const Color& color, const FloatRectangle& rect, const FloatDimension& arcDim); // floating-point version
166
167         result DrawEllipse(const Rectangle& rect);
168         result DrawEllipse(const FloatRectangle& rect); // floating-point version
169         result FillEllipse(const Color& color, const Rectangle& rect);
170         result FillEllipse(const Color& color, const FloatRectangle& rect); // floating-point version
171
172         result DrawArc(const Rectangle& rect, int startAngle, int endAngle, ArcStyle arcStyle);
173         result DrawArc(const FloatRectangle& rect, float startAngle, float endAngle, ArcStyle arcStyle); // floating-point version
174
175         result DrawTriangle(const Point& point1, const Point& point2, const Point& point3);
176         result DrawTriangle(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& point3); // floating-point version
177         result FillTriangle(const Color& color, const Point& point1, const Point& point2, const Point& point3);
178         result FillTriangle(const Color& color, const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& point3); // floating-point version
179
180         result DrawLine(const Point& point1, const Point& point2);
181         result DrawLine(const FloatPoint& point1, const FloatPoint& point2); // floating-point version
182         result DrawPolyline(const Tizen::Base::Collection::IList& points);
183         result DrawPolygon(const Tizen::Base::Collection::IList& points);
184         result FillPolygon(const Color& color, const Tizen::Base::Collection::IList& points);
185
186         result SetFont(const Font& font);
187         Font* GetFontN(void);
188
189         void SetTextOrigin(TextOrigin origin);
190
191         result DrawText(const Point& point, const Tizen::Base::String& text);
192         result DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length);
193         result DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, const Color& outlineColor);
194         result DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor);
195         result DrawText(const Point& point, const EnrichedText& enrichedText);
196
197         result DrawBitmap(const Point& point, const _BitmapImpl& bitmap);
198         result DrawBitmap(const FloatPoint& point, const _BitmapImpl& bitmap); // floating-point version
199         result DrawBitmap(const Rectangle& rect, const _BitmapImpl& bitmap);
200         result DrawBitmap(const FloatRectangle& rect, const _BitmapImpl& bitmap); // floating-point version
201         result DrawBitmap(const Rectangle& destRect, const _BitmapImpl& srcBitmap, const Rectangle& srcRect);
202         result DrawBitmap(const FloatRectangle& destRect, const _BitmapImpl& srcBitmap, const FloatRectangle& srcRect); // floating-point version
203         result DrawBitmap(const Point& point, const _BitmapImpl& bitmap, FlipDirection dir);
204         result DrawBitmap(const FloatPoint& point, const _BitmapImpl& bitmap, FlipDirection dir); // floating-point version
205         result DrawBitmap(const Point& point, const _BitmapImpl& bitmap, const Point& pivot, int degree);
206         result DrawBitmap(const FloatPoint& point, const _BitmapImpl& bitmap, const FloatPoint& pivot, float degree); // floating-point version
207         result DrawNinePatchedBitmap(const Rectangle& rect, const _BitmapImpl& bitmap);
208         result DrawNinePatchedBitmap(const FloatRectangle& rect, const _BitmapImpl& bitmap); // floating-point version
209
210         result Show(void);
211         result Show(const Rectangle& rect);
212
213         Rectangle GetBounds(void) const;
214
215         result SetClipBounds(const Rectangle& rect);
216         Rectangle GetClipBounds(void) const;
217
218         result Lock(BufferInfo& info, long timeout = INFINITE);
219         result Unlock(void);
220
221         void SetForegroundColor(const Color& color);
222         Color GetForegroundColor(void) const;
223         void SetBackgroundColor(const Color& color);
224         Color GetBackgroundColor(void) const;
225
226         result SetPosition(const Point& point);
227         result SetPosition(int x, int y);
228
229         Canvas* GetSubCanvasN(const Rectangle& subRegion) const;
230
231         /*
232          * Sets a priority font to the %_CanvasImpl. This font have priority at user font which is installed through _CanvasImpl::SetFont()
233          *
234          * @return              An error code
235          * @param[in]   pFont   The font @n
236          *                      It should be constructed before being passed to this method.
237          * @exception  E_SUCCESS                        The method is successful.
238          * @exception  E_INVALID_ARG            The specified input parameter is invalid.
239          * @exception  E_OPERATION_FAILED       This instance is in an invalid state.
240          */
241         result SetPriorityFont(const Font& font);
242
243         /*
244          * Resets a priority font
245          */
246         void ResetPriorityFont(void);
247
248         // for performance test
249         void SetStableRenderer(bool isStable);
250
251         // for removing the Ui dependency
252         static void SetFrameInfoCallback(void* (*pGetDefaultFrameNativeHandle)(void), void* (*pGetDefaultFrameHandle)(void));
253         static void SetThemeInfoCallback(Color (*pGetDefaultForegroundColor)(void), Color (*pGetDefaultBackgroundColor)(void));
254
255         static _CanvasImpl* GetInstance(Canvas& canvas);
256         static const _CanvasImpl* GetInstance(const Canvas& canvas);
257
258 private:
259         _CanvasImpl(const _CanvasImpl& canvas);
260         _CanvasImpl& operator =(const _CanvasImpl& value);
261
262 protected:
263         _Canvas* _pNativeCanvas;
264         struct _CanvasCoordHolder* _pCoordHolder;
265         Font* _pFont;
266         Font* _pPriorityFont;
267         Tizen::Base::Collection::ArrayListT<int> _dashList;
268         int _dashOffset;
269
270         friend class _Canvas;
271         friend class _CanvasImplPrivate;
272         friend class _BitmapImpl;
273         friend class TextElement;
274         friend class Tizen::Ui::Animations::_VisualElementCanvas;
275
276 }; // _CanvasImpl
277
278 }} // Tizen::Graphics
279
280 #endif // _FGRP_INTERNAL_CANVASIMPL_H_