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