• 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_CFX_DEFAULTRENDERDEVICE_H_
8 #define CORE_FXGE_CFX_DEFAULTRENDERDEVICE_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/retain_ptr.h"
13 #include "core/fxge/cfx_renderdevice.h"
14 #include "core/fxge/dib/fx_dib.h"
15 
16 class SkPictureRecorder;
17 struct SkRect;
18 
19 class CFX_DefaultRenderDevice final : public CFX_RenderDevice {
20  public:
21   CFX_DefaultRenderDevice();
22   ~CFX_DefaultRenderDevice() override;
23 
24   bool Attach(RetainPtr<CFX_DIBitmap> pBitmap);
25   bool AttachWithRgbByteOrder(RetainPtr<CFX_DIBitmap> pBitmap,
26                               bool bRgbByteOrder);
27   bool AttachWithBackdropAndGroupKnockout(
28       RetainPtr<CFX_DIBitmap> pBitmap,
29       RetainPtr<CFX_DIBitmap> pBackdropBitmap,
30       bool bGroupKnockout);
31   bool Create(int width,
32               int height,
33               FXDIB_Format format,
34               RetainPtr<CFX_DIBitmap> pBackdropBitmap);
35 
36 #if defined(_SKIA_SUPPORT_)
37   bool AttachRecorder(SkPictureRecorder* recorder);
38   void Clear(uint32_t color);
39   std::unique_ptr<SkPictureRecorder> CreateRecorder(const SkRect& bounds);
40   bool SetBitsWithMask(const RetainPtr<CFX_DIBBase>& pBitmap,
41                        const RetainPtr<CFX_DIBBase>& pMask,
42                        int left,
43                        int top,
44                        int bitmap_alpha,
45                        BlendMode blend_type) override;
46 #endif
47 
48   // Runtime check to see if Skia is the renderer variant in use.
49   static bool SkiaIsDefaultRenderer();
50 
51 #if defined(_SKIA_SUPPORT_)
52   // This internal definition of renderer types must stay updated with respect
53   // to the public definition of `FPDF_RENDERER_TYPE`, so that all public
54   // definition values can be mapped to a value in
55   // `CFX_DefaultRenderDevice::RendererType`.
56   enum class RendererType {
57     kAgg = 0,
58     kSkia = 1,
59   };
60 
61   // Update default renderer.
62   static void SetDefaultRenderer(RendererType renderer_type);
63 #endif  // defined(_SKIA_SUPPORT_)
64 
65  private:
66   bool AttachImpl(RetainPtr<CFX_DIBitmap> pBitmap,
67                   bool bRgbByteOrder,
68                   RetainPtr<CFX_DIBitmap> pBackdropBitmap,
69                   bool bGroupKnockout);
70 
71   bool AttachAggImpl(RetainPtr<CFX_DIBitmap> pBitmap,
72                      bool bRgbByteOrder,
73                      RetainPtr<CFX_DIBitmap> pBackdropBitmap,
74                      bool bGroupKnockout);
75 
76   bool CreateAgg(int width,
77                  int height,
78                  FXDIB_Format format,
79                  RetainPtr<CFX_DIBitmap> pBackdropBitmap);
80 
81 #if defined(_SKIA_SUPPORT_)
82   bool AttachSkiaImpl(RetainPtr<CFX_DIBitmap> pBitmap,
83                       bool bRgbByteOrder,
84                       RetainPtr<CFX_DIBitmap> pBackdropBitmap,
85                       bool bGroupKnockout);
86 
87   bool CreateSkia(int width,
88                   int height,
89                   FXDIB_Format format,
90                   RetainPtr<CFX_DIBitmap> pBackdropBitmap);
91 #endif
92 };
93 
94 #endif  // CORE_FXGE_CFX_DEFAULTRENDERDEVICE_H_
95