Home | History | Annotate | Download | only in skia
      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(const RetainPtr<CFX_DIBitmap>& pBitmap,
     28                        bool bRgbByteOrder,
     29                        const RetainPtr<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(const CFX_PointF& ptMoveTo,
     73                         const CFX_PointF& ptLineTo,
     74                         uint32_t color,
     75                         int blend_type) override;
     76 
     77   bool GetClipBox(FX_RECT* pRect) override;
     78 
     79   /** Load device buffer into a DIB */
     80   bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
     81                  int left,
     82                  int top) override;
     83 
     84   RetainPtr<CFX_DIBitmap> GetBackDrop() override;
     85 
     86   bool SetDIBits(const RetainPtr<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 RetainPtr<CFX_DIBSource>& pBitmap,
     94                        const RetainPtr<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 RetainPtr<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 RetainPtr<CFX_DIBSource>& pBitmap,
    116                    int bitmap_alpha,
    117                    uint32_t color,
    118                    const CFX_Matrix* pMatrix,
    119                    uint32_t flags,
    120                    std::unique_ptr<CFX_ImageRenderer>* handle,
    121                    int blend_type) override;
    122 
    123   bool ContinueDIBits(CFX_ImageRenderer* handle,
    124                       IFX_PauseIndicator* pPause) override;
    125 
    126   bool DrawBitsWithMask(const RetainPtr<CFX_DIBSource>& pBitmap,
    127                         const RetainPtr<CFX_DIBSource>& pMask,
    128                         int bitmap_alpha,
    129                         const CFX_Matrix* pMatrix,
    130                         int blend_type);
    131 
    132   bool DrawDeviceText(int nChars,
    133                       const FXTEXT_CHARPOS* pCharPos,
    134                       CFX_Font* pFont,
    135                       const CFX_Matrix* pObject2Device,
    136                       float font_size,
    137                       uint32_t color) override;
    138 
    139   bool DrawShading(const CPDF_ShadingPattern* pPattern,
    140                    const CFX_Matrix* pMatrix,
    141                    const FX_RECT& clip_rect,
    142                    int alpha,
    143                    bool bAlphaMode) override;
    144 
    145   virtual uint8_t* GetBuffer() const;
    146 
    147   void PaintStroke(SkPaint* spaint,
    148                    const CFX_GraphStateData* pGraphState,
    149                    const SkMatrix& matrix);
    150   void Clear(uint32_t color);
    151   void Flush() override;
    152   SkPictureRecorder* GetRecorder() const { return m_pRecorder; }
    153   void PreMultiply();
    154   static void PreMultiply(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
    155   SkCanvas* SkiaCanvas() { return m_pCanvas; }
    156   void DebugVerifyBitmapIsPreMultiplied() const;
    157   void Dump() const;
    158 
    159   bool GetGroupKnockout() const { return m_bGroupKnockout; }
    160 
    161  private:
    162   RetainPtr<CFX_DIBitmap> m_pBitmap;
    163   RetainPtr<CFX_DIBitmap> m_pOriDevice;
    164   SkCanvas* m_pCanvas;
    165   SkPictureRecorder* const m_pRecorder;
    166   std::unique_ptr<SkiaState> m_pCache;
    167 #ifdef _SKIA_SUPPORT_PATHS_
    168   std::unique_ptr<CFX_ClipRgn> m_pClipRgn;
    169   std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack;
    170   int m_FillFlags;
    171   bool m_bRgbByteOrder;
    172 #endif
    173   bool m_bGroupKnockout;
    174 };
    175 #endif  // defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
    176 
    177 #endif  // CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_
    178