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