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 SkCanvas; 17 18 class CFX_DefaultRenderDevice final : public CFX_RenderDevice { 19 public: 20 CFX_DefaultRenderDevice(); 21 ~CFX_DefaultRenderDevice() override; 22 23 bool Attach(RetainPtr<CFX_DIBitmap> pBitmap); 24 bool AttachWithRgbByteOrder(RetainPtr<CFX_DIBitmap> pBitmap, 25 bool bRgbByteOrder); 26 bool AttachWithBackdropAndGroupKnockout( 27 RetainPtr<CFX_DIBitmap> pBitmap, 28 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 29 bool bGroupKnockout); 30 #if defined(PDF_USE_SKIA) 31 [[nodiscard]] bool AttachCanvas(SkCanvas& canvas); 32 #endif 33 34 [[nodiscard]] bool Create(int width, int height, FXDIB_Format format); 35 [[nodiscard]] bool CreateWithBackdrop(int width, 36 int height, 37 FXDIB_Format format, 38 RetainPtr<CFX_DIBitmap> backdrop); 39 40 void Clear(uint32_t color); 41 42 // Runtime check to see if Skia is the renderer variant in use. 43 static bool UseSkiaRenderer(); 44 45 #if defined(PDF_USE_SKIA) 46 // This internal definition of renderer types must stay updated with respect 47 // to the public definition of `FPDF_RENDERER_TYPE`, so that all public 48 // definition values can be mapped to a value in 49 // `CFX_DefaultRenderDevice::RendererType`. 50 enum class RendererType { 51 kAgg = 0, 52 kSkia = 1, 53 }; 54 55 // When Skia is enabled at compile time, this constant is assigned as the 56 // default value UseSkiaRenderer() returns. SetRendererType() may override it. 57 static constexpr RendererType kDefaultRenderer = RendererType::kSkia; 58 59 static void SetRendererType(RendererType renderer_type); 60 #endif // defined(PDF_USE_SKIA) 61 62 private: 63 bool AttachImpl(RetainPtr<CFX_DIBitmap> pBitmap, 64 bool bRgbByteOrder, 65 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 66 bool bGroupKnockout); 67 68 bool AttachAggImpl(RetainPtr<CFX_DIBitmap> pBitmap, 69 bool bRgbByteOrder, 70 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 71 bool bGroupKnockout); 72 73 bool CreateAgg(int width, 74 int height, 75 FXDIB_Format format, 76 RetainPtr<CFX_DIBitmap> pBackdropBitmap); 77 78 #if defined(PDF_USE_SKIA) 79 bool AttachSkiaImpl(RetainPtr<CFX_DIBitmap> pBitmap, 80 bool bRgbByteOrder, 81 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 82 bool bGroupKnockout); 83 84 bool CreateSkia(int width, 85 int height, 86 FXDIB_Format format, 87 RetainPtr<CFX_DIBitmap> pBackdropBitmap); 88 #endif 89 }; 90 91 #endif // CORE_FXGE_CFX_DEFAULTRENDERDEVICE_H_ 92