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 bool Create(int width, 31 int height, 32 FXDIB_Format format, 33 RetainPtr<CFX_DIBitmap> pBackdropBitmap); 34 35 #if defined(_SKIA_SUPPORT_) 36 bool AttachCanvas(SkCanvas* canvas); 37 void Clear(uint32_t color); 38 #endif 39 40 // Runtime check to see if Skia is the renderer variant in use. 41 static bool SkiaIsDefaultRenderer(); 42 43 #if defined(_SKIA_SUPPORT_) 44 // This internal definition of renderer types must stay updated with respect 45 // to the public definition of `FPDF_RENDERER_TYPE`, so that all public 46 // definition values can be mapped to a value in 47 // `CFX_DefaultRenderDevice::RendererType`. 48 enum class RendererType { 49 kAgg = 0, 50 kSkia = 1, 51 }; 52 53 // Update default renderer. 54 static void SetDefaultRenderer(RendererType renderer_type); 55 #endif // defined(_SKIA_SUPPORT_) 56 57 private: 58 bool AttachImpl(RetainPtr<CFX_DIBitmap> pBitmap, 59 bool bRgbByteOrder, 60 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 61 bool bGroupKnockout); 62 63 bool AttachAggImpl(RetainPtr<CFX_DIBitmap> pBitmap, 64 bool bRgbByteOrder, 65 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 66 bool bGroupKnockout); 67 68 bool CreateAgg(int width, 69 int height, 70 FXDIB_Format format, 71 RetainPtr<CFX_DIBitmap> pBackdropBitmap); 72 73 #if defined(_SKIA_SUPPORT_) 74 bool AttachSkiaImpl(RetainPtr<CFX_DIBitmap> pBitmap, 75 bool bRgbByteOrder, 76 RetainPtr<CFX_DIBitmap> pBackdropBitmap, 77 bool bGroupKnockout); 78 79 bool CreateSkia(int width, 80 int height, 81 FXDIB_Format format, 82 RetainPtr<CFX_DIBitmap> pBackdropBitmap); 83 #endif 84 }; 85 86 #endif // CORE_FXGE_CFX_DEFAULTRENDERDEVICE_H_ 87