cfx_renderdevice.h revision 33357cad1fd1321a2b38d2963e2585f27ce980a2
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
12#include "core/fxge/cfx_gemodule.h"
13#include "core/fxge/fx_dib.h"
14#include "core/fxge/fx_font.h"
15
16class CFX_Font;
17class CFX_GraphStateData;
18class IFX_RenderDeviceDriver;
19
20#define FXDC_DEVICE_CLASS 1
21#define FXDC_PIXEL_WIDTH 2
22#define FXDC_PIXEL_HEIGHT 3
23#define FXDC_BITS_PIXEL 4
24#define FXDC_HORZ_SIZE 5
25#define FXDC_VERT_SIZE 6
26#define FXDC_RENDER_CAPS 7
27#define FXDC_DISPLAY 1
28#define FXDC_PRINTER 2
29
30#define FXRC_GET_BITS 0x01
31#define FXRC_BIT_MASK 0x02
32#define FXRC_ALPHA_MASK 0x04
33#define FXRC_ALPHA_PATH 0x10
34#define FXRC_ALPHA_IMAGE 0x20
35#define FXRC_ALPHA_OUTPUT 0x40
36#define FXRC_BLEND_MODE 0x80
37#define FXRC_SOFT_CLIP 0x100
38#define FXRC_CMYK_OUTPUT 0x200
39#define FXRC_BITMASK_OUTPUT 0x400
40#define FXRC_BYTEMASK_OUTPUT 0x800
41#define FXRENDER_IMAGE_LOSSY 0x1000
42#define FXRC_FILLSTROKE_PATH 0x2000
43#define FXRC_SHADING 0x4000
44
45#define FXFILL_ALTERNATE 1
46#define FXFILL_WINDING 2
47#define FXFILL_FULLCOVER 4
48#define FXFILL_RECT_AA 8
49#define FX_FILL_STROKE 16
50#define FX_STROKE_ADJUST 32
51#define FX_STROKE_TEXT_MODE 64
52#define FX_FILL_TEXT_MODE 128
53#define FX_ZEROAREA_FILL 256
54#define FXFILL_NOPATHSMOOTH 512
55
56#define FXTEXT_CLEARTYPE 0x01
57#define FXTEXT_BGR_STRIPE 0x02
58#define FXTEXT_PRINTGRAPHICTEXT 0x04
59#define FXTEXT_NO_NATIVETEXT 0x08
60#define FXTEXT_PRINTIMAGETEXT 0x10
61#define FXTEXT_NOSMOOTH 0x20
62
63enum class FXPT_TYPE : uint8_t { LineTo, BezierTo, MoveTo };
64
65class FXTEXT_CHARPOS {
66 public:
67  FXTEXT_CHARPOS();
68  FXTEXT_CHARPOS(const FXTEXT_CHARPOS&);
69  ~FXTEXT_CHARPOS();
70
71  FX_FLOAT m_AdjustMatrix[4];
72  CFX_PointF m_Origin;
73  uint32_t m_GlyphIndex;
74  int32_t m_FontCharWidth;
75#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
76  uint32_t m_ExtGID;
77#endif
78  int32_t m_FallbackFontPosition;
79  bool m_bGlyphAdjust;
80  bool m_bFontStyle;
81};
82
83class CFX_RenderDevice {
84 public:
85  CFX_RenderDevice();
86  virtual ~CFX_RenderDevice();
87
88  // Take ownership of |pDriver|.
89  void SetDeviceDriver(std::unique_ptr<IFX_RenderDeviceDriver> pDriver);
90  IFX_RenderDeviceDriver* GetDeviceDriver() const {
91    return m_pDeviceDriver.get();
92  }
93
94  void SaveState();
95  void RestoreState(bool bKeepSaved);
96
97  int GetWidth() const { return m_Width; }
98  int GetHeight() const { return m_Height; }
99  int GetDeviceClass() const { return m_DeviceClass; }
100  int GetRenderCaps() const { return m_RenderCaps; }
101  int GetDeviceCaps(int id) const;
102  CFX_Matrix GetCTM() const;
103  CFX_DIBitmap* GetBitmap() const { return m_pBitmap; }
104  void SetBitmap(CFX_DIBitmap* pBitmap) { m_pBitmap = pBitmap; }
105  bool CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const;
106  const FX_RECT& GetClipBox() const { return m_ClipBox; }
107  bool SetClip_PathFill(const CFX_PathData* pPathData,
108                        const CFX_Matrix* pObject2Device,
109                        int fill_mode);
110  bool SetClip_Rect(const FX_RECT& pRect);
111  bool SetClip_PathStroke(const CFX_PathData* pPathData,
112                          const CFX_Matrix* pObject2Device,
113                          const CFX_GraphStateData* pGraphState);
114  bool DrawPath(const CFX_PathData* pPathData,
115                const CFX_Matrix* pObject2Device,
116                const CFX_GraphStateData* pGraphState,
117                uint32_t fill_color,
118                uint32_t stroke_color,
119                int fill_mode) {
120    return DrawPathWithBlend(pPathData, pObject2Device, pGraphState, fill_color,
121                             stroke_color, fill_mode, FXDIB_BLEND_NORMAL);
122  }
123  bool DrawPathWithBlend(const CFX_PathData* pPathData,
124                         const CFX_Matrix* pObject2Device,
125                         const CFX_GraphStateData* pGraphState,
126                         uint32_t fill_color,
127                         uint32_t stroke_color,
128                         int fill_mode,
129                         int blend_type);
130  bool SetPixel(int x, int y, uint32_t color);
131  bool FillRect(const FX_RECT* pRect, uint32_t color) {
132    return FillRectWithBlend(pRect, color, FXDIB_BLEND_NORMAL);
133  }
134  bool FillRectWithBlend(const FX_RECT* pRect, uint32_t color, int blend_type);
135  bool DrawCosmeticLine(FX_FLOAT x1,
136                        FX_FLOAT y1,
137                        FX_FLOAT x2,
138                        FX_FLOAT y2,
139                        uint32_t color,
140                        int fill_mode,
141                        int blend_type);
142
143  bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
144  CFX_DIBitmap* GetBackDrop();
145  bool SetDIBits(const CFX_DIBSource* pBitmap, int left, int top) {
146    return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL);
147  }
148  bool SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
149                          int left,
150                          int top,
151                          int blend_type);
152  bool StretchDIBits(const CFX_DIBSource* pBitmap,
153                     int left,
154                     int top,
155                     int dest_width,
156                     int dest_height) {
157    return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width,
158                                          dest_height, 0, FXDIB_BLEND_NORMAL);
159  }
160  bool StretchDIBitsWithFlagsAndBlend(const CFX_DIBSource* pBitmap,
161                                      int left,
162                                      int top,
163                                      int dest_width,
164                                      int dest_height,
165                                      uint32_t flags,
166                                      int blend_type);
167  bool SetBitMask(const CFX_DIBSource* pBitmap,
168                  int left,
169                  int top,
170                  uint32_t color);
171  bool StretchBitMask(const CFX_DIBSource* pBitmap,
172                      int left,
173                      int top,
174                      int dest_width,
175                      int dest_height,
176                      uint32_t color);
177  bool StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
178                               int left,
179                               int top,
180                               int dest_width,
181                               int dest_height,
182                               uint32_t color,
183                               uint32_t flags);
184  bool StartDIBits(const CFX_DIBSource* pBitmap,
185                   int bitmap_alpha,
186                   uint32_t color,
187                   const CFX_Matrix* pMatrix,
188                   uint32_t flags,
189                   void*& handle) {
190    return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, pMatrix, flags,
191                                handle, FXDIB_BLEND_NORMAL);
192  }
193  bool StartDIBitsWithBlend(const CFX_DIBSource* pBitmap,
194                            int bitmap_alpha,
195                            uint32_t color,
196                            const CFX_Matrix* pMatrix,
197                            uint32_t flags,
198                            void*& handle,
199                            int blend_type);
200  bool ContinueDIBits(void* handle, IFX_Pause* pPause);
201  void CancelDIBits(void* handle);
202
203  bool DrawNormalText(int nChars,
204                      const FXTEXT_CHARPOS* pCharPos,
205                      CFX_Font* pFont,
206                      FX_FLOAT font_size,
207                      const CFX_Matrix* pText2Device,
208                      uint32_t fill_color,
209                      uint32_t text_flags);
210  bool DrawTextPath(int nChars,
211                    const FXTEXT_CHARPOS* pCharPos,
212                    CFX_Font* pFont,
213                    FX_FLOAT font_size,
214                    const CFX_Matrix* pText2User,
215                    const CFX_Matrix* pUser2Device,
216                    const CFX_GraphStateData* pGraphState,
217                    uint32_t fill_color,
218                    uint32_t stroke_color,
219                    CFX_PathData* pClippingPath,
220                    int nFlag);
221
222#ifdef _SKIA_SUPPORT_
223  virtual void DebugVerifyBitmapIsPreMultiplied() const;
224  virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
225                               const CFX_DIBSource* pMask,
226                               int left,
227                               int top,
228                               int bitmap_alpha,
229                               int blend_type);
230#endif
231#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
232  void Flush();
233#endif
234
235 private:
236  void InitDeviceInfo();
237  void UpdateClipBox();
238  bool DrawFillStrokePath(const CFX_PathData* pPathData,
239                          const CFX_Matrix* pObject2Device,
240                          const CFX_GraphStateData* pGraphState,
241                          uint32_t fill_color,
242                          uint32_t stroke_color,
243                          int fill_mode,
244                          int blend_type);
245
246  CFX_DIBitmap* m_pBitmap;
247  int m_Width;
248  int m_Height;
249  int m_bpp;
250  int m_RenderCaps;
251  int m_DeviceClass;
252  FX_RECT m_ClipBox;
253  std::unique_ptr<IFX_RenderDeviceDriver> m_pDeviceDriver;
254};
255
256#endif  // CORE_FXGE_CFX_RENDERDEVICE_H_
257