• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXGE_CFX_RENDERDEVICE_H_
8 #define CORE_FXGE_CFX_RENDERDEVICE_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "build/build_config.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 #include "core/fxge/fx_dib.h"
17 #include "core/fxge/render_defines.h"
18 #include "core/fxge/renderdevicedriver_iface.h"
19 
20 class CFX_DIBBase;
21 class CFX_DIBitmap;
22 class CFX_Font;
23 class CFX_GraphStateData;
24 class CFX_ImageRenderer;
25 class CFX_PathData;
26 class PauseIndicatorIface;
27 class TextCharPos;
28 struct CFX_Color;
29 
30 enum class BorderStyle { SOLID, DASH, BEVELED, INSET, UNDERLINE };
31 
32 class CFX_RenderDevice {
33  public:
34   class StateRestorer {
35    public:
36     explicit StateRestorer(CFX_RenderDevice* pDevice);
37     ~StateRestorer();
38 
39    private:
40     UnownedPtr<CFX_RenderDevice> m_pDevice;
41   };
42 
43   CFX_RenderDevice();
44   virtual ~CFX_RenderDevice();
45 
46   static CFX_Matrix GetFlipMatrix(float width,
47                                   float height,
48                                   float left,
49                                   float top);
50 
51   void SetDeviceDriver(std::unique_ptr<RenderDeviceDriverIface> pDriver);
GetDeviceDriver()52   RenderDeviceDriverIface* GetDeviceDriver() const {
53     return m_pDeviceDriver.get();
54   }
55 
56   void SaveState();
57   void RestoreState(bool bKeepSaved);
58 
GetWidth()59   int GetWidth() const { return m_Width; }
GetHeight()60   int GetHeight() const { return m_Height; }
GetDeviceType()61   DeviceType GetDeviceType() const { return m_DeviceType; }
GetRenderCaps()62   int GetRenderCaps() const { return m_RenderCaps; }
63   int GetDeviceCaps(int id) const;
64   RetainPtr<CFX_DIBitmap> GetBitmap() const;
65   void SetBitmap(const RetainPtr<CFX_DIBitmap>& pBitmap);
66   bool CreateCompatibleBitmap(const RetainPtr<CFX_DIBitmap>& pDIB,
67                               int width,
68                               int height) const;
GetClipBox()69   const FX_RECT& GetClipBox() const { return m_ClipBox; }
70   void SetBaseClip(const FX_RECT& rect);
71   bool SetClip_PathFill(const CFX_PathData* pPathData,
72                         const CFX_Matrix* pObject2Device,
73                         int fill_mode);
74   bool SetClip_PathStroke(const CFX_PathData* pPathData,
75                           const CFX_Matrix* pObject2Device,
76                           const CFX_GraphStateData* pGraphState);
77   bool SetClip_Rect(const FX_RECT& pRect);
DrawPath(const CFX_PathData * pPathData,const CFX_Matrix * pObject2Device,const CFX_GraphStateData * pGraphState,uint32_t fill_color,uint32_t stroke_color,int fill_mode)78   bool DrawPath(const CFX_PathData* pPathData,
79                 const CFX_Matrix* pObject2Device,
80                 const CFX_GraphStateData* pGraphState,
81                 uint32_t fill_color,
82                 uint32_t stroke_color,
83                 int fill_mode) {
84     return DrawPathWithBlend(pPathData, pObject2Device, pGraphState, fill_color,
85                              stroke_color, fill_mode, BlendMode::kNormal);
86   }
87   bool DrawPathWithBlend(const CFX_PathData* pPathData,
88                          const CFX_Matrix* pObject2Device,
89                          const CFX_GraphStateData* pGraphState,
90                          uint32_t fill_color,
91                          uint32_t stroke_color,
92                          int fill_mode,
93                          BlendMode blend_type);
FillRect(const FX_RECT & rect,uint32_t color)94   bool FillRect(const FX_RECT& rect, uint32_t color) {
95     return FillRectWithBlend(rect, color, BlendMode::kNormal);
96   }
97 
98   RetainPtr<CFX_DIBitmap> GetBackDrop();
99   bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top);
SetDIBits(const RetainPtr<CFX_DIBBase> & pBitmap,int left,int top)100   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int left, int top) {
101     return SetDIBitsWithBlend(pBitmap, left, top, BlendMode::kNormal);
102   }
103   bool SetDIBitsWithBlend(const RetainPtr<CFX_DIBBase>& pBitmap,
104                           int left,
105                           int top,
106                           BlendMode blend_mode);
StretchDIBits(const RetainPtr<CFX_DIBBase> & pBitmap,int left,int top,int dest_width,int dest_height)107   bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
108                      int left,
109                      int top,
110                      int dest_width,
111                      int dest_height) {
112     return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width,
113                                           dest_height, FXDIB_ResampleOptions(),
114                                           BlendMode::kNormal);
115   }
116   bool StretchDIBitsWithFlagsAndBlend(const RetainPtr<CFX_DIBBase>& pBitmap,
117                                       int left,
118                                       int top,
119                                       int dest_width,
120                                       int dest_height,
121                                       const FXDIB_ResampleOptions& options,
122                                       BlendMode blend_mode);
123   bool SetBitMask(const RetainPtr<CFX_DIBBase>& pBitmap,
124                   int left,
125                   int top,
126                   uint32_t argb);
127   bool StretchBitMask(const RetainPtr<CFX_DIBBase>& pBitmap,
128                       int left,
129                       int top,
130                       int dest_width,
131                       int dest_height,
132                       uint32_t color);
133   bool StretchBitMaskWithFlags(const RetainPtr<CFX_DIBBase>& pBitmap,
134                                int left,
135                                int top,
136                                int dest_width,
137                                int dest_height,
138                                uint32_t argb,
139                                const FXDIB_ResampleOptions& options);
StartDIBits(const RetainPtr<CFX_DIBBase> & pBitmap,int bitmap_alpha,uint32_t color,const CFX_Matrix & matrix,const FXDIB_ResampleOptions & options,std::unique_ptr<CFX_ImageRenderer> * handle)140   bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
141                    int bitmap_alpha,
142                    uint32_t color,
143                    const CFX_Matrix& matrix,
144                    const FXDIB_ResampleOptions& options,
145                    std::unique_ptr<CFX_ImageRenderer>* handle) {
146     return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, matrix, options,
147                                 handle, BlendMode::kNormal);
148   }
149   bool StartDIBitsWithBlend(const RetainPtr<CFX_DIBBase>& pBitmap,
150                             int bitmap_alpha,
151                             uint32_t argb,
152                             const CFX_Matrix& matrix,
153                             const FXDIB_ResampleOptions& options,
154                             std::unique_ptr<CFX_ImageRenderer>* handle,
155                             BlendMode blend_mode);
156   bool ContinueDIBits(CFX_ImageRenderer* handle, PauseIndicatorIface* pPause);
157 
158   bool DrawNormalText(int nChars,
159                       const TextCharPos* pCharPos,
160                       CFX_Font* pFont,
161                       float font_size,
162                       const CFX_Matrix& mtText2Device,
163                       uint32_t fill_color,
164                       uint32_t text_flags);
165   bool DrawTextPath(int nChars,
166                     const TextCharPos* pCharPos,
167                     CFX_Font* pFont,
168                     float font_size,
169                     const CFX_Matrix& mtText2User,
170                     const CFX_Matrix* pUser2Device,
171                     const CFX_GraphStateData* pGraphState,
172                     uint32_t fill_color,
173                     uint32_t stroke_color,
174                     CFX_PathData* pClippingPath,
175                     int nFlag);
176 
177   void DrawFillRect(const CFX_Matrix* pUser2Device,
178                     const CFX_FloatRect& rect,
179                     const CFX_Color& color,
180                     int32_t nTransparency);
181   void DrawFillRect(const CFX_Matrix* pUser2Device,
182                     const CFX_FloatRect& rect,
183                     const FX_COLORREF& color);
184   void DrawStrokeRect(const CFX_Matrix& mtUser2Device,
185                       const CFX_FloatRect& rect,
186                       const FX_COLORREF& color,
187                       float fWidth);
188   void DrawStrokeLine(const CFX_Matrix* pUser2Device,
189                       const CFX_PointF& ptMoveTo,
190                       const CFX_PointF& ptLineTo,
191                       const FX_COLORREF& color,
192                       float fWidth);
193   void DrawBorder(const CFX_Matrix* pUser2Device,
194                   const CFX_FloatRect& rect,
195                   float fWidth,
196                   const CFX_Color& color,
197                   const CFX_Color& crLeftTop,
198                   const CFX_Color& crRightBottom,
199                   BorderStyle nStyle,
200                   int32_t nTransparency);
201   void DrawFillArea(const CFX_Matrix& mtUser2Device,
202                     const std::vector<CFX_PointF>& points,
203                     const FX_COLORREF& color);
204   void DrawShadow(const CFX_Matrix& mtUser2Device,
205                   bool bVertical,
206                   bool bHorizontal,
207                   const CFX_FloatRect& rect,
208                   int32_t nTransparency,
209                   int32_t nStartGray,
210                   int32_t nEndGray);
211 
212 #ifdef _SKIA_SUPPORT_
213   virtual void DebugVerifyBitmapIsPreMultiplied() const;
214   virtual bool SetBitsWithMask(const RetainPtr<CFX_DIBBase>& pBitmap,
215                                const RetainPtr<CFX_DIBBase>& pMask,
216                                int left,
217                                int top,
218                                int bitmap_alpha,
219                                BlendMode blend_type);
220 #endif
221 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
222   void Flush(bool release);
223 #endif
224 
225  private:
226   void InitDeviceInfo();
227   void UpdateClipBox();
228   bool DrawFillStrokePath(const CFX_PathData* pPathData,
229                           const CFX_Matrix* pObject2Device,
230                           const CFX_GraphStateData* pGraphState,
231                           uint32_t fill_color,
232                           uint32_t stroke_color,
233                           int fill_mode,
234                           BlendMode blend_type);
235   bool DrawCosmeticLine(const CFX_PointF& ptMoveTo,
236                         const CFX_PointF& ptLineTo,
237                         uint32_t color,
238                         int fill_mode,
239                         BlendMode blend_type);
240   bool FillRectWithBlend(const FX_RECT& rect,
241                          uint32_t color,
242                          BlendMode blend_type);
243 
244   RetainPtr<CFX_DIBitmap> m_pBitmap;
245   int m_Width = 0;
246   int m_Height = 0;
247   int m_bpp = 0;
248   int m_RenderCaps = 0;
249   DeviceType m_DeviceType = DeviceType::kUnknown;
250   FX_RECT m_ClipBox;
251   std::unique_ptr<RenderDeviceDriverIface> m_pDeviceDriver;
252 };
253 
254 #endif  // CORE_FXGE_CFX_RENDERDEVICE_H_
255