• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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_RENDERDEVICEDRIVER_IFACE_H_
8 #define CORE_FXGE_RENDERDEVICEDRIVER_IFACE_H_
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 
14 #include "build/build_config.h"
15 #include "core/fxcrt/fx_coordinates.h"
16 #include "core/fxcrt/retain_ptr.h"
17 #include "core/fxcrt/span.h"
18 #include "core/fxge/dib/fx_dib.h"
19 
20 class CFX_AggImageRenderer;
21 class CFX_DIBBase;
22 class CFX_DIBitmap;
23 class CFX_Font;
24 class CFX_GraphStateData;
25 class CFX_Matrix;
26 class CFX_Path;
27 class CPDF_ShadingPattern;
28 class PauseIndicatorIface;
29 class TextCharPos;
30 struct CFX_FillRenderOptions;
31 struct CFX_TextRenderOptions;
32 struct FX_RECT;
33 
34 enum class DeviceType : bool {
35   kDisplay,
36 #if BUILDFLAG(IS_WIN)
37   kPrinter,
38 #endif
39 };
40 
41 class RenderDeviceDriverIface {
42  public:
43   enum class Result {
44     kFailure,
45     kSuccess,
46 #if BUILDFLAG(IS_WIN)
47     kNotSupported
48 #endif
49   };
50 
51   struct StartResult {
52     StartResult(Result result,
53                 std::unique_ptr<CFX_AggImageRenderer> agg_image_renderer);
54     ~StartResult();
55 
56     const Result result;
57     std::unique_ptr<CFX_AggImageRenderer> agg_image_renderer;
58   };
59 
60   virtual ~RenderDeviceDriverIface();
61 
62   virtual DeviceType GetDeviceType() const = 0;
63   virtual int GetDeviceCaps(int caps_id) const = 0;
64 
65   virtual void SaveState() = 0;
66   virtual void RestoreState(bool bKeepSaved) = 0;
67 
68   virtual void SetBaseClip(const FX_RECT& rect);
69   virtual bool SetClip_PathFill(const CFX_Path& path,
70                                 const CFX_Matrix* pObject2Device,
71                                 const CFX_FillRenderOptions& fill_options) = 0;
72   virtual bool SetClip_PathStroke(const CFX_Path& path,
73                                   const CFX_Matrix* pObject2Device,
74                                   const CFX_GraphStateData* pGraphState);
75   virtual bool DrawPath(const CFX_Path& path,
76                         const CFX_Matrix* pObject2Device,
77                         const CFX_GraphStateData* pGraphState,
78                         uint32_t fill_color,
79                         uint32_t stroke_color,
80                         const CFX_FillRenderOptions& fill_options) = 0;
81   virtual bool FillRect(const FX_RECT& rect, uint32_t fill_color);
82   virtual bool DrawCosmeticLine(const CFX_PointF& ptMoveTo,
83                                 const CFX_PointF& ptLineTo,
84                                 uint32_t color);
85 
86   virtual FX_RECT GetClipBox() const = 0;
87   virtual bool GetDIBits(RetainPtr<CFX_DIBitmap> bitmap,
88                          int left,
89                          int top) const;
90   virtual RetainPtr<const CFX_DIBitmap> GetBackDrop() const;
91   virtual bool SetDIBits(RetainPtr<const CFX_DIBBase> bitmap,
92                          uint32_t color,
93                          const FX_RECT& src_rect,
94                          int dest_left,
95                          int dest_top,
96                          BlendMode blend_type) = 0;
97   virtual bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
98                              uint32_t color,
99                              int dest_left,
100                              int dest_top,
101                              int dest_width,
102                              int dest_height,
103                              const FX_RECT* pClipRect,
104                              const FXDIB_ResampleOptions& options,
105                              BlendMode blend_type) = 0;
106   virtual StartResult StartDIBits(RetainPtr<const CFX_DIBBase> bitmap,
107                                   float alpha,
108                                   uint32_t color,
109                                   const CFX_Matrix& matrix,
110                                   const FXDIB_ResampleOptions& options,
111                                   BlendMode blend_type) = 0;
112   virtual bool ContinueDIBits(CFX_AggImageRenderer* handle,
113                               PauseIndicatorIface* pPause);
114   virtual bool DrawDeviceText(pdfium::span<const TextCharPos> pCharPos,
115                               CFX_Font* pFont,
116                               const CFX_Matrix& mtObject2Device,
117                               float font_size,
118                               uint32_t color,
119                               const CFX_TextRenderOptions& options);
120   virtual int GetDriverType() const;
121 #if defined(PDF_USE_SKIA)
122   virtual bool DrawShading(const CPDF_ShadingPattern& pattern,
123                            const CFX_Matrix& matrix,
124                            const FX_RECT& clip_rect,
125                            int alpha);
126   virtual bool SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
127                                RetainPtr<const CFX_DIBBase> mask,
128                                int left,
129                                int top,
130                                float alpha,
131                                BlendMode blend_type);
132   virtual void SetGroupKnockout(bool group_knockout);
133 
134   // For `CFX_SkiaDeviceDriver` only:
135   // Syncs the current rendering result from the internal buffer to the output
136   // bitmap if such internal buffer exists.
137   virtual void SyncInternalBitmaps();
138 #endif  // defined(PDF_USE_SKIA)
139 
140   // Multiplies the device by a constant alpha, returning `true` on success.
141   // Implementations CHECK the following conditions:
142   // - `this` is bitmap-based and `this` is not of a mask format.
143   //
144   // The backing bitmap for `this` will be converted to format
145   // `FXDIB_Format::kBgra` on success when `alpha` is not 1.
146   virtual bool MultiplyAlpha(float alpha) = 0;
147 
148   // Multiplies the device by an alpha mask, returning `true` on success.
149   // Implementations CHECK the following conditions:
150   // - `this` is bitmap-based and of format `FXDIB_Format::kBgra` or
151   //   `FXDIB_Format::kBgrx`.
152   // - `mask` must be of format `FXDIB_Format::k8bppMask`.
153   // - `mask` must have the same dimensions as `this`.
154   //
155   // The backing bitmap for `this` will be converted to format
156   // `FXDIB_Format::kBgra` on success.
157   virtual bool MultiplyAlphaMask(RetainPtr<const CFX_DIBitmap> mask) = 0;
158 };
159 
160 #endif  // CORE_FXGE_RENDERDEVICEDRIVER_IFACE_H_
161