OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/include/fxge/fx_ge.h" | 5 #include "core/include/fxge/fx_ge.h" |
6 | 6 |
7 #if defined(_SKIA_SUPPORT_) | 7 #if defined(_SKIA_SUPPORT_) |
8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
9 | 9 |
10 #include "SkDashPathEffect.h" | |
11 #include "SkRasterClip.h" | |
12 #include "SkScan.h" | |
13 #include "SkStroke.h" | |
14 #include "SkTLazy.h" | |
15 | |
16 #include "core/src/fxge/agg/include/fx_agg_driver.h" | 10 #include "core/src/fxge/agg/include/fx_agg_driver.h" |
17 #include "core/src/fxge/skia/fx_skia_blitter_new.h" | |
18 #include "core/src/fxge/skia/fx_skia_device.h" | 11 #include "core/src/fxge/skia/fx_skia_device.h" |
19 | 12 |
20 extern "C" { | 13 #include "SkCanvas.h" |
21 extern void FX_OUTPUT_LOG_FUNC(const char*, ...); | 14 #include "SkDashPathEffect.h" |
22 extern int FX_GET_TICK_FUNC(); | 15 #include "SkPaint.h" |
23 }; | 16 #include "SkPath.h" |
24 | 17 |
25 #ifdef _FOXIT_DEBUG_ | 18 static SkPath BuildPath(const CFX_PathData* pPathData, |
26 #define FOXIT_DEBUG1(msg) FX_OUTPUT_LOG_FUNC(msg) | 19 const CFX_Matrix* pObject2Device) { |
27 #define FOXIT_DEBUG2(msg, para) FX_OUTPUT_LOG_FUNC(msg, para) | 20 SkPath skPath; |
28 #define FOXIT_DEBUG3(msg, para1, para2) FX_OUTPUT_LOG_FUNC(msg, para1, para2) | |
29 #define FOXIT_DEBUG4(msg, para1, para2, para3) \ | |
30 FX_OUTPUT_LOG_FUNC(msg, para1, para2, para3) | |
31 #define FOXIT_DEBUG5(msg, para1, para2, para3, param4) \ | |
32 FX_OUTPUT_LOG_FUNC(msg, para1, para2, para3, param4) | |
33 #else | |
34 #define FOXIT_DEBUG1(msg) | |
35 #define FOXIT_DEBUG2(msg, para) | |
36 #define FOXIT_DEBUG3(msg, para1, para2) | |
37 #define FOXIT_DEBUG4(msg, para1, para2, para3) | |
38 #define FOXIT_DEBUG5(msg, para1, para2, para3, param4) | |
39 #endif | |
40 | |
41 /// Run-length-encoded supersampling antialiased blitter. | |
42 class SuperBlitter_skia { | |
43 public: | |
44 static void DrawPath(const SkPath& srcPath, | |
45 SkBlitter* blitter, | |
46 const SkRasterClip& rect, | |
47 const SkPaint& origPaint); | |
48 }; | |
49 FX_BOOL FxSkDrawTreatAsHairline(const SkPaint& paint, SkScalar* coverage) { | |
50 if (SkPaint::kStroke_Style != paint.getStyle()) | |
51 return FALSE; | |
52 FXSYS_assert(coverage); | |
53 SkScalar strokeWidth = paint.getStrokeWidth(); | |
54 if (0 == strokeWidth) { | |
55 *coverage = SK_Scalar1; | |
56 return TRUE; | |
57 } | |
58 // if we get here, we need to try to fake a thick-stroke with a modulated | |
59 // hairline | |
60 if (!paint.isAntiAlias()) | |
61 return FALSE; | |
62 if (strokeWidth <= SK_Scalar1) { | |
63 *coverage = strokeWidth; | |
64 return TRUE; | |
65 } | |
66 return FALSE; | |
67 } | |
68 | |
69 void SuperBlitter_skia::DrawPath(const SkPath& srcPath, | |
70 SkBlitter* blitter, | |
71 const SkRasterClip& rect, | |
72 const SkPaint& origPaint) { | |
73 SkPath* pathPtr = (SkPath*)&srcPath; | |
74 bool doFill = true; | |
75 SkPath tmpPath; | |
76 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); | |
77 { | |
78 SkScalar coverage; | |
79 if (FxSkDrawTreatAsHairline(origPaint, &coverage)) { | |
80 if (SK_Scalar1 == coverage) { | |
81 paint.writable()->setStrokeWidth(0); | |
82 } else if (1) { // xfermodeSupportsCoverageAsAlpha(xfer), we not use | |
83 // blend mode here, xfer aways NULL. | |
84 U8CPU newAlpha; | |
85 // this is the old technique, which we preserve for now so | |
86 // we don't change previous results (testing) | |
87 // the new way seems fine, its just (a tiny bit) different | |
88 int scale = (int)SkScalarMul(coverage, 256); | |
89 newAlpha = origPaint.getAlpha() * scale >> 8; | |
90 SkPaint* writablePaint = paint.writable(); | |
91 writablePaint->setStrokeWidth(0); | |
92 writablePaint->setAlpha(newAlpha); | |
93 } | |
94 } | |
95 } | |
96 if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { | |
97 SkIRect devBounds = rect.getBounds(); | |
98 // outset to have slop for antialasing and hairlines | |
99 devBounds.outset(1, 1); | |
100 SkRect cullRect = SkRect::Make(devBounds); | |
101 doFill = paint->getFillPath(*pathPtr, &tmpPath, &cullRect); | |
102 pathPtr = &tmpPath; | |
103 } | |
104 // avoid possibly allocating a new path in transform if we can | |
105 SkPath* devPathPtr = pathPtr; | |
106 void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*); | |
107 if (doFill) { | |
108 if (paint->isAntiAlias()) { | |
109 proc = SkScan::AntiFillPath; | |
110 } else { | |
111 proc = SkScan::FillPath; | |
112 } | |
113 } else { // hairline | |
114 if (paint->isAntiAlias()) { | |
115 proc = SkScan::AntiHairPath; | |
116 } else { | |
117 proc = SkScan::HairPath; | |
118 } | |
119 } | |
120 proc(*devPathPtr, rect, blitter); | |
121 } | |
122 | |
123 class CSkia_PathData { | |
124 public: | |
125 CSkia_PathData() {} | |
126 ~CSkia_PathData() {} | |
127 SkPath m_PathData; | |
128 | |
129 void BuildPath(const CFX_PathData* pPathData, | |
130 const CFX_Matrix* pObject2Device); | |
131 }; | |
132 | |
133 void CSkia_PathData::BuildPath(const CFX_PathData* pPathData, | |
134 const CFX_Matrix* pObject2Device) { | |
135 const CFX_PathData* pFPath = pPathData; | 21 const CFX_PathData* pFPath = pPathData; |
136 int nPoints = pFPath->GetPointCount(); | 22 int nPoints = pFPath->GetPointCount(); |
137 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 23 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
138 for (int i = 0; i < nPoints; i++) { | 24 for (int i = 0; i < nPoints; i++) { |
139 FX_FIXFLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY; | 25 FX_FLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY; |
Tom Sepez
2016/03/03 19:18:20
nit: one per line.
caryclark
2016/03/03 21:03:44
Done.
| |
140 if (pObject2Device) | 26 if (pObject2Device) |
141 pObject2Device->Transform(x, y); | 27 pObject2Device->Transform(x, y); |
142 int point_type = pPoints[i].m_Flag & FXPT_TYPE; | 28 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
143 if (point_type == FXPT_MOVETO) { | 29 if (point_type == FXPT_MOVETO) { |
144 m_PathData.moveTo(x, y); | 30 skPath.moveTo(x, y); |
145 } else if (point_type == FXPT_LINETO) { | 31 } else if (point_type == FXPT_LINETO) { |
146 if (pPoints[i - 1].m_Flag == FXPT_MOVETO && | 32 skPath.lineTo(x, y); |
147 (i == nPoints - 1 || pPoints[i + 1].m_Flag == FXPT_MOVETO) && | |
148 FXSYS_abs(pPoints[i].m_PointX - pPoints[i - 1].m_PointX) < 0.4f && | |
149 FXSYS_abs(pPoints[i].m_PointY - pPoints[i - 1].m_PointY) < 0.4f) | |
150 // PDF line includes the destination point, unlike Windows line. | |
151 // We received some PDF which actually draws zero length lines. TESTDOC: | |
152 // summer cha show.pdf | |
153 // Therefore, we have to extend the line by 0.4 pixel here. | |
dsinclair
2016/03/03 18:40:11
I'm not sure I understand this comment, the line w
caryclark
2016/03/03 21:03:44
An old Skia bug ignored zero-length line segments
| |
154 // But only for standalone segment. TESTDOC: bug #1434 - maze.pdf; | |
155 // TESTDOC: bug#1508 di704P_QIG_111.pdf | |
156 x += 0.4; | |
157 // TODO: we should actually tell skia vertex generator to process zero | |
158 // length stroked line | |
159 // (only butts are drawn) | |
160 m_PathData.lineTo(x, y); | |
161 } else if (point_type == FXPT_BEZIERTO) { | 33 } else if (point_type == FXPT_BEZIERTO) { |
162 FX_FIXFLOAT x2 = pPoints[i + 1].m_PointX, y2 = pPoints[i + 1].m_PointY; | 34 FX_FLOAT x2 = pPoints[i + 1].m_PointX, y2 = pPoints[i + 1].m_PointY; |
163 FX_FIXFLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; | 35 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; |
164 if (pObject2Device) { | 36 if (pObject2Device) { |
165 pObject2Device->Transform(x2, y2); | 37 pObject2Device->Transform(x2, y2); |
166 pObject2Device->Transform(x3, y3); | 38 pObject2Device->Transform(x3, y3); |
167 } | 39 } |
168 m_PathData.cubicTo(x, y, x2, y2, x3, y3); | 40 skPath.cubicTo(x, y, x2, y2, x3, y3); |
169 i += 2; | 41 i += 2; |
170 } | 42 } |
171 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 43 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) |
172 m_PathData.close(); | 44 skPath.close(); |
173 } | 45 } |
46 return skPath; | |
174 } | 47 } |
175 | 48 |
176 // convert a stroking path to scanlines | 49 // convert a stroking path to scanlines |
177 static void SkRasterizeStroke(SkPaint& spaint, | 50 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint& spaint, |
178 SkPath* dstPathData, | 51 const CFX_GraphStateData* pGraphState) { |
179 SkPath& path_data, | |
180 const CFX_Matrix* pObject2Device, | |
181 const CFX_GraphStateData* pGraphState, | |
182 FX_FIXFLOAT scale = FIX8_ONE, | |
183 FX_BOOL bStrokeAdjust = FALSE, | |
184 FX_BOOL bTextMode = FALSE) { | |
185 SkPaint::Cap cap; | 52 SkPaint::Cap cap; |
186 switch (pGraphState->m_LineCap) { | 53 switch (pGraphState->m_LineCap) { |
187 case CFX_GraphStateData::LineCapRound: | 54 case CFX_GraphStateData::LineCapRound: |
188 cap = SkPaint::kRound_Cap; | 55 cap = SkPaint::kRound_Cap; |
189 break; | 56 break; |
190 case CFX_GraphStateData::LineCapSquare: | 57 case CFX_GraphStateData::LineCapSquare: |
191 cap = SkPaint::kSquare_Cap; | 58 cap = SkPaint::kSquare_Cap; |
192 break; | 59 break; |
193 default: | 60 default: |
194 cap = SkPaint::kButt_Cap; | 61 cap = SkPaint::kButt_Cap; |
195 break; | 62 break; |
196 } | 63 } |
197 SkPaint::Join join; | 64 SkPaint::Join join; |
198 switch (pGraphState->m_LineJoin) { | 65 switch (pGraphState->m_LineJoin) { |
199 case CFX_GraphStateData::LineJoinRound: | 66 case CFX_GraphStateData::LineJoinRound: |
200 join = SkPaint::kRound_Join; | 67 join = SkPaint::kRound_Join; |
201 break; | 68 break; |
202 case CFX_GraphStateData::LineJoinBevel: | 69 case CFX_GraphStateData::LineJoinBevel: |
203 join = SkPaint::kBevel_Join; | 70 join = SkPaint::kBevel_Join; |
204 break; | 71 break; |
205 default: | 72 default: |
206 join = SkPaint::kMiter_Join; | 73 join = SkPaint::kMiter_Join; |
207 break; | 74 break; |
208 } | 75 } |
209 FX_FIXFLOAT width = pGraphState->m_LineWidth * scale; | 76 FX_FLOAT width = pGraphState->m_LineWidth; |
210 FX_FIXFLOAT unit = fix32_to_8(fixdiv_8_8_to_32( | |
211 FIX8_ONE, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2)); | |
212 if (width <= unit) | |
213 width = unit; | |
214 | 77 |
215 if (pGraphState->m_DashArray) { | 78 if (pGraphState->m_DashArray) { |
216 int count = (pGraphState->m_DashCount + 1) / 2; | 79 int count = (pGraphState->m_DashCount + 1) / 2; |
217 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); | 80 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); |
218 // Set dash pattern | 81 // Set dash pattern |
219 for (int i = 0; i < count; i++) { | 82 for (int i = 0; i < count; i++) { |
220 FX_FIXFLOAT on = pGraphState->m_DashArray[i * 2]; | 83 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; |
221 if (on <= 0.000001f) | 84 if (on <= 0.000001f) |
222 on = FIX8_ONE / 10; | 85 on = 1.f / 10; |
223 FX_FIXFLOAT off = i * 2 + 1 == pGraphState->m_DashCount | 86 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount |
224 ? on | 87 ? on |
225 : pGraphState->m_DashArray[i * 2 + 1]; | 88 : pGraphState->m_DashArray[i * 2 + 1]; |
226 if (off < 0) | 89 if (off < 0) |
227 off = 0; | 90 off = 0; |
228 intervals[i * 2] = on * scale; | 91 intervals[i * 2] = on; |
229 intervals[i * 2 + 1] = off * scale; | 92 intervals[i * 2 + 1] = off; |
230 } | 93 } |
231 SkDashPathEffect* pEffect = new SkDashPathEffect( | 94 spaint |
232 intervals, count * 2, pGraphState->m_DashPhase * scale); | 95 .setPathEffect(SkDashPathEffect::Create(intervals, count * 2, |
233 spaint.setPathEffect(pEffect)->unref(); | 96 pGraphState->m_DashPhase)) |
234 spaint.setStrokeWidth(width); | 97 ->unref(); |
235 spaint.setStrokeMiter(pGraphState->m_MiterLimit); | |
236 spaint.setStrokeCap(cap); | |
237 spaint.setStrokeJoin(join); | |
238 spaint.getFillPath(path_data, dstPathData); | |
239 SkMatrix smatrix; | |
240 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, | |
241 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, | |
242 0, 1); | |
243 dstPathData->transform(smatrix); | |
244 FX_Free(intervals); | |
245 } else { | |
246 SkStroke stroker; | |
247 stroker.setCap(cap); | |
248 stroker.setJoin(join); | |
249 stroker.setMiterLimit(pGraphState->m_MiterLimit); | |
250 stroker.setWidth(width); | |
251 stroker.setDoFill(FALSE); | |
252 stroker.strokePath(path_data, dstPathData); | |
253 SkMatrix smatrix; | |
254 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, | |
dsinclair
2016/03/03 18:40:11
Do we need to worry about, what I'm guessing is ob
caryclark
2016/03/03 21:03:44
There is likely missing code, but the transform sh
| |
255 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, | |
256 0, 1); | |
257 dstPathData->transform(smatrix); | |
258 } | 98 } |
99 spaint.setStyle(SkPaint::kStroke_Style); | |
100 spaint.setAntiAlias(TRUE); | |
101 spaint.setStrokeWidth(width); | |
102 spaint.setStrokeMiter(pGraphState->m_MiterLimit); | |
103 spaint.setStrokeCap(cap); | |
104 spaint.setStrokeJoin(join); | |
259 } | 105 } |
260 | 106 |
261 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 107 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
262 int dither_bits, | 108 int dither_bits, |
263 FX_BOOL bRgbByteOrder, | 109 FX_BOOL bRgbByteOrder, |
264 CFX_DIBitmap* pOriDevice, | 110 CFX_DIBitmap* pOriDevice, |
265 FX_BOOL bGroupKnockout) { | 111 FX_BOOL bGroupKnockout) { |
266 m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, | 112 m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, |
267 pOriDevice, bGroupKnockout); | 113 pOriDevice, bGroupKnockout); |
114 SkBitmap skBitmap; | |
115 const CFX_DIBitmap* bitmap = m_pAggDriver->m_pBitmap; | |
116 SkImageInfo imageInfo = | |
117 SkImageInfo::Make(bitmap->GetWidth(), bitmap->GetHeight(), | |
118 kN32_SkColorType, kOpaque_SkAlphaType); | |
119 skBitmap.installPixels(imageInfo, bitmap->GetBuffer(), bitmap->GetPitch(), | |
120 nullptr, /* to do : set color table */ | |
121 nullptr, nullptr); | |
122 m_canvas = new SkCanvas(skBitmap); | |
268 } | 123 } |
124 | |
269 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 125 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
126 #if 0 // fix me : mismatch on allocator ? | |
dsinclair
2016/03/03 18:40:11
Once we figure out the allocator issue, can we std
caryclark
2016/03/03 21:03:44
I don't know. SkCanvas is a reference counted obje
dsinclair
2016/03/03 21:15:17
Ah, makes sense. Thanks for the info.
| |
127 delete m_canvas; | |
128 #endif | |
270 delete m_pAggDriver; | 129 delete m_pAggDriver; |
271 } | 130 } |
131 | |
272 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 132 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
273 const FXTEXT_CHARPOS* pCharPos, | 133 const FXTEXT_CHARPOS* pCharPos, |
274 CFX_Font* pFont, | 134 CFX_Font* pFont, |
275 CFX_FontCache* pCache, | 135 CFX_FontCache* pCache, |
276 const CFX_Matrix* pObject2Device, | 136 const CFX_Matrix* pObject2Device, |
277 FX_FIXFLOAT font_size, | 137 FX_FLOAT font_size, |
278 FX_DWORD color, | 138 FX_DWORD color, |
279 int alpha_flag, | 139 int alpha_flag, |
280 void* pIccTransform) { | 140 void* pIccTransform) { |
281 return m_pAggDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | 141 return m_pAggDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
282 pObject2Device, font_size, color, | 142 pObject2Device, font_size, color, |
283 alpha_flag, pIccTransform); | 143 alpha_flag, pIccTransform); |
284 } | 144 } |
145 | |
285 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) { | 146 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) { |
286 return m_pAggDriver->GetDeviceCaps(caps_id); | 147 return m_pAggDriver->GetDeviceCaps(caps_id); |
287 } | 148 } |
149 | |
288 void CFX_SkiaDeviceDriver::SaveState() { | 150 void CFX_SkiaDeviceDriver::SaveState() { |
151 m_canvas->save(); | |
289 m_pAggDriver->SaveState(); | 152 m_pAggDriver->SaveState(); |
290 } | 153 } |
291 | 154 |
292 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved) { | 155 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved) { |
293 m_pAggDriver->RestoreState(bKeepSaved); | 156 m_pAggDriver->RestoreState(bKeepSaved); |
157 m_canvas->restore(); | |
294 } | 158 } |
295 void CFX_SkiaDeviceDriver::SetClipMask(rasterizer_scanline_aa& rasterizer) { | 159 |
160 void CFX_SkiaDeviceDriver::SetClipMask( | |
161 agg::rasterizer_scanline_aa& rasterizer) { | |
296 m_pAggDriver->SetClipMask(rasterizer); | 162 m_pAggDriver->SetClipMask(rasterizer); |
297 } | 163 } |
298 void CFX_SkiaDeviceDriver::SetClipMask(SkPath& skPath, SkPaint* spaint) { | |
299 SkIRect clip_box; | |
300 clip_box.set(0, 0, fix0_to_8(GetDeviceCaps(FXDC_PIXEL_WIDTH)), | |
301 fix0_to_8(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | |
302 clip_box.intersect(m_pAggDriver->m_pClipRgn->GetBox().left, | |
303 m_pAggDriver->m_pClipRgn->GetBox().top, | |
304 m_pAggDriver->m_pClipRgn->GetBox().right, | |
305 m_pAggDriver->m_pClipRgn->GetBox().bottom); | |
306 | 164 |
307 SkPath* pathPtr = &skPath; | |
308 | |
309 SkRect path_rect = skPath.getBounds(); | |
310 | |
311 clip_box.intersect(FXSYS_floor(path_rect.fLeft), FXSYS_floor(path_rect.fTop), | |
312 FXSYS_floor(path_rect.fRight) + 1, | |
313 FXSYS_floor(path_rect.fBottom) + 1); | |
314 CFX_DIBitmapRef mask; | |
315 CFX_DIBitmap* pThisLayer = mask.New(); | |
316 pThisLayer->Create(clip_box.width(), clip_box.height(), FXDIB_8bppMask); | |
317 pThisLayer->Clear(0); | |
318 | |
319 CFX_SkiaA8Renderer render; | |
320 render.Init(pThisLayer, clip_box.fLeft, clip_box.fTop); | |
321 | |
322 SkRasterClip rasterClip(clip_box); | |
323 SuperBlitter_skia::DrawPath(skPath, (SkBlitter*)&render, rasterClip, *spaint); | |
324 | |
325 // Finally, we have got the mask that we need, intersect with current clip | |
326 // region | |
327 m_pAggDriver->m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask); | |
328 } | |
329 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( | 165 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( |
330 const CFX_PathData* pPathData, // path info | 166 const CFX_PathData* pPathData, // path info |
331 const CFX_Matrix* pObject2Device, // optional transformation | 167 const CFX_Matrix* pObject2Device, // optional transformation |
332 int fill_mode // fill mode, WINDING or ALTERNATE | 168 int fill_mode // fill mode, WINDING or ALTERNATE |
333 ) { | 169 ) { |
334 if (!m_pAggDriver->m_pClipRgn) { | 170 if (!m_pAggDriver->m_pClipRgn) { |
335 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( | 171 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( |
336 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 172 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
337 } | 173 } |
338 | 174 |
339 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 175 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
340 CFX_FloatRect rectf; | 176 CFX_FloatRect rectf; |
341 if (pPathData->IsRect(pObject2Device, &rectf)) { | 177 if (pPathData->IsRect(pObject2Device, &rectf)) { |
342 rectf.Intersect( | 178 rectf.Intersect( |
343 CFX_FloatRect(0, 0, (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 179 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
344 (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 180 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
345 FX_RECT rect = rectf.GetOutterRect(); | 181 FX_RECT rect = rectf.GetOutterRect(); |
346 m_pAggDriver->m_pClipRgn->IntersectRect(rect); | 182 m_pAggDriver->m_pClipRgn->IntersectRect(rect); |
347 return TRUE; | 183 return TRUE; |
348 } | 184 } |
349 } | 185 } |
350 CSkia_PathData path_data; | 186 SkPath clip = BuildPath(pPathData, pObject2Device); |
351 path_data.BuildPath(pPathData, pObject2Device); | 187 clip.setFillType((fill_mode & 3) == FXFILL_WINDING |
352 path_data.m_PathData.close(); | 188 ? SkPath::kWinding_FillType |
353 path_data.m_PathData.setFillType((fill_mode & 3) == FXFILL_WINDING | 189 : SkPath::kEvenOdd_FillType); |
354 ? SkPath::kWinding_FillType | 190 #if 0 |
355 : SkPath::kEvenOdd_FillType); | 191 // fix me : don't clip quite yet |
dsinclair
2016/03/03 18:40:11
nit: fix me should be TODO(caryclark)
caryclark
2016/03/03 21:03:44
Done.
| |
356 | 192 // need to understand how to save/restore to balance the clip |
357 SkPaint spaint; | 193 m_canvas->clipPath(clip, SkRegion::kReplace_Op); |
358 spaint.setColor(0xffffffff); | 194 #endif |
359 spaint.setAntiAlias(TRUE); | |
360 spaint.setStyle(SkPaint::kFill_Style); | |
361 | |
362 SetClipMask(path_data.m_PathData, &spaint); | |
363 | 195 |
364 return TRUE; | 196 return TRUE; |
365 } | 197 } |
366 | 198 |
367 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( | 199 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( |
368 const CFX_PathData* pPathData, // path info | 200 const CFX_PathData* pPathData, // path info |
369 const CFX_Matrix* pObject2Device, // optional transformation | 201 const CFX_Matrix* pObject2Device, // optional transformation |
370 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 202 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
371 ) { | 203 ) { |
372 if (!m_pAggDriver->m_pClipRgn) { | 204 if (!m_pAggDriver->m_pClipRgn) { |
373 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( | 205 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( |
374 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 206 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
375 } | 207 } |
376 | 208 |
377 // build path data | 209 // build path data |
378 CSkia_PathData path_data; | 210 SkPath skPath = BuildPath(pPathData, NULL); |
379 path_data.BuildPath(pPathData, NULL); | 211 skPath.setFillType(SkPath::kWinding_FillType); |
380 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); | |
381 | 212 |
382 SkPaint spaint; | 213 SkPaint spaint; |
383 spaint.setColor(0xffffffff); | 214 PaintStroke(spaint, pGraphState); |
384 spaint.setStyle(SkPaint::kStroke_Style); | |
385 spaint.setAntiAlias(TRUE); | |
386 | |
387 SkPath dst_path; | 215 SkPath dst_path; |
388 SkRasterizeStroke(spaint, &dst_path, path_data.m_PathData, pObject2Device, | 216 spaint.getFillPath(skPath, &dst_path); |
389 pGraphState, 1, FALSE, 0); | 217 #if 01 |
390 spaint.setStyle(SkPaint::kFill_Style); | 218 // fix me : don't clip quite yet |
391 SetClipMask(dst_path, &spaint); | 219 // need to understand how to save/restore so that clip is later undone |
392 | 220 m_canvas->clipPath(dst_path, SkRegion::kReplace_Op); |
221 #endif | |
393 return TRUE; | 222 return TRUE; |
394 } | 223 } |
224 | |
395 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizer( | 225 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizer( |
396 rasterizer_scanline_aa& rasterizer, | 226 agg::rasterizer_scanline_aa& rasterizer, |
397 FX_DWORD color, | 227 FX_DWORD color, |
398 FX_BOOL bFullCover, | 228 FX_BOOL bFullCover, |
399 FX_BOOL bGroupKnockout, | 229 FX_BOOL bGroupKnockout, |
400 int alpha_flag, | 230 int alpha_flag, |
401 void* pIccTransform) { | 231 void* pIccTransform) { |
402 return m_pAggDriver->RenderRasterizer( | 232 return m_pAggDriver->RenderRasterizer( |
403 rasterizer, color, bFullCover, bGroupKnockout, alpha_flag, pIccTransform); | 233 rasterizer, color, bFullCover, bGroupKnockout, alpha_flag, pIccTransform); |
404 } | 234 } |
405 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizerSkia(SkPath& skPath, | |
406 const SkPaint& origPaint, | |
407 SkIRect& rect, | |
408 FX_DWORD color, | |
409 FX_BOOL bFullCover, | |
410 FX_BOOL bGroupKnockout, | |
411 int alpha_flag, | |
412 void* pIccTransform, | |
413 FX_BOOL bFill) { | |
414 CFX_DIBitmap* pt = bGroupKnockout ? m_pAggDriver->GetBackDrop() : NULL; | |
415 CFX_SkiaRenderer render; | |
416 if (!render.Init(m_pAggDriver->m_pBitmap, pt, m_pAggDriver->m_pClipRgn, color, | |
417 bFullCover, m_pAggDriver->m_bRgbByteOrder, alpha_flag, | |
418 pIccTransform)) | |
419 return FALSE; | |
420 | |
421 SkRasterClip rasterClip(rect); | |
422 SuperBlitter_skia::DrawPath(skPath, (SkBlitter*)&render, rasterClip, | |
423 origPaint); | |
424 | |
425 return TRUE; | |
426 } | |
427 | 235 |
428 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 236 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( |
429 const CFX_PathData* pPathData, // path info | 237 const CFX_PathData* pPathData, // path info |
430 const CFX_Matrix* pObject2Device, // optional transformation | 238 const CFX_Matrix* pObject2Device, // optional transformation |
431 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 239 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
432 FX_DWORD fill_color, // fill color | 240 FX_DWORD fill_color, // fill color |
433 FX_DWORD stroke_color, // stroke color | 241 FX_DWORD stroke_color, // stroke color |
434 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 242 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
435 int alpha_flag, | 243 int alpha_flag, |
436 void* pIccTransform) { | 244 void* pIccTransform, |
245 int blend_type) { | |
437 if (!GetBuffer()) | 246 if (!GetBuffer()) |
438 return TRUE; | 247 return TRUE; |
439 FOXIT_DEBUG1("CFX_SkiaDeviceDriver::DrawPath: entering"); | |
440 SkIRect rect; | 248 SkIRect rect; |
441 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 249 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
442 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 250 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
251 SkPath skPath = BuildPath(pPathData, pObject2Device); | |
252 SkPaint spaint; | |
253 spaint.setAntiAlias(TRUE); | |
443 if ((fill_mode & 3) && fill_color) { | 254 if ((fill_mode & 3) && fill_color) { |
444 // We have to transform before building path data, otherwise we'll have | 255 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
445 // flatting problem | 256 ? SkPath::kWinding_FillType |
446 // when we enlarge a small path (flatten before transformed) | 257 : SkPath::kEvenOdd_FillType); |
447 // TESTDOC: Bug #5115 - DS_S1Dimpact_lr.pdf | |
448 // build path data | |
449 CSkia_PathData path_data; | |
450 path_data.BuildPath(pPathData, pObject2Device); | |
451 // path_data.m_PathData.close(); | |
452 path_data.m_PathData.setFillType((fill_mode & 3) == FXFILL_WINDING | |
453 ? SkPath::kWinding_FillType | |
454 : SkPath::kEvenOdd_FillType); | |
455 | 258 |
456 SkPaint spaint; | |
457 spaint.setAntiAlias(TRUE); | |
458 spaint.setStyle(SkPaint::kFill_Style); | 259 spaint.setStyle(SkPaint::kFill_Style); |
459 spaint.setColor(fill_color); | 260 spaint.setColor(fill_color); |
460 if (!RenderRasterizerSkia(path_data.m_PathData, spaint, rect, fill_color, | 261 m_canvas->drawPath(skPath, spaint); |
461 fill_mode & FXFILL_FULLCOVER, FALSE, alpha_flag, | |
462 pIccTransform)) | |
463 return FALSE; | |
464 } | 262 } |
465 | |
466 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 263 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) |
467 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) | 264 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) |
468 : FXARGB_A(stroke_color); | 265 : FXARGB_A(stroke_color); |
469 | 266 |
470 if (pGraphState && stroke_alpha) { | 267 if (pGraphState && stroke_alpha) { |
471 // We split the matrix into two parts: first part doing the scaling, so we | |
472 // won't have the | |
473 // flatness problem, second part doing the transformation, so we don't have | |
474 // stroking geo problem. | |
475 // TESTDOC: Bug #5253 - test[1].pdf | |
476 CFX_Matrix matrix1, matrix2; | |
477 if (pObject2Device) { | |
478 matrix1.a = FXSYS_fabs(pObject2Device->a) > FXSYS_fabs(pObject2Device->b) | |
479 ? FXSYS_fabs(pObject2Device->a) | |
480 : FXSYS_fabs(pObject2Device->b); | |
481 matrix1.d = matrix1.a; // FXSYS_fabs(pObject2Device->c) > | |
482 // FXSYS_fabs(pObject2Device->d) ? | |
483 // pObject2Device->c : pObject2Device->d; | |
484 matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a, | |
485 pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d, | |
486 pObject2Device->e, pObject2Device->f); | |
487 } | |
488 // build path data | |
489 CSkia_PathData path_data; | |
490 path_data.BuildPath(pPathData, &matrix1); | |
491 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); | |
492 | |
493 SkPaint spaint; | |
494 spaint.setColor(stroke_color); | 268 spaint.setColor(stroke_color); |
495 spaint.setStyle(SkPaint::kStroke_Style); | 269 PaintStroke(spaint, pGraphState); |
496 spaint.setAntiAlias(TRUE); | 270 m_canvas->drawPath(skPath, spaint); |
497 SkPath dst_path; | |
498 SkRasterizeStroke(spaint, &dst_path, path_data.m_PathData, &matrix2, | |
499 pGraphState, matrix1.a, FALSE, 0); | |
500 spaint.setStyle(SkPaint::kFill_Style); | |
501 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag) << 8 | | |
502 FXGETFLAG_ALPHA_STROKE(alpha_flag); | |
503 | |
504 if (!RenderRasterizerSkia(dst_path, spaint, rect, stroke_color, | |
505 fill_mode & FXFILL_FULLCOVER, FALSE, fill_flag, | |
506 pIccTransform, FALSE)) | |
507 return FALSE; | |
508 } | 271 } |
509 | 272 |
510 return TRUE; | 273 return TRUE; |
511 } | 274 } |
512 | 275 |
513 FX_BOOL CFX_SkiaDeviceDriver::SetPixel(int x, | 276 FX_BOOL CFX_SkiaDeviceDriver::SetPixel(int x, |
514 int y, | 277 int y, |
515 FX_DWORD color, | 278 FX_DWORD color, |
516 int alpha_flag, | 279 int alpha_flag, |
517 void* pIccTransform) { | 280 void* pIccTransform) { |
518 return m_pAggDriver->SetPixel(x, y, color, alpha_flag, pIccTransform); | 281 return m_pAggDriver->SetPixel(x, y, color, alpha_flag, pIccTransform); |
519 } | 282 } |
520 | 283 |
521 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, | 284 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, |
522 FX_DWORD fill_color, | 285 FX_DWORD fill_color, |
523 int alpha_flag, | 286 int alpha_flag, |
524 void* pIccTransform) { | 287 void* pIccTransform, |
525 return m_pAggDriver->FillRect(pRect, fill_color, alpha_flag, pIccTransform); | 288 int blend_type) { |
289 return m_pAggDriver->FillRect(pRect, fill_color, alpha_flag, pIccTransform, | |
290 blend_type); | |
526 } | 291 } |
527 | 292 |
528 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 293 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
529 return m_pAggDriver->GetClipBox(pRect); | 294 return m_pAggDriver->GetClipBox(pRect); |
530 } | 295 } |
531 | 296 |
532 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 297 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
533 int left, | 298 int left, |
534 int top, | 299 int top, |
535 void* pIccTransform, | 300 void* pIccTransform, |
(...skipping 15 matching lines...) Expand all Loading... | |
551 | 316 |
552 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 317 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
553 FX_DWORD argb, | 318 FX_DWORD argb, |
554 int dest_left, | 319 int dest_left, |
555 int dest_top, | 320 int dest_top, |
556 int dest_width, | 321 int dest_width, |
557 int dest_height, | 322 int dest_height, |
558 const FX_RECT* pClipRect, | 323 const FX_RECT* pClipRect, |
559 FX_DWORD flags, | 324 FX_DWORD flags, |
560 int alpha_flag, | 325 int alpha_flag, |
561 void* pIccTransform) { | 326 void* pIccTransform, |
327 int blend_type) { | |
562 return m_pAggDriver->StretchDIBits(pSource, argb, dest_left, dest_top, | 328 return m_pAggDriver->StretchDIBits(pSource, argb, dest_left, dest_top, |
563 dest_width, dest_height, pClipRect, flags, | 329 dest_width, dest_height, pClipRect, flags, |
564 alpha_flag, pIccTransform); | 330 alpha_flag, pIccTransform, blend_type); |
565 } | 331 } |
566 | 332 |
567 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 333 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
568 int bitmap_alpha, | 334 int bitmap_alpha, |
569 FX_DWORD argb, | 335 FX_DWORD argb, |
570 const CFX_Matrix* pMatrix, | 336 const CFX_Matrix* pMatrix, |
571 FX_DWORD render_flags, | 337 FX_DWORD render_flags, |
572 void*& handle, | 338 void*& handle, |
573 int alpha_flag, | 339 int alpha_flag, |
574 void* pIccTransform) { | 340 void* pIccTransform, |
341 int blend_type) { | |
575 return m_pAggDriver->StartDIBits(pSource, bitmap_alpha, argb, pMatrix, | 342 return m_pAggDriver->StartDIBits(pSource, bitmap_alpha, argb, pMatrix, |
576 render_flags, handle, alpha_flag, | 343 render_flags, handle, alpha_flag, |
577 pIccTransform); | 344 pIccTransform, blend_type); |
578 } | 345 } |
579 | 346 |
580 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { | 347 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
581 return m_pAggDriver->ContinueDIBits(pHandle, pPause); | 348 return m_pAggDriver->ContinueDIBits(pHandle, pPause); |
582 } | 349 } |
583 | 350 |
584 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { | 351 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { |
585 m_pAggDriver->CancelDIBits(pHandle); | 352 m_pAggDriver->CancelDIBits(pHandle); |
586 } | 353 } |
587 | 354 |
(...skipping 30 matching lines...) Expand all Loading... | |
618 CFX_SkiaDeviceDriver* pDriver = | 385 CFX_SkiaDeviceDriver* pDriver = |
619 new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE); | 386 new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE); |
620 SetDeviceDriver(pDriver); | 387 SetDeviceDriver(pDriver); |
621 return TRUE; | 388 return TRUE; |
622 } | 389 } |
623 CFX_SkiaDevice::~CFX_SkiaDevice() { | 390 CFX_SkiaDevice::~CFX_SkiaDevice() { |
624 if (m_bOwnedBitmap && GetBitmap()) | 391 if (m_bOwnedBitmap && GetBitmap()) |
625 delete GetBitmap(); | 392 delete GetBitmap(); |
626 } | 393 } |
627 | 394 |
395 #if 01 | |
396 #include <stdarg.h> | |
397 #include <stdio.h> | |
398 | |
399 void SkDebugf(const char format[], ...) { | |
400 va_list args; | |
401 va_start(args, format); | |
402 vfprintf(stderr, format, args); | |
403 va_end(args); | |
404 } | |
405 | |
628 #endif | 406 #endif |
407 | |
408 #endif | |
OLD | NEW |