Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fx_skia_device.h
Go to the documentation of this file.
1// Copyright 2014 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#ifndef CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_
6#define CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_
7
8#include <stdint.h>
9
10#include <memory>
11
12#include "core/fxcrt/data_vector.h"
13#include "core/fxcrt/fx_memory_wrappers.h"
14#include "core/fxcrt/retain_ptr.h"
15#include "core/fxcrt/unowned_ptr.h"
16#include "core/fxge/cfx_fillrenderoptions.h"
17#include "core/fxge/cfx_path.h"
18#include "core/fxge/renderdevicedriver_iface.h"
19#include "third_party/base/check_op.h"
20#include "third_party/base/containers/span.h"
21#include "third_party/skia/include/core/SkPoint.h"
22#include "third_party/skia/include/core/SkRSXform.h"
23#include "third_party/skia/include/core/SkRefCnt.h"
24
25class CFX_Font;
26class CFX_Matrix;
27class SkCanvas;
28class SkSurface;
29class TextCharPos;
31
32// Assumes Skia is not going to add non-data members to its fundamental types.
35
36class CFX_SkiaDeviceDriver final : public RenderDeviceDriverIface {
37 public:
39 RetainPtr<CFX_DIBitmap> pBitmap,
40 bool bRgbByteOrder,
41 RetainPtr<CFX_DIBitmap> pBackdropBitmap,
42 bool bGroupKnockout);
43 static std::unique_ptr<CFX_SkiaDeviceDriver> Create(SkCanvas* canvas);
44
45 ~CFX_SkiaDeviceDriver() override;
46
47 /** Options */
48 DeviceType GetDeviceType() const override;
49 int GetDeviceCaps(int caps_id) const override;
50
51 /** Save and restore all graphic states */
52 void SaveState() override;
53 void RestoreState(bool bKeepSaved) override;
54
55 /** Set clipping path using filled region */
57 const CFX_Path& path, // path info
58 const CFX_Matrix* pObject2Device, // optional transformation
59 const CFX_FillRenderOptions& fill_options) // fill options
60 override;
61
62 /** Set clipping path using stroked region */
64 const CFX_Path& path, // path info
65 const CFX_Matrix* pObject2Device, // required transformation
67 pGraphState) // graphic state, for pen attributes
68 override;
69
70 /** Draw a path */
71 bool DrawPath(const CFX_Path& path,
72 const CFX_Matrix* pObject2Device,
73 const CFX_GraphStateData* pGraphState,
74 uint32_t fill_color,
75 uint32_t stroke_color,
76 const CFX_FillRenderOptions& fill_options,
77 BlendMode blend_type) override;
78
79 bool FillRectWithBlend(const FX_RECT& rect,
80 uint32_t fill_color,
81 BlendMode blend_type) override;
82
83 /** Draw a single pixel (device dependant) line */
84 bool DrawCosmeticLine(const CFX_PointF& ptMoveTo,
85 const CFX_PointF& ptLineTo,
86 uint32_t color,
87 BlendMode blend_type) override;
88
89 bool GetClipBox(FX_RECT* pRect) override;
90
91 /** Load device buffer into a DIB */
92 bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
93 int left,
94 int top) override;
95
96 RetainPtr<CFX_DIBitmap> GetBackDrop() override;
97
98 bool SetDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
99 uint32_t color,
100 const FX_RECT& src_rect,
101 int dest_left,
102 int dest_top,
103 BlendMode blend_type) override;
104 bool SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
105 RetainPtr<const CFX_DIBBase> mask,
106 int dest_left,
107 int dest_top,
108 float alpha,
109 BlendMode blend_type) override;
110 void SetGroupKnockout(bool group_knockout) override;
112
113 bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
114 uint32_t color,
115 int dest_left,
116 int dest_top,
117 int dest_width,
118 int dest_height,
119 const FX_RECT* pClipRect,
120 const FXDIB_ResampleOptions& options,
121 BlendMode blend_type) override;
122
123 bool StartDIBits(RetainPtr<const CFX_DIBBase> bitmap,
124 float alpha,
125 uint32_t color,
126 const CFX_Matrix& matrix,
127 const FXDIB_ResampleOptions& options,
128 std::unique_ptr<CFX_ImageRenderer>* handle,
129 BlendMode blend_type) override;
130
132 PauseIndicatorIface* pPause) override;
133
134 bool DrawBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
135 RetainPtr<const CFX_DIBBase> mask,
136 float alpha,
137 const CFX_Matrix& matrix,
138 BlendMode blend_type);
139
140 bool DrawDeviceText(pdfium::span<const TextCharPos> pCharPos,
141 CFX_Font* pFont,
142 const CFX_Matrix& mtObject2Device,
143 float font_size,
144 uint32_t color,
145 const CFX_TextRenderOptions& options) override;
146
147 int GetDriverType() const override;
148
149 bool DrawShading(const CPDF_ShadingPattern* pPattern,
150 const CFX_Matrix* pMatrix,
151 const FX_RECT& clip_rect,
152 int alpha,
153 bool bAlphaMode) override;
154
155 bool MultiplyAlpha(float alpha) override;
156 bool MultiplyAlphaMask(const RetainPtr<const CFX_DIBBase>& mask) override;
157
158 void Clear(uint32_t color);
159 void Dump() const;
160
161 private:
162 class CharDetail {
163 public:
164 CharDetail();
165 ~CharDetail();
166
167 const DataVector<SkPoint>& GetPositions() const { return m_positions; }
168 void SetPositionAt(size_t index, const SkPoint& position) {
169 m_positions[index] = position;
170 }
171 const DataVector<uint16_t>& GetGlyphs() const { return m_glyphs; }
172 void SetGlyphAt(size_t index, uint16_t glyph) { m_glyphs[index] = glyph; }
173 const DataVector<uint32_t>& GetFontCharWidths() const {
174 return m_fontCharWidths;
175 }
176 void SetFontCharWidthAt(size_t index, uint32_t width) {
177 m_fontCharWidths[index] = width;
178 }
179 size_t Count() const {
180 DCHECK_EQ(m_positions.size(), m_glyphs.size());
181 return m_glyphs.size();
182 }
183 void SetCount(size_t count) {
184 m_positions.resize(count);
185 m_glyphs.resize(count);
186 m_fontCharWidths.resize(count);
187 }
188
189 private:
190 DataVector<SkPoint> m_positions; // accumulator for text positions
191 DataVector<uint16_t> m_glyphs; // accumulator for text glyphs
192 // accumulator for glyphs' width defined in pdf
193 DataVector<uint32_t> m_fontCharWidths;
194 };
195
196 // Use the public creation methods instead.
197 CFX_SkiaDeviceDriver(RetainPtr<CFX_DIBitmap> pBitmap,
198 bool bRgbByteOrder,
199 RetainPtr<CFX_DIBitmap> pBackdropBitmap,
200 bool bGroupKnockout);
201 explicit CFX_SkiaDeviceDriver(SkCanvas* canvas);
202
203 bool TryDrawText(pdfium::span<const TextCharPos> char_pos,
204 const CFX_Font* pFont,
205 const CFX_Matrix& matrix,
206 float font_size,
207 uint32_t color,
208 const CFX_TextRenderOptions& options);
209
210 bool StartDIBitsSkia(RetainPtr<const CFX_DIBBase> bitmap,
211 const FX_RECT& src_rect,
212 float alpha,
213 uint32_t color,
214 const CFX_Matrix& matrix,
215 const FXDIB_ResampleOptions& options,
216 BlendMode blend_type);
217
218 RetainPtr<CFX_DIBitmap> m_pBitmap;
219 RetainPtr<CFX_DIBitmap> m_pBackdropBitmap;
220
221 // The input bitmap passed by the render device. Only used when the input
222 // bitmap is 24 bpp and cannot be directly used as the back of a SkCanvas.
223 RetainPtr<CFX_DIBitmap> m_pOriginalBitmap;
224
225 sk_sp<SkSurface> surface_;
226 UnownedPtr<SkCanvas> m_pCanvas;
227 CFX_FillRenderOptions m_FillOptions;
228 bool m_bRgbByteOrder;
229 bool m_bGroupKnockout;
230
231 CharDetail m_charDetails;
232 // accumulator for txt rotate/scale/translate
233 DataVector<SkRSXform> m_rsxform;
234};
235
236#endif // CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_
uint32_t GetBits(uint32_t nBits)
uint32_t GetPitch() const
Definition cfx_dibbase.h:54
int GetHeight() const
Definition cfx_dibbase.h:53
int GetWidth() const
Definition cfx_dibbase.h:52
constexpr CFX_FloatRect(float l, float b, float r, float t)
void Intersect(const CFX_FloatRect &other_rect)
FX_RECT GetOuterRect() const
int GetSubstFontItalicAngle() const
Definition cfx_font.cpp:164
FXFT_FaceRec * GetFaceRec() const
Definition cfx_font.h:79
float GetXUnit() const
float GetYUnit() const
CFX_Matrix()=default
static CFX_Matrix GetFlipMatrix(float width, float height, float left, float top)
void SetBitmap(RetainPtr< CFX_DIBitmap > bitmap)
bool GetClipBox(FX_RECT *pRect) override
bool DrawBitsWithMask(RetainPtr< const CFX_DIBBase > bitmap, RetainPtr< const CFX_DIBBase > mask, float alpha, const CFX_Matrix &matrix, BlendMode blend_type)
bool StartDIBits(RetainPtr< const CFX_DIBBase > bitmap, float alpha, uint32_t color, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options, std::unique_ptr< CFX_ImageRenderer > *handle, BlendMode blend_type) override
bool DrawDeviceText(pdfium::span< const TextCharPos > pCharPos, CFX_Font *pFont, const CFX_Matrix &mtObject2Device, float font_size, uint32_t color, const CFX_TextRenderOptions &options) override
bool MultiplyAlpha(float alpha) override
void SetGroupKnockout(bool group_knockout) override
DeviceType GetDeviceType() const override
RetainPtr< CFX_DIBitmap > GetBackDrop() override
bool FillRectWithBlend(const FX_RECT &rect, uint32_t fill_color, BlendMode blend_type) override
bool SyncInternalBitmaps() override
void SaveState() override
bool SetClip_PathFill(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_FillRenderOptions &fill_options) override
bool ContinueDIBits(CFX_ImageRenderer *handle, PauseIndicatorIface *pPause) override
bool GetDIBits(const RetainPtr< CFX_DIBitmap > &pBitmap, int left, int top) override
static std::unique_ptr< CFX_SkiaDeviceDriver > Create(RetainPtr< CFX_DIBitmap > pBitmap, bool bRgbByteOrder, RetainPtr< CFX_DIBitmap > pBackdropBitmap, bool bGroupKnockout)
bool SetDIBits(const RetainPtr< const CFX_DIBBase > &pBitmap, uint32_t color, const FX_RECT &src_rect, int dest_left, int dest_top, BlendMode blend_type) override
bool MultiplyAlphaMask(const RetainPtr< const CFX_DIBBase > &mask) override
static std::unique_ptr< CFX_SkiaDeviceDriver > Create(SkCanvas *canvas)
int GetDriverType() const override
int GetDeviceCaps(int caps_id) const override
bool DrawCosmeticLine(const CFX_PointF &ptMoveTo, const CFX_PointF &ptLineTo, uint32_t color, BlendMode blend_type) override
bool StretchDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t color, int dest_left, int dest_top, int dest_width, int dest_height, const FX_RECT *pClipRect, const FXDIB_ResampleOptions &options, BlendMode blend_type) override
bool DrawShading(const CPDF_ShadingPattern *pPattern, const CFX_Matrix *pMatrix, const FX_RECT &clip_rect, int alpha, bool bAlphaMode) override
void RestoreState(bool bKeepSaved) override
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options, BlendMode blend_type) override
bool SetClip_PathStroke(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState) override
bool SetBitsWithMask(RetainPtr< const CFX_DIBBase > bitmap, RetainPtr< const CFX_DIBBase > mask, int dest_left, int dest_top, float alpha, BlendMode blend_type) override
void Clear(uint32_t color)
float GetExponent() const
uint32_t GetOrigOutputs() const
float GetRange(int i) const
uint32_t CountOutputs() const
float GetDomain(int i) const
uint32_t CountInputs() const
std::tuple< float, float, float > ReadColor()
uint32_t GetBitsPerSample() const
ShadingType GetShadingType() const
static bool UseInterpolateBilinear(const FXDIB_ResampleOptions &options, int dest_width, int dest_height, int src_width, int src_height)
float m_AdjustMatrix[4]
bool m_bGlyphAdjust
@ kRadialShading
@ kAxialShading
@ kCoonsPatchMeshShading
BlendMode
Definition fx_dib.h:49
#define FXARGB_A(argb)
Definition fx_dib.h:124
FXDIB_Format
Definition fx_dib.h:19
#define FX_DATA_PARTITION_EXCEPTION(T)
#define SHOW_SKIA_PATH
#define FXSYS_PI
Definition fx_system.h:43
#define CHECK(cvref)
#define FXDC_BITS_PIXEL
#define FXRC_FILLSTROKE_PATH
#define FXDC_RENDER_CAPS
#define FXDC_PIXEL_WIDTH
#define FXRC_ALPHA_OUTPUT
#define FXDC_VERT_SIZE
#define FXDC_PIXEL_HEIGHT
#define FXDC_HORZ_SIZE
#define FXRC_ALPHA_PATH
#define FXRC_BLEND_MODE
#define FXRC_ALPHA_IMAGE
#define FXRC_GET_BITS
#define FXRC_SHADING
#define FXRC_SOFT_CLIP
bool bInterpolateBilinear
Definition fx_dib.h:41
int32_t bottom
int32_t right
int32_t top
int32_t left