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/check_op.h"
13#include "core/fxcrt/data_vector.h"
14#include "core/fxcrt/fx_memory_wrappers.h"
15#include "core/fxcrt/retain_ptr.h"
16#include "core/fxcrt/span.h"
17#include "core/fxcrt/unowned_ptr.h"
18#include "core/fxge/cfx_fillrenderoptions.h"
19#include "core/fxge/cfx_path.h"
20#include "core/fxge/renderdevicedriver_iface.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 SkPaint;
29class SkPath;
30class SkSurface;
31class TextCharPos;
33
34// Assumes Skia is not going to add non-data members to its fundamental types.
37
38class CFX_SkiaDeviceDriver final : public RenderDeviceDriverIface {
39 public:
41 RetainPtr<CFX_DIBitmap> pBitmap,
42 bool bRgbByteOrder,
43 RetainPtr<CFX_DIBitmap> pBackdropBitmap,
44 bool bGroupKnockout);
45 static std::unique_ptr<CFX_SkiaDeviceDriver> Create(SkCanvas& canvas);
46
47 ~CFX_SkiaDeviceDriver() override;
48
49 // RenderDeviceDriverIface:
50 DeviceType GetDeviceType() const override;
51 int GetDeviceCaps(int caps_id) const override;
52 void SaveState() override;
53 void RestoreState(bool bKeepSaved) override;
54 bool SetClip_PathFill(const CFX_Path& path,
55 const CFX_Matrix* pObject2Device,
56 const CFX_FillRenderOptions& fill_options) override;
57 bool SetClip_PathStroke(const CFX_Path& path,
58 const CFX_Matrix* pObject2Device,
59 const CFX_GraphStateData* pGraphState) override;
60 bool DrawPath(const CFX_Path& path,
61 const CFX_Matrix* pObject2Device,
62 const CFX_GraphStateData* pGraphState,
63 uint32_t fill_color,
64 uint32_t stroke_color,
65 const CFX_FillRenderOptions& fill_options) override;
66 bool FillRect(const FX_RECT& rect, uint32_t fill_color) override;
67 FX_RECT GetClipBox() const override;
68 bool GetDIBits(RetainPtr<CFX_DIBitmap> bitmap,
69 int left,
70 int top) const override;
71 RetainPtr<const CFX_DIBitmap> GetBackDrop() const override;
72 bool SetDIBits(RetainPtr<const CFX_DIBBase> bitmap,
73 uint32_t color,
74 const FX_RECT& src_rect,
75 int dest_left,
76 int dest_top,
77 BlendMode blend_type) override;
78 bool SetBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
79 RetainPtr<const CFX_DIBBase> mask,
80 int dest_left,
81 int dest_top,
82 float alpha,
83 BlendMode blend_type) override;
84 void SetGroupKnockout(bool group_knockout) override;
86 bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
87 uint32_t color,
88 int dest_left,
89 int dest_top,
90 int dest_width,
91 int dest_height,
92 const FX_RECT* pClipRect,
93 const FXDIB_ResampleOptions& options,
94 BlendMode blend_type) override;
96 float alpha,
97 uint32_t color,
98 const CFX_Matrix& matrix,
99 const FXDIB_ResampleOptions& options,
100 BlendMode blend_type) override;
101 bool DrawBitsWithMask(RetainPtr<const CFX_DIBBase> bitmap,
102 RetainPtr<const CFX_DIBBase> mask,
103 float alpha,
104 const CFX_Matrix& matrix,
105 BlendMode blend_type);
106 bool DrawDeviceText(pdfium::span<const TextCharPos> pCharPos,
107 CFX_Font* pFont,
108 const CFX_Matrix& mtObject2Device,
109 float font_size,
110 uint32_t color,
111 const CFX_TextRenderOptions& options) override;
112 int GetDriverType() const override;
113 bool DrawShading(const CPDF_ShadingPattern& pattern,
114 const CFX_Matrix& matrix,
115 const FX_RECT& clip_rect,
116 int alpha) override;
117
118 bool MultiplyAlpha(float alpha) override;
119 bool MultiplyAlphaMask(RetainPtr<const CFX_DIBitmap> mask) override;
120
121 void Clear(uint32_t color);
122 void Dump() const;
123
124 private:
125 class CharDetail {
126 public:
127 CharDetail();
128 ~CharDetail();
129
130 const DataVector<SkPoint>& GetPositions() const { return m_positions; }
131 void SetPositionAt(size_t index, const SkPoint& position) {
132 m_positions[index] = position;
133 }
134 const DataVector<uint16_t>& GetGlyphs() const { return m_glyphs; }
135 void SetGlyphAt(size_t index, uint16_t glyph) { m_glyphs[index] = glyph; }
136 const DataVector<uint32_t>& GetFontCharWidths() const {
137 return m_fontCharWidths;
138 }
139 void SetFontCharWidthAt(size_t index, uint32_t width) {
140 m_fontCharWidths[index] = width;
141 }
142 size_t Count() const {
143 DCHECK_EQ(m_positions.size(), m_glyphs.size());
144 return m_glyphs.size();
145 }
146 void SetCount(size_t count) {
147 m_positions.resize(count);
148 m_glyphs.resize(count);
149 m_fontCharWidths.resize(count);
150 }
151
152 private:
153 DataVector<SkPoint> m_positions; // accumulator for text positions
154 DataVector<uint16_t> m_glyphs; // accumulator for text glyphs
155 // accumulator for glyphs' width defined in pdf
156 DataVector<uint32_t> m_fontCharWidths;
157 };
158
159 // Use the public creation methods instead.
160 CFX_SkiaDeviceDriver(RetainPtr<CFX_DIBitmap> pBitmap,
161 bool bRgbByteOrder,
162 RetainPtr<CFX_DIBitmap> pBackdropBitmap,
163 bool bGroupKnockout);
164 explicit CFX_SkiaDeviceDriver(SkCanvas& canvas);
165
166 bool TryDrawText(pdfium::span<const TextCharPos> char_pos,
167 const CFX_Font* pFont,
168 const CFX_Matrix& matrix,
169 float font_size,
170 uint32_t color,
171 const CFX_TextRenderOptions& options);
172
173 bool StartDIBitsSkia(RetainPtr<const CFX_DIBBase> bitmap,
174 const FX_RECT& src_rect,
175 float alpha,
176 uint32_t color,
177 const CFX_Matrix& matrix,
178 const FXDIB_ResampleOptions& options,
179 BlendMode blend_type);
180
181 // A wrapper around SkCanvas::drawPath() that optionally can show debug data.
182 void DrawPathImpl(const SkPath& path, const SkPaint& paint);
183
184 RetainPtr<CFX_DIBitmap> m_pBitmap;
185 RetainPtr<CFX_DIBitmap> m_pBackdropBitmap;
186
187 // The input bitmap passed by the render device. Only used when the input
188 // bitmap is 24 bpp and cannot be directly used as the back of a SkCanvas.
189 RetainPtr<CFX_DIBitmap> m_pOriginalBitmap;
190
191 sk_sp<SkSurface> surface_;
192 UnownedPtr<SkCanvas> m_pCanvas;
193 CFX_FillRenderOptions m_FillOptions;
194 bool m_bRgbByteOrder;
195 bool m_bGroupKnockout;
196
197 CharDetail m_charDetails;
198 // accumulator for txt rotate/scale/translate
199 DataVector<SkRSXform> m_rsxform;
200};
201
202#endif // CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_
#define DCHECK_IS_ON()
Definition check.h:24
#define DCHECK
Definition check.h:33
#define DCHECK_GE(x, y)
Definition check_op.h:22
#define DCHECK_LE(x, y)
Definition check_op.h:21
#define CHECK_EQ(x, y)
Definition check_op.h:10
#define CHECK_GE(x, y)
Definition check_op.h:15
#define CHECK_LE(x, y)
Definition check_op.h:14
#define DCHECK_EQ(x, y)
Definition check_op.h:17
uint32_t GetBits(uint32_t nBits)
FXDIB_Format GetFormat() const
Definition cfx_dibbase.h:69
void SetFormat(FXDIB_Format format)
uint32_t GetPitch() const
Definition cfx_dibbase.h:67
int GetHeight() const
Definition cfx_dibbase.h:66
int GetWidth() const
Definition cfx_dibbase.h:65
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:178
FXFT_FaceRec * GetFaceRec() const
Definition cfx_font.h:76
bool IsVertical() const
Definition cfx_font.h:108
constexpr CFX_Matrix()=default
float GetXUnit() const
float GetYUnit() const
static CFX_Matrix GetFlipMatrix(float width, float height, float left, float top)
void SetBitmap(RetainPtr< CFX_DIBitmap > bitmap)
bool DrawBitsWithMask(RetainPtr< const CFX_DIBBase > bitmap, RetainPtr< const CFX_DIBBase > mask, float alpha, const CFX_Matrix &matrix, BlendMode blend_type)
void SyncInternalBitmaps() 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
StartResult StartDIBits(RetainPtr< const CFX_DIBBase > bitmap, float alpha, uint32_t color, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options, BlendMode blend_type) override
bool FillRect(const FX_RECT &rect, uint32_t fill_color) override
bool DrawShading(const CPDF_ShadingPattern &pattern, const CFX_Matrix &matrix, const FX_RECT &clip_rect, int alpha) override
void SetGroupKnockout(bool group_knockout) override
DeviceType GetDeviceType() const override
void SaveState() override
bool MultiplyAlphaMask(RetainPtr< const CFX_DIBitmap > mask) override
static std::unique_ptr< CFX_SkiaDeviceDriver > Create(SkCanvas &canvas)
bool SetClip_PathFill(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_FillRenderOptions &fill_options) override
RetainPtr< const CFX_DIBitmap > GetBackDrop() const override
static std::unique_ptr< CFX_SkiaDeviceDriver > Create(RetainPtr< CFX_DIBitmap > pBitmap, bool bRgbByteOrder, RetainPtr< CFX_DIBitmap > pBackdropBitmap, bool bGroupKnockout)
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) override
int GetDriverType() const override
int GetDeviceCaps(int caps_id) const override
bool SetDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t color, const FX_RECT &src_rect, int dest_left, int dest_top, BlendMode blend_type) override
FX_RECT GetClipBox() const 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
void RestoreState(bool bKeepSaved) override
bool GetDIBits(RetainPtr< CFX_DIBitmap > bitmap, int left, int top) const 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)
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
Definition cpdf_array.h:29
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
float GetExponent() const
uint32_t GetOrigOutputs() const
uint32_t InputCount() const
float GetRange(int i) const
float GetDomain(int i) const
uint32_t OutputCount() const
uint32_t ReadFlag() const
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)
bool m_bGlyphAdjust
@ kRadialShading
@ kAxialShading
@ kCoonsPatchMeshShading
CFX_PTemplate< float > CFX_PointF
BlendMode
Definition fx_dib.h:119
#define FXARGB_A(argb)
Definition fx_dib.h:196
FXDIB_Format
Definition fx_dib.h:21
#define FX_DATA_PARTITION_EXCEPTION(T)
#define SHOW_SKIA_PATH
#define FXSYS_PI
Definition fx_system.h:44
#define NOTREACHED_NORETURN()
Definition notreached.h:22
#define CHECK(cvref)
#define FXDC_BITS_PIXEL
#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_SOFT_CLIP
int32_t bottom
int32_t right
int32_t top
int32_t left