• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_AGG_FX_AGG_DRIVER_H_
8 #define CORE_FXGE_AGG_FX_AGG_DRIVER_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "build/build_config.h"
14 #include "core/fxcrt/retain_ptr.h"
15 #include "core/fxge/cfx_fillrenderoptions.h"
16 #include "core/fxge/renderdevicedriver_iface.h"
17 
18 class CFX_ClipRgn;
19 class CFX_GraphStateData;
20 class CFX_Matrix;
21 class CFX_Path;
22 
23 namespace pdfium {
24 
25 namespace agg {
26 class rasterizer_scanline_aa;
27 }  // namespace agg
28 
29 class CFX_AggDeviceDriver final : public RenderDeviceDriverIface {
30  public:
31   CFX_AggDeviceDriver(RetainPtr<CFX_DIBitmap> pBitmap,
32                       bool bRgbByteOrder,
33                       RetainPtr<CFX_DIBitmap> pBackdropBitmap,
34                       bool bGroupKnockout);
35   ~CFX_AggDeviceDriver() override;
36 
37   void InitPlatform();
38   void DestroyPlatform();
39 
40   // RenderDeviceDriverIface:
41   DeviceType GetDeviceType() const override;
42   int GetDeviceCaps(int caps_id) const override;
43   void SaveState() override;
44   void RestoreState(bool bKeepSaved) override;
45   bool SetClip_PathFill(const CFX_Path& path,
46                         const CFX_Matrix* pObject2Device,
47                         const CFX_FillRenderOptions& fill_options) override;
48   bool SetClip_PathStroke(const CFX_Path& path,
49                           const CFX_Matrix* pObject2Device,
50                           const CFX_GraphStateData* pGraphState) override;
51   bool DrawPath(const CFX_Path& path,
52                 const CFX_Matrix* pObject2Device,
53                 const CFX_GraphStateData* pGraphState,
54                 uint32_t fill_color,
55                 uint32_t stroke_color,
56                 const CFX_FillRenderOptions& fill_options,
57                 BlendMode blend_type) override;
58   bool FillRectWithBlend(const FX_RECT& rect,
59                          uint32_t fill_color,
60                          BlendMode blend_type) override;
61   bool GetClipBox(FX_RECT* pRect) override;
62   bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
63                  int left,
64                  int top) override;
65   RetainPtr<CFX_DIBitmap> GetBackDrop() override;
66   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
67                  uint32_t argb,
68                  const FX_RECT& src_rect,
69                  int left,
70                  int top,
71                  BlendMode blend_type) override;
72   bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource,
73                      uint32_t argb,
74                      int dest_left,
75                      int dest_top,
76                      int dest_width,
77                      int dest_height,
78                      const FX_RECT* pClipRect,
79                      const FXDIB_ResampleOptions& options,
80                      BlendMode blend_type) override;
81   bool StartDIBits(const RetainPtr<CFX_DIBBase>& pSource,
82                    int bitmap_alpha,
83                    uint32_t argb,
84                    const CFX_Matrix& matrix,
85                    const FXDIB_ResampleOptions& options,
86                    std::unique_ptr<CFX_ImageRenderer>* handle,
87                    BlendMode blend_type) override;
88   bool ContinueDIBits(CFX_ImageRenderer* handle,
89                       PauseIndicatorIface* pPause) override;
90   bool DrawDeviceText(pdfium::span<const TextCharPos> pCharPos,
91                       CFX_Font* pFont,
92                       const CFX_Matrix& mtObject2Device,
93                       float font_size,
94                       uint32_t color,
95                       const CFX_TextRenderOptions& options) override;
96   int GetDriverType() const override;
97   bool MultiplyAlpha(float alpha) override;
98   bool MultiplyAlpha(const RetainPtr<CFX_DIBBase>& mask) override;
99 
100  private:
101   void RenderRasterizer(pdfium::agg::rasterizer_scanline_aa& rasterizer,
102                         uint32_t color,
103                         bool bFullCover,
104                         bool bGroupKnockout);
105 
106   void SetClipMask(pdfium::agg::rasterizer_scanline_aa& rasterizer);
107 
108   RetainPtr<CFX_DIBitmap> const m_pBitmap;
109   std::unique_ptr<CFX_ClipRgn> m_pClipRgn;
110   std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack;
111 #if BUILDFLAG(IS_APPLE)
112   void* m_pPlatformGraphics = nullptr;
113 #endif
114   CFX_FillRenderOptions m_FillOptions;
115   const bool m_bRgbByteOrder;
116   const bool m_bGroupKnockout;
117   RetainPtr<CFX_DIBitmap> m_pBackdropBitmap;
118 };
119 
120 }  // namespace pdfium
121 
122 #endif  // CORE_FXGE_AGG_FX_AGG_DRIVER_H_
123