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 #ifndef CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_ 6 #define CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_ 7 8 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxge/cfx_pathdata.h" 14 #include "core/fxge/renderdevicedriver_iface.h" 15 16 class CFX_ClipRgn; 17 class SkCanvas; 18 class SkMatrix; 19 class SkPaint; 20 class SkPath; 21 class SkPictureRecorder; 22 class SkiaState; 23 class TextCharPos; 24 struct SkIRect; 25 26 class CFX_SkiaDeviceDriver final : public RenderDeviceDriverIface { 27 public: 28 CFX_SkiaDeviceDriver(const RetainPtr<CFX_DIBitmap>& pBitmap, 29 bool bRgbByteOrder, 30 const RetainPtr<CFX_DIBitmap>& pBackdropBitmap, 31 bool bGroupKnockout); 32 #ifdef _SKIA_SUPPORT_ 33 explicit CFX_SkiaDeviceDriver(SkPictureRecorder* recorder); 34 CFX_SkiaDeviceDriver(int size_x, int size_y); 35 #endif 36 ~CFX_SkiaDeviceDriver() override; 37 38 /** Options */ 39 DeviceType GetDeviceType() const override; 40 int GetDeviceCaps(int caps_id) const override; 41 42 /** Save and restore all graphic states */ 43 void SaveState() override; 44 void RestoreState(bool bKeepSaved) override; 45 46 /** Set clipping path using filled region */ 47 bool SetClip_PathFill( 48 const CFX_PathData* pPathData, // path info 49 const CFX_Matrix* pObject2Device, // optional transformation 50 int fill_mode) override; // fill mode, WINDING or ALTERNATE 51 52 /** Set clipping path using stroked region */ 53 bool SetClip_PathStroke( 54 const CFX_PathData* pPathData, // path info 55 const CFX_Matrix* pObject2Device, // required transformation 56 const CFX_GraphStateData* 57 pGraphState) // graphic state, for pen attributes 58 override; 59 60 /** Draw a path */ 61 bool DrawPath(const CFX_PathData* pPathData, 62 const CFX_Matrix* pObject2Device, 63 const CFX_GraphStateData* pGraphState, 64 uint32_t fill_color, 65 uint32_t stroke_color, 66 int fill_mode, 67 BlendMode blend_type) override; 68 69 bool FillRectWithBlend(const FX_RECT& rect, 70 uint32_t fill_color, 71 BlendMode blend_type) override; 72 73 /** Draw a single pixel (device dependant) line */ 74 bool DrawCosmeticLine(const CFX_PointF& ptMoveTo, 75 const CFX_PointF& ptLineTo, 76 uint32_t color, 77 BlendMode blend_type) override; 78 79 bool GetClipBox(FX_RECT* pRect) override; 80 81 /** Load device buffer into a DIB */ 82 bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap, 83 int left, 84 int top) override; 85 86 RetainPtr<CFX_DIBitmap> GetBackDrop() override; 87 88 bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, 89 uint32_t color, 90 const FX_RECT& src_rect, 91 int dest_left, 92 int dest_top, 93 BlendMode blend_type) override; 94 #ifdef _SKIA_SUPPORT_ 95 bool SetBitsWithMask(const RetainPtr<CFX_DIBBase>& pBitmap, 96 const RetainPtr<CFX_DIBBase>& pMask, 97 int dest_left, 98 int dest_top, 99 int bitmap_alpha, 100 BlendMode blend_type) override; 101 #endif 102 103 #ifdef _SKIA_SUPPORT_PATHS_ 104 void SetClipMask(const FX_RECT& clipBox, const SkPath& skClipPath); 105 #endif 106 107 bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, 108 uint32_t color, 109 int dest_left, 110 int dest_top, 111 int dest_width, 112 int dest_height, 113 const FX_RECT* pClipRect, 114 const FXDIB_ResampleOptions& options, 115 BlendMode blend_type) override; 116 117 bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, 118 int bitmap_alpha, 119 uint32_t color, 120 const CFX_Matrix& matrix, 121 const FXDIB_ResampleOptions& options, 122 std::unique_ptr<CFX_ImageRenderer>* handle, 123 BlendMode blend_type) override; 124 125 bool ContinueDIBits(CFX_ImageRenderer* handle, 126 PauseIndicatorIface* pPause) override; 127 128 bool DrawBitsWithMask(const RetainPtr<CFX_DIBBase>& pBitmap, 129 const RetainPtr<CFX_DIBBase>& pMask, 130 int bitmap_alpha, 131 const CFX_Matrix& matrix, 132 BlendMode blend_type); 133 134 bool DrawDeviceText(int nChars, 135 const TextCharPos* pCharPos, 136 CFX_Font* pFont, 137 const CFX_Matrix& mtObject2Device, 138 float font_size, 139 uint32_t color) override; 140 141 int GetDriverType() const override; 142 143 bool DrawShading(const CPDF_ShadingPattern* pPattern, 144 const CFX_Matrix* pMatrix, 145 const FX_RECT& clip_rect, 146 int alpha, 147 bool bAlphaMode) override; 148 149 virtual uint8_t* GetBuffer() const; 150 151 void PaintStroke(SkPaint* spaint, 152 const CFX_GraphStateData* pGraphState, 153 const SkMatrix& matrix); 154 void Clear(uint32_t color); 155 void Flush() override; GetRecorder()156 SkPictureRecorder* GetRecorder() const { return m_pRecorder; } 157 void PreMultiply(); 158 static void PreMultiply(const RetainPtr<CFX_DIBitmap>& pDIBitmap); SkiaCanvas()159 SkCanvas* SkiaCanvas() { return m_pCanvas; } 160 void DebugVerifyBitmapIsPreMultiplied() const; 161 void Dump() const; 162 GetGroupKnockout()163 bool GetGroupKnockout() const { return m_bGroupKnockout; } 164 165 #ifdef _SKIA_SUPPORT_PATHS_ clip_region()166 const CFX_ClipRgn* clip_region() const { return m_pClipRgn.get(); } stack()167 const std::vector<std::unique_ptr<CFX_ClipRgn>>& stack() const { 168 return m_StateStack; 169 } 170 #endif 171 172 private: 173 RetainPtr<CFX_DIBitmap> m_pBitmap; 174 RetainPtr<CFX_DIBitmap> m_pBackdropBitmap; 175 SkCanvas* m_pCanvas; 176 SkPictureRecorder* const m_pRecorder; 177 std::unique_ptr<SkiaState> m_pCache; 178 #ifdef _SKIA_SUPPORT_PATHS_ 179 std::unique_ptr<CFX_ClipRgn> m_pClipRgn; 180 std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack; 181 int m_FillFlags; 182 bool m_bRgbByteOrder; 183 #endif 184 bool m_bGroupKnockout; 185 }; 186 #endif // defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ 187 188 #endif // CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_ 189