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 #if defined(_SKIA_SUPPORT_) | 5 #ifdef _SKIA_SUPPORT_ |
6 #include <algorithm> | 6 #include <algorithm> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "core/fxcodec/include/fx_codec.h" | 9 #include "core/fxcodec/include/fx_codec.h" |
10 #include "core/fxcrt/include/fx_memory.h" | 10 #include "core/fxcrt/include/fx_memory.h" |
11 | 11 |
12 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" | 12 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" |
13 #include "core/fpdfapi/fpdf_page/pageint.h" | 13 #include "core/fpdfapi/fpdf_page/pageint.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
17 #include "core/fxge/include/cfx_fontcache.h" | 17 #include "core/fxge/include/cfx_fontcache.h" |
18 #endif | |
19 | |
18 #include "core/fxge/include/cfx_fxgedevice.h" | 20 #include "core/fxge/include/cfx_fxgedevice.h" |
21 | |
22 #ifdef _SKIA_SUPPORT_ | |
dsinclair
2016/09/19 20:45:12
Let's consolidate all of these header if's into fe
| |
19 #include "core/fxge/include/cfx_gemodule.h" | 23 #include "core/fxge/include/cfx_gemodule.h" |
24 #endif | |
25 | |
20 #include "core/fxge/include/cfx_graphstatedata.h" | 26 #include "core/fxge/include/cfx_graphstatedata.h" |
21 #include "core/fxge/include/cfx_pathdata.h" | 27 #include "core/fxge/include/cfx_pathdata.h" |
28 | |
29 #ifdef _SKIA_SUPPORT_ | |
22 #include "core/fxge/include/cfx_renderdevice.h" | 30 #include "core/fxge/include/cfx_renderdevice.h" |
31 #else | |
32 #include "core/fxge/ge/cfx_cliprgn.h" | |
33 #endif | |
34 | |
23 #include "core/fxge/skia/fx_skia_device.h" | 35 #include "core/fxge/skia/fx_skia_device.h" |
36 #include "third_party/skia/include/core/SkCanvas.h" | |
24 | 37 |
25 #include "third_party/skia/include/core/SkCanvas.h" | 38 #ifdef _SKIA_SUPPORT_ |
26 #include "third_party/skia/include/core/SkColorFilter.h" | 39 #include "third_party/skia/include/core/SkColorFilter.h" |
27 #include "third_party/skia/include/core/SkColorPriv.h" | 40 #include "third_party/skia/include/core/SkColorPriv.h" |
28 #include "third_party/skia/include/core/SkMaskFilter.h" | 41 #include "third_party/skia/include/core/SkMaskFilter.h" |
42 #endif | |
43 | |
29 #include "third_party/skia/include/core/SkPaint.h" | 44 #include "third_party/skia/include/core/SkPaint.h" |
30 #include "third_party/skia/include/core/SkPath.h" | 45 #include "third_party/skia/include/core/SkPath.h" |
46 | |
47 #ifdef _SKIA_SUPPORT_ | |
31 #include "third_party/skia/include/core/SkPictureRecorder.h" | 48 #include "third_party/skia/include/core/SkPictureRecorder.h" |
32 #include "third_party/skia/include/core/SkShader.h" | 49 #include "third_party/skia/include/core/SkShader.h" |
33 #include "third_party/skia/include/core/SkStream.h" | 50 #include "third_party/skia/include/core/SkStream.h" |
34 #include "third_party/skia/include/core/SkTypeface.h" | 51 #include "third_party/skia/include/core/SkTypeface.h" |
52 #endif | |
53 | |
35 #include "third_party/skia/include/effects/SkDashPathEffect.h" | 54 #include "third_party/skia/include/effects/SkDashPathEffect.h" |
55 | |
56 #ifdef _SKIA_SUPPORT_ | |
36 #include "third_party/skia/include/effects/SkGradientShader.h" | 57 #include "third_party/skia/include/effects/SkGradientShader.h" |
58 #endif | |
59 | |
37 #include "third_party/skia/include/pathops/SkPathOps.h" | 60 #include "third_party/skia/include/pathops/SkPathOps.h" |
38 | 61 |
39 #ifdef SK_DEBUG | 62 #ifdef SK_DEBUG |
40 #include "third_party/skia/include/core/SkClipStack.h" | 63 #include "third_party/skia/include/core/SkClipStack.h" |
41 #endif | 64 #endif |
42 | 65 |
43 namespace { | 66 namespace { |
44 | 67 |
45 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents | 68 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents |
46 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip | 69 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 #else // DRAW_SKIA_CLIP | 111 #else // DRAW_SKIA_CLIP |
89 | 112 |
90 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} | 113 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} |
91 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} | 114 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} |
92 | 115 |
93 #endif // DRAW_SKIA_CLIP | 116 #endif // DRAW_SKIA_CLIP |
94 | 117 |
95 #undef SHOW_SKIA_PATH | 118 #undef SHOW_SKIA_PATH |
96 #undef DRAW_SKIA_CLIP | 119 #undef DRAW_SKIA_CLIP |
97 | 120 |
121 #ifdef _SKIA_SUPPORT_ | |
98 static void DebugValidate(const CFX_DIBitmap* bitmap, | 122 static void DebugValidate(const CFX_DIBitmap* bitmap, |
99 const CFX_DIBitmap* device) { | 123 const CFX_DIBitmap* device) { |
100 if (bitmap) { | 124 if (bitmap) { |
101 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); | 125 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); |
102 if (bitmap->GetBPP() == 32) { | 126 if (bitmap->GetBPP() == 32) { |
103 bitmap->DebugVerifyBitmapIsPreMultiplied(); | 127 bitmap->DebugVerifyBitmapIsPreMultiplied(); |
104 } | 128 } |
105 } | 129 } |
106 if (device) { | 130 if (device) { |
107 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); | 131 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); |
108 if (device->GetBPP() == 32) { | 132 if (device->GetBPP() == 32) { |
109 device->DebugVerifyBitmapIsPreMultiplied(); | 133 device->DebugVerifyBitmapIsPreMultiplied(); |
110 } | 134 } |
111 } | 135 } |
112 } | 136 } |
137 #endif | |
113 | 138 |
114 SkPath BuildPath(const CFX_PathData* pPathData) { | 139 SkPath BuildPath(const CFX_PathData* pPathData) { |
115 SkPath skPath; | 140 SkPath skPath; |
116 const CFX_PathData* pFPath = pPathData; | 141 const CFX_PathData* pFPath = pPathData; |
117 int nPoints = pFPath->GetPointCount(); | 142 int nPoints = pFPath->GetPointCount(); |
118 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 143 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
119 for (int i = 0; i < nPoints; i++) { | 144 for (int i = 0; i < nPoints; i++) { |
120 FX_FLOAT x = pPoints[i].m_PointX; | 145 FX_FLOAT x = pPoints[i].m_PointX; |
121 FX_FLOAT y = pPoints[i].m_PointY; | 146 FX_FLOAT y = pPoints[i].m_PointY; |
122 int point_type = pPoints[i].m_Flag & FXPT_TYPE; | 147 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 case FXDIB_BLEND_COLOR: | 206 case FXDIB_BLEND_COLOR: |
182 return SkXfermode::kColor_Mode; | 207 return SkXfermode::kColor_Mode; |
183 case FXDIB_BLEND_LUMINOSITY: | 208 case FXDIB_BLEND_LUMINOSITY: |
184 return SkXfermode::kLuminosity_Mode; | 209 return SkXfermode::kLuminosity_Mode; |
185 case FXDIB_BLEND_NORMAL: | 210 case FXDIB_BLEND_NORMAL: |
186 default: | 211 default: |
187 return SkXfermode::kSrcOver_Mode; | 212 return SkXfermode::kSrcOver_Mode; |
188 } | 213 } |
189 } | 214 } |
190 | 215 |
216 #ifdef _SKIA_SUPPORT_ | |
191 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { | 217 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { |
192 if (pFunc->CountInputs() != 1) | 218 if (pFunc->CountInputs() != 1) |
193 return false; | 219 return false; |
194 if (pFunc->m_Exponent != 1) | 220 if (pFunc->m_Exponent != 1) |
195 return false; | 221 return false; |
196 if (pFunc->m_nOrigOutputs != 3) | 222 if (pFunc->m_nOrigOutputs != 3) |
197 return false; | 223 return false; |
198 skColors->push( | 224 skColors->push( |
199 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), | 225 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), |
200 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), | 226 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 if (!AddColors(pSubFunc, skColors)) | 296 if (!AddColors(pSubFunc, skColors)) |
271 return false; | 297 return false; |
272 FX_FLOAT boundsEnd = | 298 FX_FLOAT boundsEnd = |
273 i < inputs - 1 ? pFunc->GetBound(i) : pFunc->GetDomain(1); | 299 i < inputs - 1 ? pFunc->GetBound(i) : pFunc->GetDomain(1); |
274 skPos->push(boundsStart); | 300 skPos->push(boundsStart); |
275 skPos->push(boundsEnd); | 301 skPos->push(boundsEnd); |
276 boundsStart = boundsEnd; | 302 boundsStart = boundsEnd; |
277 } | 303 } |
278 return true; | 304 return true; |
279 } | 305 } |
306 #endif | |
280 | 307 |
281 // see https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line | 308 // see https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line |
282 SkScalar LineSide(const SkPoint line[2], const SkPoint& pt) { | 309 SkScalar LineSide(const SkPoint line[2], const SkPoint& pt) { |
283 return (line[1].fY - line[0].fY) * pt.fX - (line[1].fX - line[0].fX) * pt.fY + | 310 return (line[1].fY - line[0].fY) * pt.fX - (line[1].fX - line[0].fX) * pt.fY + |
284 line[1].fX * line[0].fY - line[1].fY * line[0].fX; | 311 line[1].fX * line[0].fY - line[1].fY * line[0].fX; |
285 } | 312 } |
286 | 313 |
287 SkPoint IntersectSides(const SkPoint& parallelPt, | 314 SkPoint IntersectSides(const SkPoint& parallelPt, |
288 const SkVector& paraRay, | 315 const SkVector& paraRay, |
289 const SkPoint& perpendicularPt) { | 316 const SkPoint& perpendicularPt) { |
290 SkVector perpRay = {paraRay.fY, -paraRay.fX}; | 317 SkVector perpRay = {paraRay.fY, -paraRay.fX}; |
291 SkScalar denom = perpRay.fY * paraRay.fX - paraRay.fY * perpRay.fX; | 318 SkScalar denom = perpRay.fY * paraRay.fX - paraRay.fY * perpRay.fX; |
292 if (!denom) { | 319 if (!denom) { |
293 SkPoint zeroPt = {0, 0}; | 320 SkPoint zeroPt = {0, 0}; |
294 return zeroPt; | 321 return zeroPt; |
295 } | 322 } |
296 SkVector ab0 = parallelPt - perpendicularPt; | 323 SkVector ab0 = parallelPt - perpendicularPt; |
297 SkScalar numerA = ab0.fY * perpRay.fX - perpRay.fY * ab0.fX; | 324 SkScalar numerA = ab0.fY * perpRay.fX - perpRay.fY * ab0.fX; |
298 numerA /= denom; | 325 numerA /= denom; |
299 SkPoint result = {parallelPt.fX + paraRay.fX * numerA, | 326 SkPoint result = {parallelPt.fX + paraRay.fX * numerA, |
300 parallelPt.fY + paraRay.fY * numerA}; | 327 parallelPt.fY + paraRay.fY * numerA}; |
301 return result; | 328 return result; |
302 } | 329 } |
303 | 330 |
331 #ifdef _SKIA_SUPPORT_ | |
304 void ClipAngledGradient(const SkPoint pts[2], | 332 void ClipAngledGradient(const SkPoint pts[2], |
305 SkPoint rectPts[4], | 333 SkPoint rectPts[4], |
306 bool clipStart, | 334 bool clipStart, |
307 bool clipEnd, | 335 bool clipEnd, |
308 SkPath* clip) { | 336 SkPath* clip) { |
309 // find the corners furthest from the gradient perpendiculars | 337 // find the corners furthest from the gradient perpendiculars |
310 SkScalar minPerpDist = SK_ScalarMax; | 338 SkScalar minPerpDist = SK_ScalarMax; |
311 SkScalar maxPerpDist = SK_ScalarMin; | 339 SkScalar maxPerpDist = SK_ScalarMin; |
312 int minPerpPtIndex = -1; | 340 int minPerpPtIndex = -1; |
313 int maxPerpPtIndex = -1; | 341 int maxPerpPtIndex = -1; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 colorType = SkColorType::kUnknown_SkColorType; | 492 colorType = SkColorType::kUnknown_SkColorType; |
465 } | 493 } |
466 SkImageInfo imageInfo = | 494 SkImageInfo imageInfo = |
467 SkImageInfo::Make(width, height, colorType, alphaType); | 495 SkImageInfo::Make(width, height, colorType, alphaType); |
468 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, | 496 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, |
469 nullptr); | 497 nullptr); |
470 *widthPtr = width; | 498 *widthPtr = width; |
471 *heightPtr = height; | 499 *heightPtr = height; |
472 return true; | 500 return true; |
473 } | 501 } |
502 #else | |
503 | |
504 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, | |
505 int dest_left, | |
506 int dest_top, | |
507 int width, | |
508 int height, | |
509 const CFX_DIBSource* pSrcBitmap, | |
510 int src_left, | |
511 int src_top) { | |
512 if (!pBitmap) | |
513 return; | |
514 | |
515 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, | |
516 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), | |
517 src_left, src_top, nullptr); | |
518 if (width == 0 || height == 0) | |
519 return; | |
520 | |
521 int Bpp = pBitmap->GetBPP() / 8; | |
522 FXDIB_Format dest_format = pBitmap->GetFormat(); | |
523 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | |
524 int pitch = pBitmap->GetPitch(); | |
525 uint8_t* buffer = pBitmap->GetBuffer(); | |
526 if (dest_format == src_format) { | |
527 for (int row = 0; row < height; row++) { | |
528 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; | |
529 uint8_t* src_scan = | |
530 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; | |
531 if (Bpp == 4) { | |
532 for (int col = 0; col < width; col++) { | |
533 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], | |
534 src_scan[1], src_scan[2])); | |
535 dest_scan += 4; | |
536 src_scan += 4; | |
537 } | |
538 } else { | |
539 for (int col = 0; col < width; col++) { | |
540 *dest_scan++ = src_scan[2]; | |
541 *dest_scan++ = src_scan[1]; | |
542 *dest_scan++ = src_scan[0]; | |
543 src_scan += 3; | |
544 } | |
545 } | |
546 } | |
547 return; | |
548 } | |
549 } | |
550 | |
551 #endif | |
474 | 552 |
475 } // namespace | 553 } // namespace |
476 | 554 |
477 // Encapsulate the state used for successive text and path draws so that | 555 // Encapsulate the state used for successive text and path draws so that |
478 // they can be combined. | 556 // they can be combined. |
479 class SkiaState { | 557 class SkiaState { |
480 public: | 558 public: |
481 enum class Clip { | 559 enum class Clip { |
482 kSave, | 560 kSave, |
483 kPath, | 561 kPath, |
(...skipping 18 matching lines...) Expand all Loading... | |
502 const CFX_GraphStateData* pDrawState, | 580 const CFX_GraphStateData* pDrawState, |
503 uint32_t fill_color, | 581 uint32_t fill_color, |
504 uint32_t stroke_color, | 582 uint32_t stroke_color, |
505 int fill_mode, | 583 int fill_mode, |
506 int blend_type, | 584 int blend_type, |
507 CFX_SkiaDeviceDriver* pDriver) { | 585 CFX_SkiaDeviceDriver* pDriver) { |
508 if (m_debugDisable) | 586 if (m_debugDisable) |
509 return false; | 587 return false; |
510 if (m_commandIndex < m_commands.count()) | 588 if (m_commandIndex < m_commands.count()) |
511 FlushCommands(pDriver); | 589 FlushCommands(pDriver); |
590 #if _SKIA_SUPPORT_ | |
512 if (m_drawText) | 591 if (m_drawText) |
513 FlushText(pDriver); | 592 FlushText(pDriver); |
593 #endif | |
514 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, | 594 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, |
515 fill_mode, blend_type)) { | 595 fill_mode, blend_type)) { |
516 FlushPath(pDriver); | 596 FlushPath(pDriver); |
517 } | 597 } |
518 if (!m_drawPath) { | 598 if (!m_drawPath) { |
519 m_skPath.reset(); | 599 m_skPath.reset(); |
520 m_fillPath = (fill_mode & 3) && fill_color; | 600 m_fillPath = (fill_mode & 3) && fill_color; |
521 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 601 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
522 ? SkPath::kEvenOdd_FillType | 602 ? SkPath::kEvenOdd_FillType |
523 : SkPath::kWinding_FillType); | 603 : SkPath::kWinding_FillType); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 DebugShowSkiaPath(m_skPath); | 650 DebugShowSkiaPath(m_skPath); |
571 DebugShowCanvasMatrix(skCanvas); | 651 DebugShowCanvasMatrix(skCanvas); |
572 skPaint.setStyle(SkPaint::kStroke_Style); | 652 skPaint.setStyle(SkPaint::kStroke_Style); |
573 skPaint.setColor(m_strokeColor); | 653 skPaint.setColor(m_strokeColor); |
574 skCanvas->drawPath(m_skPath, skPaint); | 654 skCanvas->drawPath(m_skPath, skPaint); |
575 } | 655 } |
576 skCanvas->restore(); | 656 skCanvas->restore(); |
577 m_drawPath = false; | 657 m_drawPath = false; |
578 } | 658 } |
579 | 659 |
660 #ifdef _SKIA_SUPPORT_ | |
580 bool DrawText(int nChars, | 661 bool DrawText(int nChars, |
581 const FXTEXT_CHARPOS* pCharPos, | 662 const FXTEXT_CHARPOS* pCharPos, |
582 CFX_Font* pFont, | 663 CFX_Font* pFont, |
583 CFX_FontCache* pCache, | 664 CFX_FontCache* pCache, |
584 const CFX_Matrix* pMatrix, | 665 const CFX_Matrix* pMatrix, |
585 FX_FLOAT font_size, | 666 FX_FLOAT font_size, |
586 uint32_t color, | 667 uint32_t color, |
587 CFX_SkiaDeviceDriver* pDriver) { | 668 CFX_SkiaDeviceDriver* pDriver) { |
588 if (m_debugDisable) | 669 if (m_debugDisable) |
589 return false; | 670 return false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 skPaint.setSubpixelText(true); | 716 skPaint.setSubpixelText(true); |
636 skPaint.setHinting(SkPaint::kNo_Hinting); | 717 skPaint.setHinting(SkPaint::kNo_Hinting); |
637 SkCanvas* skCanvas = pDriver->SkiaCanvas(); | 718 SkCanvas* skCanvas = pDriver->SkiaCanvas(); |
638 skCanvas->save(); | 719 skCanvas->save(); |
639 skCanvas->concat(skMatrix); | 720 skCanvas->concat(skMatrix); |
640 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, | 721 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, |
641 m_positions.begin(), skPaint); | 722 m_positions.begin(), skPaint); |
642 skCanvas->restore(); | 723 skCanvas->restore(); |
643 m_drawText = false; | 724 m_drawText = false; |
644 } | 725 } |
726 #endif | |
645 | 727 |
646 bool SetClipFill(const CFX_PathData* pPathData, | 728 bool SetClipFill(const CFX_PathData* pPathData, |
647 const CFX_Matrix* pMatrix, | 729 const CFX_Matrix* pMatrix, |
648 int fill_mode, | 730 int fill_mode, |
649 CFX_SkiaDeviceDriver* pDriver) { | 731 CFX_SkiaDeviceDriver* pDriver) { |
650 if (m_debugDisable) | 732 if (m_debugDisable) |
651 return false; | 733 return false; |
652 SkPath skClipPath = BuildPath(pPathData); | 734 SkPath skClipPath = BuildPath(pPathData); |
653 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 735 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
654 ? SkPath::kEvenOdd_FillType | 736 ? SkPath::kEvenOdd_FillType |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 for (int index = 0; index < pState->m_DashCount; ++index) { | 908 for (int index = 0; index < pState->m_DashCount; ++index) { |
827 if (pState->m_DashArray[index] != refState.m_DashArray[index]) | 909 if (pState->m_DashArray[index] != refState.m_DashArray[index]) |
828 return false; | 910 return false; |
829 } | 911 } |
830 return true; | 912 return true; |
831 } | 913 } |
832 | 914 |
833 void Flush(CFX_SkiaDeviceDriver* pDriver) { | 915 void Flush(CFX_SkiaDeviceDriver* pDriver) { |
834 if (m_drawPath) | 916 if (m_drawPath) |
835 FlushPath(pDriver); | 917 FlushPath(pDriver); |
918 #ifdef _SKIA_SUPPORT_ | |
836 if (m_drawText) | 919 if (m_drawText) |
837 FlushText(pDriver); | 920 FlushText(pDriver); |
921 #endif | |
838 } | 922 } |
839 | 923 |
840 #ifdef SK_DEBUG | 924 #ifdef SK_DEBUG |
841 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { | 925 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { |
842 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); | 926 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); |
843 pDriver->m_pCanvas->getClipStack()->dump(); | 927 pDriver->m_pCanvas->getClipStack()->dump(); |
844 SkDebugf("Cache:\n"); | 928 SkDebugf("Cache:\n"); |
845 for (int index = 0; index < m_commands.count(); ++index) { | 929 for (int index = 0; index < m_commands.count(); ++index) { |
846 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); | 930 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); |
847 switch (m_commands[index]) { | 931 switch (m_commands[index]) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
965 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, | 1049 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, |
966 kOpaque_SkAlphaType); | 1050 kOpaque_SkAlphaType); |
967 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), | 1051 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), |
968 nullptr, /* to do : set color table */ | 1052 nullptr, /* to do : set color table */ |
969 nullptr, nullptr); | 1053 nullptr, nullptr); |
970 m_pCanvas = new SkCanvas(skBitmap); | 1054 m_pCanvas = new SkCanvas(skBitmap); |
971 if (m_bGroupKnockout) | 1055 if (m_bGroupKnockout) |
972 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' | 1056 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' |
973 } | 1057 } |
974 | 1058 |
1059 #ifdef _SKIA_SUPPORT_ | |
975 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) | 1060 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) |
976 : m_pBitmap(nullptr), | 1061 : m_pBitmap(nullptr), |
977 m_pOriDevice(nullptr), | 1062 m_pOriDevice(nullptr), |
978 m_pRecorder(new SkPictureRecorder), | 1063 m_pRecorder(new SkPictureRecorder), |
979 m_pCache(new SkiaState), | 1064 m_pCache(new SkiaState), |
980 m_bGroupKnockout(FALSE) { | 1065 m_bGroupKnockout(FALSE) { |
981 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); | 1066 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); |
982 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 1067 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
983 } | 1068 } |
984 | 1069 |
985 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) | 1070 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) |
986 : m_pBitmap(nullptr), | 1071 : m_pBitmap(nullptr), |
987 m_pOriDevice(nullptr), | 1072 m_pOriDevice(nullptr), |
988 m_pRecorder(recorder), | 1073 m_pRecorder(recorder), |
989 m_pCache(new SkiaState), | 1074 m_pCache(new SkiaState), |
990 m_bGroupKnockout(FALSE) { | 1075 m_bGroupKnockout(FALSE) { |
991 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 1076 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
992 } | 1077 } |
1078 #endif | |
993 | 1079 |
994 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 1080 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
995 Flush(); | 1081 Flush(); |
996 if (!m_pRecorder) | 1082 if (!m_pRecorder) |
997 delete m_pCanvas; | 1083 delete m_pCanvas; |
998 } | 1084 } |
999 | 1085 |
1000 void CFX_SkiaDeviceDriver::Flush() { | 1086 void CFX_SkiaDeviceDriver::Flush() { |
1001 m_pCache->Flush(this); | 1087 m_pCache->Flush(this); |
1002 m_pCache->FlushCommands(this); | 1088 m_pCache->FlushCommands(this); |
1003 } | 1089 } |
1004 | 1090 |
1005 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 1091 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
1006 const FXTEXT_CHARPOS* pCharPos, | 1092 const FXTEXT_CHARPOS* pCharPos, |
1007 CFX_Font* pFont, | 1093 CFX_Font* pFont, |
1008 CFX_FontCache* pCache, | 1094 CFX_FontCache* pCache, |
1009 const CFX_Matrix* pObject2Device, | 1095 const CFX_Matrix* pObject2Device, |
1010 FX_FLOAT font_size, | 1096 FX_FLOAT font_size, |
1011 uint32_t color) { | 1097 uint32_t color) { |
1098 #ifdef _SKIA_SUPPORT_ | |
1012 if (!pCache) | 1099 if (!pCache) |
1013 pCache = CFX_GEModule::Get()->GetFontCache(); | 1100 pCache = CFX_GEModule::Get()->GetFontCache(); |
1014 if (m_pCache->DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, | 1101 if (m_pCache->DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, |
1015 font_size, color, this)) { | 1102 font_size, color, this)) { |
1016 return TRUE; | 1103 return TRUE; |
1017 } | 1104 } |
1018 sk_sp<SkTypeface> typeface( | 1105 sk_sp<SkTypeface> typeface( |
1019 SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr)); | 1106 SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr)); |
1020 SkPaint paint; | 1107 SkPaint paint; |
1021 paint.setAntiAlias(true); | 1108 paint.setAntiAlias(true); |
(...skipping 12 matching lines...) Expand all Loading... | |
1034 SkTDArray<uint16_t> glyphs; | 1121 SkTDArray<uint16_t> glyphs; |
1035 glyphs.setCount(nChars); | 1122 glyphs.setCount(nChars); |
1036 for (int index = 0; index < nChars; ++index) { | 1123 for (int index = 0; index < nChars; ++index) { |
1037 const FXTEXT_CHARPOS& cp = pCharPos[index]; | 1124 const FXTEXT_CHARPOS& cp = pCharPos[index]; |
1038 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; | 1125 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; |
1039 glyphs[index] = (uint16_t)cp.m_GlyphIndex; | 1126 glyphs[index] = (uint16_t)cp.m_GlyphIndex; |
1040 } | 1127 } |
1041 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); | 1128 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); |
1042 m_pCanvas->restore(); | 1129 m_pCanvas->restore(); |
1043 return TRUE; | 1130 return TRUE; |
1131 #else | |
1132 return FALSE; | |
1133 #endif | |
1044 } | 1134 } |
1045 | 1135 |
1046 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { | 1136 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { |
1047 switch (caps_id) { | 1137 switch (caps_id) { |
1048 case FXDC_DEVICE_CLASS: | 1138 case FXDC_DEVICE_CLASS: |
1049 return FXDC_DISPLAY; | 1139 return FXDC_DISPLAY; |
1050 case FXDC_PIXEL_WIDTH: | 1140 case FXDC_PIXEL_WIDTH: |
1051 return m_pCanvas->imageInfo().width(); | 1141 return m_pCanvas->imageInfo().width(); |
1052 case FXDC_PIXEL_HEIGHT: | 1142 case FXDC_PIXEL_HEIGHT: |
1053 return m_pCanvas->imageInfo().height(); | 1143 return m_pCanvas->imageInfo().height(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 spaint.setAntiAlias(true); | 1298 spaint.setAntiAlias(true); |
1209 spaint.setColor(fill_color); | 1299 spaint.setColor(fill_color); |
1210 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); | 1300 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); |
1211 | 1301 |
1212 m_pCanvas->drawRect( | 1302 m_pCanvas->drawRect( |
1213 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 1303 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
1214 spaint); | 1304 spaint); |
1215 return TRUE; | 1305 return TRUE; |
1216 } | 1306 } |
1217 | 1307 |
1308 #ifdef _SKIA_SUPPORT_ | |
1218 FX_BOOL CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, | 1309 FX_BOOL CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, |
1219 const CFX_Matrix* pMatrix, | 1310 const CFX_Matrix* pMatrix, |
1220 const FX_RECT& clip_rect, | 1311 const FX_RECT& clip_rect, |
1221 int alpha, | 1312 int alpha, |
1222 FX_BOOL bAlphaMode) { | 1313 FX_BOOL bAlphaMode) { |
1223 if (kAxialShading != pPattern->GetShadingType() && | 1314 if (kAxialShading != pPattern->GetShadingType() && |
1224 kRadialShading != pPattern->GetShadingType()) { | 1315 kRadialShading != pPattern->GetShadingType()) { |
1225 // TODO(caryclark) more types | 1316 // TODO(caryclark) more types |
1226 return false; | 1317 return false; |
1227 } | 1318 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1341 skPath.transform(inverse); | 1432 skPath.transform(inverse); |
1342 } | 1433 } |
1343 m_pCanvas->save(); | 1434 m_pCanvas->save(); |
1344 if (!skClip.isEmpty()) | 1435 if (!skClip.isEmpty()) |
1345 m_pCanvas->clipPath(skClip, SkRegion::kIntersect_Op, true); | 1436 m_pCanvas->clipPath(skClip, SkRegion::kIntersect_Op, true); |
1346 m_pCanvas->concat(skMatrix); | 1437 m_pCanvas->concat(skMatrix); |
1347 m_pCanvas->drawPath(skPath, paint); | 1438 m_pCanvas->drawPath(skPath, paint); |
1348 m_pCanvas->restore(); | 1439 m_pCanvas->restore(); |
1349 return true; | 1440 return true; |
1350 } | 1441 } |
1442 #endif | |
1351 | 1443 |
1352 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { | 1444 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { |
1353 return m_pBitmap->GetBuffer(); | 1445 return m_pBitmap->GetBuffer(); |
1354 } | 1446 } |
1355 | 1447 |
1356 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 1448 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
1357 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead | 1449 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead |
1358 pRect->left = 0; | 1450 pRect->left = 0; |
1359 pRect->top = 0; | 1451 pRect->top = 0; |
1360 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 1452 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
1361 pRect->right = canvasSize.width(); | 1453 pRect->right = canvasSize.width(); |
1362 pRect->bottom = canvasSize.height(); | 1454 pRect->bottom = canvasSize.height(); |
1363 return TRUE; | 1455 return TRUE; |
1364 } | 1456 } |
1365 | 1457 |
1366 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 1458 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
1367 int left, | 1459 int left, |
1368 int top) { | 1460 int top) { |
1369 if (!m_pBitmap) | 1461 if (!m_pBitmap) |
1370 return TRUE; | 1462 return TRUE; |
1371 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); | 1463 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); |
1372 if (!srcBuffer) | 1464 if (!srcBuffer) |
1373 return TRUE; | 1465 return TRUE; |
1466 #ifdef _SKIA_SUPPORT_ | |
1374 int srcWidth = m_pBitmap->GetWidth(); | 1467 int srcWidth = m_pBitmap->GetWidth(); |
1375 int srcHeight = m_pBitmap->GetHeight(); | 1468 int srcHeight = m_pBitmap->GetHeight(); |
1376 int srcRowBytes = srcWidth * sizeof(uint32_t); | 1469 int srcRowBytes = srcWidth * sizeof(uint32_t); |
1377 SkImageInfo srcImageInfo = SkImageInfo::Make( | 1470 SkImageInfo srcImageInfo = SkImageInfo::Make( |
1378 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1471 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1379 SkBitmap skSrcBitmap; | 1472 SkBitmap skSrcBitmap; |
1380 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, | 1473 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, |
1381 nullptr, nullptr); | 1474 nullptr, nullptr); |
1382 SkASSERT(pBitmap); | 1475 SkASSERT(pBitmap); |
1383 uint8_t* dstBuffer = pBitmap->GetBuffer(); | 1476 uint8_t* dstBuffer = pBitmap->GetBuffer(); |
1384 SkASSERT(dstBuffer); | 1477 SkASSERT(dstBuffer); |
1385 int dstWidth = pBitmap->GetWidth(); | 1478 int dstWidth = pBitmap->GetWidth(); |
1386 int dstHeight = pBitmap->GetHeight(); | 1479 int dstHeight = pBitmap->GetHeight(); |
1387 int dstRowBytes = dstWidth * sizeof(uint32_t); | 1480 int dstRowBytes = dstWidth * sizeof(uint32_t); |
1388 SkImageInfo dstImageInfo = SkImageInfo::Make( | 1481 SkImageInfo dstImageInfo = SkImageInfo::Make( |
1389 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1482 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1390 SkBitmap skDstBitmap; | 1483 SkBitmap skDstBitmap; |
1391 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, | 1484 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, |
1392 nullptr, nullptr); | 1485 nullptr, nullptr); |
1393 SkCanvas canvas(skDstBitmap); | 1486 SkCanvas canvas(skDstBitmap); |
1394 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); | 1487 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); |
1395 return TRUE; | 1488 return TRUE; |
1489 #else | |
1490 FX_RECT rect(left, top, left + pBitmap->GetWidth(), | |
1491 top + pBitmap->GetHeight()); | |
1492 CFX_DIBitmap* pBack = nullptr; | |
1493 if (m_pOriDevice) { | |
1494 pBack = m_pOriDevice->Clone(&rect); | |
1495 if (!pBack) | |
1496 return TRUE; | |
1497 | |
1498 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), | |
1499 m_pBitmap, 0, 0); | |
1500 } else { | |
1501 pBack = m_pBitmap->Clone(&rect); | |
1502 if (!pBack) | |
1503 return TRUE; | |
1504 } | |
1505 | |
1506 FX_BOOL bRet = TRUE; | |
1507 left = std::min(left, 0); | |
1508 top = std::min(top, 0); | |
1509 if (m_bRgbByteOrder) { | |
1510 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), | |
1511 pBack, left, top); | |
1512 } else { | |
1513 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, | |
1514 left, top); | |
1515 } | |
1516 delete pBack; | |
1517 return bRet; | |
1518 #endif | |
1396 } | 1519 } |
1397 | 1520 |
1398 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { | 1521 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { |
1399 return m_pOriDevice; | 1522 return m_pOriDevice; |
1400 } | 1523 } |
1401 | 1524 |
1402 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 1525 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
1403 uint32_t argb, | 1526 uint32_t argb, |
1404 const FX_RECT* pSrcRect, | 1527 const FX_RECT* pSrcRect, |
1405 int left, | 1528 int left, |
1406 int top, | 1529 int top, |
1407 int blend_type) { | 1530 int blend_type) { |
1408 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1531 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1409 return TRUE; | 1532 return TRUE; |
1410 | 1533 |
1534 #ifdef _SKIA_SUPPORT | |
1411 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, | 1535 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
1412 top + pBitmap->GetHeight()); | 1536 top + pBitmap->GetHeight()); |
1413 void* dummy; | 1537 void* dummy; |
1414 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); | 1538 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
1539 #else | |
1540 if (pBitmap->IsAlphaMask()) { | |
1541 return m_pBitmap->CompositeMask( | |
1542 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, | |
1543 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(), | |
1544 m_bRgbByteOrder, 0, nullptr); | |
1545 } | |
1546 return m_pBitmap->CompositeBitmap( | |
1547 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, | |
1548 pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); | |
1549 #endif | |
1415 } | 1550 } |
1416 | 1551 |
1417 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 1552 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
1418 uint32_t argb, | 1553 uint32_t argb, |
1419 int dest_left, | 1554 int dest_left, |
1420 int dest_top, | 1555 int dest_top, |
1421 int dest_width, | 1556 int dest_width, |
1422 int dest_height, | 1557 int dest_height, |
1423 const FX_RECT* pClipRect, | 1558 const FX_RECT* pClipRect, |
1424 uint32_t flags, | 1559 uint32_t flags, |
1425 int blend_type) { | 1560 int blend_type) { |
1561 #ifdef _SKIA_SUPPORT | |
1426 if (!m_pBitmap->GetBuffer()) | 1562 if (!m_pBitmap->GetBuffer()) |
1427 return TRUE; | 1563 return TRUE; |
1428 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, | 1564 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
1429 dest_top + dest_height); | 1565 dest_top + dest_height); |
1430 | 1566 |
1431 m_pCanvas->save(); | 1567 m_pCanvas->save(); |
1432 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, | 1568 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, |
1433 pClipRect->right, pClipRect->top); | 1569 pClipRect->right, pClipRect->top); |
1434 m_pCanvas->clipRect(skClipRect, SkRegion::kIntersect_Op, true); | 1570 m_pCanvas->clipRect(skClipRect, SkRegion::kIntersect_Op, true); |
1435 void* dummy; | 1571 void* dummy; |
1436 FX_BOOL result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); | 1572 FX_BOOL result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); |
1437 m_pCanvas->restore(); | 1573 m_pCanvas->restore(); |
1438 | 1574 |
1439 return result; | 1575 return result; |
1576 #else | |
1577 if (dest_width == pSource->GetWidth() && | |
1578 dest_height == pSource->GetHeight()) { | |
1579 FX_RECT rect(0, 0, dest_width, dest_height); | |
1580 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type); | |
1581 } | |
1582 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, | |
1583 dest_top + dest_height); | |
1584 dest_rect.Normalize(); | |
1585 FX_RECT dest_clip = dest_rect; | |
1586 dest_clip.Intersect(*pClipRect); | |
1587 CFX_BitmapComposer composer; | |
1588 composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, FALSE, | |
1589 FALSE, FALSE, m_bRgbByteOrder, 0, nullptr, blend_type); | |
1590 dest_clip.Offset(-dest_rect.left, -dest_rect.top); | |
1591 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, | |
1592 dest_clip, flags); | |
1593 if (stretcher.Start()) | |
1594 stretcher.Continue(nullptr); | |
1595 return TRUE; | |
1596 #endif | |
1440 } | 1597 } |
1441 | 1598 |
1442 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 1599 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1443 int bitmap_alpha, | 1600 int bitmap_alpha, |
1444 uint32_t argb, | 1601 uint32_t argb, |
1445 const CFX_Matrix* pMatrix, | 1602 const CFX_Matrix* pMatrix, |
1446 uint32_t render_flags, | 1603 uint32_t render_flags, |
1447 void*& handle, | 1604 void*& handle, |
1448 int blend_type) { | 1605 int blend_type) { |
1606 #ifdef _SKIA_SUPPORT | |
1449 DebugValidate(m_pBitmap, m_pOriDevice); | 1607 DebugValidate(m_pBitmap, m_pOriDevice); |
1450 SkColorTable* ct = nullptr; | 1608 SkColorTable* ct = nullptr; |
1451 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1609 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
1452 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; | 1610 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; |
1453 SkBitmap skBitmap; | 1611 SkBitmap skBitmap; |
1454 int width, height; | 1612 int width, height; |
1455 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, | 1613 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, |
1456 &height, false)) { | 1614 &height, false)) { |
1457 return FALSE; | 1615 return FALSE; |
1458 } | 1616 } |
(...skipping 19 matching lines...) Expand all Loading... | |
1478 } | 1636 } |
1479 } | 1637 } |
1480 } else { | 1638 } else { |
1481 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); | 1639 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); |
1482 } | 1640 } |
1483 m_pCanvas->restore(); | 1641 m_pCanvas->restore(); |
1484 if (ct) | 1642 if (ct) |
1485 ct->unref(); | 1643 ct->unref(); |
1486 DebugValidate(m_pBitmap, m_pOriDevice); | 1644 DebugValidate(m_pBitmap, m_pOriDevice); |
1487 return TRUE; | 1645 return TRUE; |
1646 #else | |
1647 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; | |
1648 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, | |
1649 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); | |
1650 handle = pRenderer; | |
1651 return TRUE; | |
1652 #endif | |
1488 } | 1653 } |
1489 | 1654 |
1490 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { | 1655 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
1656 #ifdef _SKIA_SUPPORT | |
1491 return FALSE; | 1657 return FALSE; |
1658 #else | |
1659 if (!m_pBitmap->GetBuffer()) { | |
1660 return TRUE; | |
1661 } | |
1662 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); | |
dsinclair
2016/09/19 20:45:12
nit: static_cast.
| |
1663 #endif | |
1492 } | 1664 } |
1493 | 1665 |
1666 #ifdef _SKIA_SUPPORT | |
1494 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { | 1667 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { |
1495 void* buffer = pDIBitmap->GetBuffer(); | 1668 void* buffer = pDIBitmap->GetBuffer(); |
1496 if (!buffer) | 1669 if (!buffer) |
1497 return; | 1670 return; |
1498 if (pDIBitmap->GetBPP() != 32) { | 1671 if (pDIBitmap->GetBPP() != 32) { |
1499 return; | 1672 return; |
1500 } | 1673 } |
1501 int height = pDIBitmap->GetHeight(); | 1674 int height = pDIBitmap->GetHeight(); |
1502 int width = pDIBitmap->GetWidth(); | 1675 int width = pDIBitmap->GetWidth(); |
1503 int rowBytes = pDIBitmap->GetPitch(); | 1676 int rowBytes = pDIBitmap->GetPitch(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1565 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1738 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1566 return true; | 1739 return true; |
1567 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, | 1740 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, |
1568 dest_top + pBitmap->GetHeight()); | 1741 dest_top + pBitmap->GetHeight()); |
1569 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); | 1742 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); |
1570 } | 1743 } |
1571 | 1744 |
1572 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { | 1745 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { |
1573 m_pCanvas->clear(color); | 1746 m_pCanvas->clear(color); |
1574 } | 1747 } |
1748 #endif | |
1575 | 1749 |
1576 void CFX_SkiaDeviceDriver::Dump() const { | 1750 void CFX_SkiaDeviceDriver::Dump() const { |
1577 #ifdef SK_DEBUG | 1751 #ifdef SK_DEBUG |
1578 if (m_pCache) | 1752 if (m_pCache) |
1579 m_pCache->Dump(this); | 1753 m_pCache->Dump(this); |
1580 #endif | 1754 #endif |
1581 } | 1755 } |
1582 | 1756 |
1757 #ifdef _SKIA_SUPPORT_ | |
1583 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { | 1758 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { |
1584 if (m_pOriDevice) | 1759 if (m_pOriDevice) |
1585 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); | 1760 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); |
1586 } | 1761 } |
1762 #endif | |
1587 | 1763 |
1588 CFX_FxgeDevice::CFX_FxgeDevice() { | 1764 CFX_FxgeDevice::CFX_FxgeDevice() { |
1765 #ifdef _SKIA_SUPPORT_ | |
1589 m_bOwnedBitmap = FALSE; | 1766 m_bOwnedBitmap = FALSE; |
1767 #endif | |
1590 } | 1768 } |
1591 | 1769 |
1770 #ifdef _SKIA_SUPPORT_ | |
1592 void CFX_FxgeDevice::Clear(uint32_t color) { | 1771 void CFX_FxgeDevice::Clear(uint32_t color) { |
1593 CFX_SkiaDeviceDriver* skDriver = | 1772 CFX_SkiaDeviceDriver* skDriver = |
1594 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1773 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1595 skDriver->Clear(color); | 1774 skDriver->Clear(color); |
1596 } | 1775 } |
1597 | 1776 |
1598 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { | 1777 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { |
1599 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); | 1778 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); |
1600 SetDeviceDriver(WrapUnique(skDriver)); | 1779 SetDeviceDriver(WrapUnique(skDriver)); |
1601 return skDriver->GetRecorder(); | 1780 return skDriver->GetRecorder(); |
1602 } | 1781 } |
1782 #endif | |
1603 | 1783 |
1604 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, | 1784 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, |
1605 bool bRgbByteOrder, | 1785 bool bRgbByteOrder, |
1606 CFX_DIBitmap* pOriDevice, | 1786 CFX_DIBitmap* pOriDevice, |
1607 bool bGroupKnockout) { | 1787 bool bGroupKnockout) { |
1608 if (!pBitmap) | 1788 if (!pBitmap) |
1609 return false; | 1789 return false; |
1610 SetBitmap(pBitmap); | 1790 SetBitmap(pBitmap); |
1611 SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver( | 1791 SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver( |
1612 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); | 1792 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); |
1613 return true; | 1793 return true; |
1614 } | 1794 } |
1615 | 1795 |
1796 #ifdef _SKIA_SUPPORT_ | |
1616 bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { | 1797 bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { |
1617 if (!recorder) | 1798 if (!recorder) |
1618 return false; | 1799 return false; |
1619 SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver(recorder))); | 1800 SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver(recorder))); |
1620 return true; | 1801 return true; |
1621 } | 1802 } |
1803 #endif | |
1622 | 1804 |
1623 bool CFX_FxgeDevice::Create(int width, | 1805 bool CFX_FxgeDevice::Create(int width, |
1624 int height, | 1806 int height, |
1625 FXDIB_Format format, | 1807 FXDIB_Format format, |
1626 CFX_DIBitmap* pOriDevice) { | 1808 CFX_DIBitmap* pOriDevice) { |
1627 m_bOwnedBitmap = TRUE; | 1809 m_bOwnedBitmap = TRUE; |
1628 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 1810 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
1629 if (!pBitmap->Create(width, height, format)) { | 1811 if (!pBitmap->Create(width, height, format)) { |
1630 delete pBitmap; | 1812 delete pBitmap; |
1631 return false; | 1813 return false; |
1632 } | 1814 } |
1633 SetBitmap(pBitmap); | 1815 SetBitmap(pBitmap); |
1634 SetDeviceDriver( | 1816 SetDeviceDriver( |
1635 WrapUnique(new CFX_SkiaDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE))); | 1817 WrapUnique(new CFX_SkiaDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE))); |
1636 return true; | 1818 return true; |
1637 } | 1819 } |
1638 | 1820 |
1639 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1821 CFX_FxgeDevice::~CFX_FxgeDevice() { |
1822 #ifdef _SKIA_SUPPORT_ | |
1640 Flush(); | 1823 Flush(); |
1641 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately | 1824 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately |
1642 if (m_bOwnedBitmap && GetBitmap()) | 1825 if (m_bOwnedBitmap && GetBitmap()) |
1643 delete GetBitmap(); | 1826 delete GetBitmap(); |
1827 #endif | |
1644 } | 1828 } |
1645 | 1829 |
1830 #ifdef _SKIA_SUPPORT_ | |
1646 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { | 1831 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { |
1647 #ifdef SK_DEBUG | 1832 #ifdef SK_DEBUG |
1648 CFX_SkiaDeviceDriver* skDriver = | 1833 CFX_SkiaDeviceDriver* skDriver = |
1649 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1834 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1650 if (skDriver) | 1835 if (skDriver) |
1651 skDriver->DebugVerifyBitmapIsPreMultiplied(); | 1836 skDriver->DebugVerifyBitmapIsPreMultiplied(); |
1652 #endif | 1837 #endif |
1653 } | 1838 } |
1654 | 1839 |
1655 bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, | 1840 bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, |
(...skipping 27 matching lines...) Expand all Loading... | |
1683 SkA32Assert(a); | 1868 SkA32Assert(a); |
1684 SkASSERT(r <= a); | 1869 SkASSERT(r <= a); |
1685 SkASSERT(g <= a); | 1870 SkASSERT(g <= a); |
1686 SkASSERT(b <= a); | 1871 SkASSERT(b <= a); |
1687 } | 1872 } |
1688 } | 1873 } |
1689 #endif | 1874 #endif |
1690 } | 1875 } |
1691 | 1876 |
1692 #endif | 1877 #endif |
OLD | NEW |