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 "core/fxge/agg/fx_agg_driver.h" | 10 #include "core/fxge/agg/fx_agg_driver.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 path.dump(&stream, false, false); | 30 path.dump(&stream, false, false); |
31 printf("%s\n", buffer); | 31 printf("%s\n", buffer); |
32 #endif // SHOW_SKIA_PATH | 32 #endif // SHOW_SKIA_PATH |
33 } | 33 } |
34 | 34 |
35 static void DebugShowCanvasMatrix(const SkCanvas* canvas) { | 35 static void DebugShowCanvasMatrix(const SkCanvas* canvas) { |
36 #if SHOW_SKIA_PATH | 36 #if SHOW_SKIA_PATH |
37 SkMatrix matrix = canvas->getTotalMatrix(); | 37 SkMatrix matrix = canvas->getTotalMatrix(); |
38 SkScalar m[9]; | 38 SkScalar m[9]; |
39 matrix.get9(m); | 39 matrix.get9(m); |
40 printf("(%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], m[4], m[5 ], m[6], | 40 printf("(%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], m[4], |
41 m[7], m[8]); | 41 m[5], m[6], m[7], m[8]); |
42 #endif // SHOW_SKIA_PATH | 42 #endif // SHOW_SKIA_PATH |
43 } | 43 } |
44 | 44 |
45 #if DRAW_SKIA_CLIP | 45 #if DRAW_SKIA_CLIP |
46 | 46 |
47 static SkPaint DebugClipPaint() { | 47 static SkPaint DebugClipPaint() { |
48 SkPaint paint; | 48 SkPaint paint; |
49 paint.setAntiAlias(true); | 49 paint.setAntiAlias(true); |
50 paint.setColor(SK_ColorGREEN); | 50 paint.setColor(SK_ColorGREEN); |
51 paint.setStyle(SkPaint::kStroke_Style); | 51 paint.setStyle(SkPaint::kStroke_Style); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; | 90 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; |
91 skPath.cubicTo(x, y, x2, y2, x3, y3); | 91 skPath.cubicTo(x, y, x2, y2, x3, y3); |
92 i += 2; | 92 i += 2; |
93 } | 93 } |
94 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 94 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) |
95 skPath.close(); | 95 skPath.close(); |
96 } | 96 } |
97 return skPath; | 97 return skPath; |
98 } | 98 } |
99 | 99 |
100 static SkMatrix ToSkMatrix(const CFX_Matrix& m) { | |
dsinclair
2016/03/24 01:45:45
nit: Can these statics move into an anonymous name
caryclark
2016/03/24 13:48:02
Done.
| |
101 SkMatrix skMatrix; | |
102 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | |
103 return skMatrix; | |
104 } | |
105 | |
106 // use when pdf's y-axis points up insead of down | |
107 static SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m) { | |
108 SkMatrix skMatrix; | |
109 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1); | |
110 return skMatrix; | |
111 } | |
112 | |
113 static SkXfermode::Mode GetSkiaBlendMode(int blend_type) { | |
114 switch (blend_type) { | |
115 case FXDIB_BLEND_MULTIPLY: | |
116 return SkXfermode::kMultiply_Mode; | |
117 case FXDIB_BLEND_SCREEN: | |
118 return SkXfermode::kScreen_Mode; | |
119 case FXDIB_BLEND_OVERLAY: | |
120 return SkXfermode::kOverlay_Mode; | |
121 case FXDIB_BLEND_DARKEN: | |
122 return SkXfermode::kDarken_Mode; | |
123 case FXDIB_BLEND_LIGHTEN: | |
124 return SkXfermode::kLighten_Mode; | |
125 case FXDIB_BLEND_COLORDODGE: | |
126 return SkXfermode::kColorDodge_Mode; | |
127 case FXDIB_BLEND_COLORBURN: | |
128 return SkXfermode::kColorBurn_Mode; | |
129 case FXDIB_BLEND_HARDLIGHT: | |
130 return SkXfermode::kHardLight_Mode; | |
131 case FXDIB_BLEND_SOFTLIGHT: | |
132 return SkXfermode::kSoftLight_Mode; | |
133 case FXDIB_BLEND_DIFFERENCE: | |
134 return SkXfermode::kDifference_Mode; | |
135 case FXDIB_BLEND_EXCLUSION: | |
136 return SkXfermode::kExclusion_Mode; | |
137 case FXDIB_BLEND_HUE: | |
138 return SkXfermode::kHue_Mode; | |
139 case FXDIB_BLEND_SATURATION: | |
140 return SkXfermode::kSaturation_Mode; | |
141 case FXDIB_BLEND_COLOR: | |
142 return SkXfermode::kColor_Mode; | |
143 case FXDIB_BLEND_LUMINOSITY: | |
144 return SkXfermode::kLuminosity_Mode; | |
145 case FXDIB_BLEND_NORMAL: | |
146 default: | |
147 return SkXfermode::kSrcOver_Mode; | |
148 } | |
149 } | |
150 | |
100 // convert a stroking path to scanlines | 151 // convert a stroking path to scanlines |
101 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, | 152 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, |
102 const CFX_GraphStateData* pGraphState, | 153 const CFX_GraphStateData* pGraphState, |
103 const SkMatrix& matrix) { | 154 const SkMatrix& matrix) { |
104 SkPaint::Cap cap; | 155 SkPaint::Cap cap; |
105 switch (pGraphState->m_LineCap) { | 156 switch (pGraphState->m_LineCap) { |
106 case CFX_GraphStateData::LineCapRound: | 157 case CFX_GraphStateData::LineCapRound: |
107 cap = SkPaint::kRound_Cap; | 158 cap = SkPaint::kRound_Cap; |
108 break; | 159 break; |
109 case CFX_GraphStateData::LineCapSquare: | 160 case CFX_GraphStateData::LineCapSquare: |
(...skipping 15 matching lines...) Expand all Loading... | |
125 join = SkPaint::kMiter_Join; | 176 join = SkPaint::kMiter_Join; |
126 break; | 177 break; |
127 } | 178 } |
128 SkMatrix inverse; | 179 SkMatrix inverse; |
129 if (!matrix.invert(&inverse)) | 180 if (!matrix.invert(&inverse)) |
130 return; // give up if the matrix is degenerate, and not invertable | 181 return; // give up if the matrix is degenerate, and not invertable |
131 inverse.set(SkMatrix::kMTransX, 0); | 182 inverse.set(SkMatrix::kMTransX, 0); |
132 inverse.set(SkMatrix::kMTransY, 0); | 183 inverse.set(SkMatrix::kMTransY, 0); |
133 SkVector deviceUnits[2] = {{0, 1}, {1, 0}}; | 184 SkVector deviceUnits[2] = {{0, 1}, {1, 0}}; |
134 inverse.mapPoints(deviceUnits, SK_ARRAY_COUNT(deviceUnits)); | 185 inverse.mapPoints(deviceUnits, SK_ARRAY_COUNT(deviceUnits)); |
135 FX_FLOAT width = SkTMax(pGraphState->m_LineWidth, | 186 FX_FLOAT width = |
136 SkTMin(deviceUnits[0].length(), deviceUnits[1].length( ))); | 187 SkTMax(pGraphState->m_LineWidth, |
188 SkTMin(deviceUnits[0].length(), deviceUnits[1].length())); | |
137 if (pGraphState->m_DashArray) { | 189 if (pGraphState->m_DashArray) { |
138 int count = (pGraphState->m_DashCount + 1) / 2; | 190 int count = (pGraphState->m_DashCount + 1) / 2; |
139 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); | 191 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); |
140 // Set dash pattern | 192 // Set dash pattern |
141 for (int i = 0; i < count; i++) { | 193 for (int i = 0; i < count; i++) { |
142 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; | 194 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; |
143 if (on <= 0.000001f) | 195 if (on <= 0.000001f) |
144 on = 1.f / 10; | 196 on = 1.f / 10; |
145 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount | 197 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount |
146 ? on | 198 ? on |
147 : pGraphState->m_DashArray[i * 2 + 1]; | 199 : pGraphState->m_DashArray[i * 2 + 1]; |
148 if (off < 0) | 200 if (off < 0) |
149 off = 0; | 201 off = 0; |
150 intervals[i * 2] = on; | 202 intervals[i * 2] = on; |
151 intervals[i * 2 + 1] = off; | 203 intervals[i * 2 + 1] = off; |
152 } | 204 } |
153 spaint->setPathEffect(SkDashPathEffect::Create(intervals, count * 2, | 205 spaint->setPathEffect( |
154 pGraphState->m_DashPhase)) | 206 SkDashPathEffect::Make(intervals, count * 2, pGraphState->m_DashPhase)); |
155 ->unref(); | |
156 } | 207 } |
157 spaint->setStyle(SkPaint::kStroke_Style); | 208 spaint->setStyle(SkPaint::kStroke_Style); |
158 spaint->setAntiAlias(true); | 209 spaint->setAntiAlias(true); |
159 spaint->setStrokeWidth(width); | 210 spaint->setStrokeWidth(width); |
160 spaint->setStrokeMiter(pGraphState->m_MiterLimit); | 211 spaint->setStrokeMiter(pGraphState->m_MiterLimit); |
161 spaint->setStrokeCap(cap); | 212 spaint->setStrokeCap(cap); |
162 spaint->setStrokeJoin(join); | 213 spaint->setStrokeJoin(join); |
163 } | 214 } |
164 | 215 |
165 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 216 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
(...skipping 30 matching lines...) Expand all Loading... | |
196 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 247 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
197 m_ditherBits = 0; | 248 m_ditherBits = 0; |
198 } | 249 } |
199 | 250 |
200 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 251 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
201 if (!m_pRecorder) | 252 if (!m_pRecorder) |
202 delete m_pCanvas; | 253 delete m_pCanvas; |
203 delete m_pAggDriver; | 254 delete m_pAggDriver; |
204 } | 255 } |
205 | 256 |
206 static SkMatrix ToSkMatrix(const CFX_Matrix& m) { | |
207 SkMatrix skMatrix; | |
208 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | |
209 return skMatrix; | |
210 } | |
211 | |
212 // use when pdf's y-axis points up insead of down | |
213 static SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m) { | |
214 SkMatrix skMatrix; | |
215 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1); | |
216 return skMatrix; | |
217 } | |
218 | |
219 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 257 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
220 const FXTEXT_CHARPOS* pCharPos, | 258 const FXTEXT_CHARPOS* pCharPos, |
221 CFX_Font* pFont, | 259 CFX_Font* pFont, |
222 CFX_FontCache* pCache, | 260 CFX_FontCache* pCache, |
223 const CFX_Matrix* pObject2Device, | 261 const CFX_Matrix* pObject2Device, |
224 FX_FLOAT font_size, | 262 FX_FLOAT font_size, |
225 FX_DWORD color, | 263 FX_DWORD color, |
226 int alpha_flag, | 264 int alpha_flag, |
227 void* pIccTransform) { | 265 void* pIccTransform) { |
228 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( | 266 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( |
229 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); | 267 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); |
230 SkPaint paint; | 268 SkPaint paint; |
231 paint.setAntiAlias(true); | 269 paint.setAntiAlias(true); |
232 paint.setColor(color); | 270 paint.setColor(color); |
233 paint.setTypeface(typeface); | 271 paint.setTypeface(typeface); |
234 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 272 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
235 paint.setTextSize(font_size); | 273 paint.setTextSize(font_size); |
274 paint.setSubpixelText(true); | |
236 m_pCanvas->save(); | 275 m_pCanvas->save(); |
237 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); | 276 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); |
238 m_pCanvas->concat(skMatrix); | 277 m_pCanvas->concat(skMatrix); |
239 for (int index = 0; index < nChars; ++index) { | 278 for (int index = 0; index < nChars; ++index) { |
240 const FXTEXT_CHARPOS& cp = pCharPos[index]; | 279 const FXTEXT_CHARPOS& cp = pCharPos[index]; |
241 uint16_t glyph = (uint16_t)cp.m_GlyphIndex; | 280 uint16_t glyph = (uint16_t)cp.m_GlyphIndex; |
242 m_pCanvas->drawText(&glyph, 2, cp.m_OriginX, cp.m_OriginY, paint); | 281 m_pCanvas->drawText(&glyph, 2, cp.m_OriginX, cp.m_OriginY, paint); |
243 } | 282 } |
244 m_pCanvas->restore(); | 283 m_pCanvas->restore(); |
245 return TRUE; | 284 return TRUE; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 377 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
339 int alpha_flag, | 378 int alpha_flag, |
340 void* pIccTransform, | 379 void* pIccTransform, |
341 int blend_type) { | 380 int blend_type) { |
342 SkIRect rect; | 381 SkIRect rect; |
343 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 382 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
344 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 383 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
345 SkPath skPath = BuildPath(pPathData); | 384 SkPath skPath = BuildPath(pPathData); |
346 SkPaint spaint; | 385 SkPaint spaint; |
347 spaint.setAntiAlias(true); | 386 spaint.setAntiAlias(true); |
387 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); | |
348 m_pCanvas->save(); | 388 m_pCanvas->save(); |
349 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | 389 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); |
350 m_pCanvas->concat(skMatrix); | 390 m_pCanvas->concat(skMatrix); |
351 if ((fill_mode & 3) && fill_color) { | 391 if ((fill_mode & 3) && fill_color) { |
352 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING | 392 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
353 ? SkPath::kWinding_FillType | 393 ? SkPath::kWinding_FillType |
354 : SkPath::kEvenOdd_FillType); | 394 : SkPath::kEvenOdd_FillType); |
355 | 395 |
356 spaint.setStyle(SkPaint::kFill_Style); | 396 spaint.setStyle(SkPaint::kFill_Style); |
357 spaint.setColor(fill_color); | 397 spaint.setColor(fill_color); |
(...skipping 15 matching lines...) Expand all Loading... | |
373 } | 413 } |
374 | 414 |
375 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, | 415 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, |
376 FX_DWORD fill_color, | 416 FX_DWORD fill_color, |
377 int alpha_flag, | 417 int alpha_flag, |
378 void* pIccTransform, | 418 void* pIccTransform, |
379 int blend_type) { | 419 int blend_type) { |
380 SkPaint spaint; | 420 SkPaint spaint; |
381 spaint.setAntiAlias(true); | 421 spaint.setAntiAlias(true); |
382 spaint.setColor(fill_color); | 422 spaint.setColor(fill_color); |
423 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); | |
383 | 424 |
384 m_pCanvas->drawRect( | 425 m_pCanvas->drawRect( |
385 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 426 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
386 spaint); | 427 spaint); |
387 return TRUE; | 428 return TRUE; |
388 } | 429 } |
389 | 430 |
390 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 431 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
391 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead | 432 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead |
392 pRect->left = 0; | 433 pRect->left = 0; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 const CFX_Matrix& m = *pMatrix; | 547 const CFX_Matrix& m = *pMatrix; |
507 // note that PDF's y-axis goes up; Skia's y-axis goes down | 548 // note that PDF's y-axis goes up; Skia's y-axis goes down |
508 if (landscape) | 549 if (landscape) |
509 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | 550 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1); |
510 else | 551 else |
511 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1); | 552 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1); |
512 m_pCanvas->concat(skMatrix); | 553 m_pCanvas->concat(skMatrix); |
513 SkPaint paint; | 554 SkPaint paint; |
514 paint.setAntiAlias(true); | 555 paint.setAntiAlias(true); |
515 paint.setFilterQuality(kHigh_SkFilterQuality); | 556 paint.setFilterQuality(kHigh_SkFilterQuality); |
557 paint.setXfermodeMode(GetSkiaBlendMode(blend_type)); | |
558 paint.setAlpha(bitmap_alpha); | |
516 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); | 559 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); |
517 m_pCanvas->restore(); | 560 m_pCanvas->restore(); |
518 return TRUE; | 561 return TRUE; |
519 } | 562 } |
520 | 563 |
521 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { | 564 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
522 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause); | 565 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause); |
523 } | 566 } |
524 | 567 |
525 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { | 568 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 SetDeviceDriver(pDriver); | 617 SetDeviceDriver(pDriver); |
575 return TRUE; | 618 return TRUE; |
576 } | 619 } |
577 | 620 |
578 CFX_SkiaDevice::~CFX_SkiaDevice() { | 621 CFX_SkiaDevice::~CFX_SkiaDevice() { |
579 if (m_bOwnedBitmap && GetBitmap()) | 622 if (m_bOwnedBitmap && GetBitmap()) |
580 delete GetBitmap(); | 623 delete GetBitmap(); |
581 } | 624 } |
582 | 625 |
583 #endif | 626 #endif |
OLD | NEW |