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