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