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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "core/fxcodec/fx_codec.h" | 8 #include "core/fxcodec/fx_codec.h" |
9 #include "core/fxcrt/fx_memory.h" | 9 #include "core/fxcrt/fx_memory.h" |
10 | 10 |
11 #include "core/fpdfapi/page/cpdf_shadingpattern.h" | 11 #include "core/fpdfapi/page/cpdf_shadingpattern.h" |
12 #include "core/fpdfapi/page/pageint.h" | 12 #include "core/fpdfapi/page/pageint.h" |
13 #include "core/fpdfapi/parser/cpdf_array.h" | 13 #include "core/fpdfapi/parser/cpdf_array.h" |
14 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 14 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
15 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 15 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
16 #include "core/fxge/cfx_fxgedevice.h" | 16 #include "core/fxge/cfx_fxgedevice.h" |
17 #include "core/fxge/cfx_gemodule.h" | 17 #include "core/fxge/cfx_gemodule.h" |
18 #include "core/fxge/cfx_graphstatedata.h" | 18 #include "core/fxge/cfx_graphstatedata.h" |
19 #include "core/fxge/cfx_pathdata.h" | 19 #include "core/fxge/cfx_pathdata.h" |
20 #include "core/fxge/cfx_renderdevice.h" | 20 #include "core/fxge/cfx_renderdevice.h" |
21 #include "core/fxge/skia/fx_skia_device.h" | 21 #include "core/fxge/skia/fx_skia_device.h" |
| 22 |
| 23 #ifndef _SKIA_SUPPORT_ |
| 24 #include "core/fxge/ge/cfx_cliprgn.h" |
| 25 #endif |
| 26 |
22 #include "third_party/base/ptr_util.h" | 27 #include "third_party/base/ptr_util.h" |
| 28 |
23 #include "third_party/skia/include/core/SkCanvas.h" | 29 #include "third_party/skia/include/core/SkCanvas.h" |
| 30 #include "third_party/skia/include/core/SkPaint.h" |
| 31 #include "third_party/skia/include/core/SkPath.h" |
| 32 #include "third_party/skia/include/effects/SkDashPathEffect.h" |
| 33 #include "third_party/skia/include/pathops/SkPathOps.h" |
| 34 |
| 35 #ifdef _SKIA_SUPPORT_ |
24 #include "third_party/skia/include/core/SkColorFilter.h" | 36 #include "third_party/skia/include/core/SkColorFilter.h" |
25 #include "third_party/skia/include/core/SkColorPriv.h" | 37 #include "third_party/skia/include/core/SkColorPriv.h" |
26 #include "third_party/skia/include/core/SkMaskFilter.h" | 38 #include "third_party/skia/include/core/SkMaskFilter.h" |
27 #include "third_party/skia/include/core/SkPaint.h" | |
28 #include "third_party/skia/include/core/SkPath.h" | |
29 #include "third_party/skia/include/core/SkPictureRecorder.h" | 39 #include "third_party/skia/include/core/SkPictureRecorder.h" |
30 #include "third_party/skia/include/core/SkShader.h" | 40 #include "third_party/skia/include/core/SkShader.h" |
31 #include "third_party/skia/include/core/SkStream.h" | 41 #include "third_party/skia/include/core/SkStream.h" |
32 #include "third_party/skia/include/core/SkTypeface.h" | 42 #include "third_party/skia/include/core/SkTypeface.h" |
33 #include "third_party/skia/include/effects/SkDashPathEffect.h" | |
34 #include "third_party/skia/include/effects/SkGradientShader.h" | 43 #include "third_party/skia/include/effects/SkGradientShader.h" |
35 #include "third_party/skia/include/pathops/SkPathOps.h" | 44 #endif |
36 | 45 |
37 #ifdef SK_DEBUG | 46 #ifdef SK_DEBUG |
38 #include "third_party/skia/include/core/SkClipStack.h" | 47 #include "third_party/skia/include/core/SkClipStack.h" |
39 #endif | 48 #endif |
40 | 49 |
41 namespace { | 50 namespace { |
42 | 51 |
| 52 #ifndef _SKIA_SUPPORT_ |
| 53 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, |
| 54 int dest_left, |
| 55 int dest_top, |
| 56 int width, |
| 57 int height, |
| 58 const CFX_DIBSource* pSrcBitmap, |
| 59 int src_left, |
| 60 int src_top) { |
| 61 if (!pBitmap) |
| 62 return; |
| 63 |
| 64 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, |
| 65 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), |
| 66 src_left, src_top, nullptr); |
| 67 if (width == 0 || height == 0) |
| 68 return; |
| 69 |
| 70 int Bpp = pBitmap->GetBPP() / 8; |
| 71 FXDIB_Format dest_format = pBitmap->GetFormat(); |
| 72 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
| 73 int pitch = pBitmap->GetPitch(); |
| 74 uint8_t* buffer = pBitmap->GetBuffer(); |
| 75 if (dest_format == src_format) { |
| 76 for (int row = 0; row < height; row++) { |
| 77 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; |
| 78 uint8_t* src_scan = |
| 79 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
| 80 if (Bpp == 4) { |
| 81 for (int col = 0; col < width; col++) { |
| 82 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], |
| 83 src_scan[1], src_scan[2])); |
| 84 dest_scan += 4; |
| 85 src_scan += 4; |
| 86 } |
| 87 } else { |
| 88 for (int col = 0; col < width; col++) { |
| 89 *dest_scan++ = src_scan[2]; |
| 90 *dest_scan++ = src_scan[1]; |
| 91 *dest_scan++ = src_scan[0]; |
| 92 src_scan += 3; |
| 93 } |
| 94 } |
| 95 } |
| 96 return; |
| 97 } |
| 98 |
| 99 uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp; |
| 100 if (dest_format == FXDIB_Rgb) { |
| 101 if (src_format == FXDIB_Rgb32) { |
| 102 for (int row = 0; row < height; row++) { |
| 103 uint8_t* dest_scan = dest_buf + row * pitch; |
| 104 uint8_t* src_scan = |
| 105 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 106 for (int col = 0; col < width; col++) { |
| 107 *dest_scan++ = src_scan[2]; |
| 108 *dest_scan++ = src_scan[1]; |
| 109 *dest_scan++ = src_scan[0]; |
| 110 src_scan += 4; |
| 111 } |
| 112 } |
| 113 } else { |
| 114 ASSERT(false); |
| 115 } |
| 116 return; |
| 117 } |
| 118 |
| 119 if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) { |
| 120 if (src_format == FXDIB_Rgb) { |
| 121 for (int row = 0; row < height; row++) { |
| 122 uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch); |
| 123 uint8_t* src_scan = |
| 124 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3; |
| 125 for (int col = 0; col < width; col++) { |
| 126 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], |
| 127 src_scan[2])); |
| 128 dest_scan += 4; |
| 129 src_scan += 3; |
| 130 } |
| 131 } |
| 132 } else if (src_format == FXDIB_Rgb32) { |
| 133 ASSERT(dest_format == FXDIB_Argb); |
| 134 for (int row = 0; row < height; row++) { |
| 135 uint8_t* dest_scan = dest_buf + row * pitch; |
| 136 uint8_t* src_scan = |
| 137 (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4); |
| 138 for (int col = 0; col < width; col++) { |
| 139 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], |
| 140 src_scan[2])); |
| 141 src_scan += 4; |
| 142 dest_scan += 4; |
| 143 } |
| 144 } |
| 145 } |
| 146 return; |
| 147 } |
| 148 |
| 149 ASSERT(false); |
| 150 } |
| 151 |
| 152 #endif |
| 153 |
43 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents | 154 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents |
44 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip | 155 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip |
45 | 156 |
46 void DebugShowSkiaPath(const SkPath& path) { | 157 void DebugShowSkiaPath(const SkPath& path) { |
47 #if SHOW_SKIA_PATH | 158 #if SHOW_SKIA_PATH |
48 char buffer[4096]; | 159 char buffer[4096]; |
49 sk_bzero(buffer, sizeof(buffer)); | 160 sk_bzero(buffer, sizeof(buffer)); |
50 SkMemoryWStream stream(buffer, sizeof(buffer)); | 161 SkMemoryWStream stream(buffer, sizeof(buffer)); |
51 path.dump(&stream, false, false); | 162 path.dump(&stream, false, false); |
52 printf("%s\n", buffer); | 163 printf("%s\n", buffer); |
(...skipping 13 matching lines...) Expand all Loading... |
66 #if DRAW_SKIA_CLIP | 177 #if DRAW_SKIA_CLIP |
67 | 178 |
68 SkPaint DebugClipPaint() { | 179 SkPaint DebugClipPaint() { |
69 SkPaint paint; | 180 SkPaint paint; |
70 paint.setAntiAlias(true); | 181 paint.setAntiAlias(true); |
71 paint.setColor(SK_ColorGREEN); | 182 paint.setColor(SK_ColorGREEN); |
72 paint.setStyle(SkPaint::kStroke_Style); | 183 paint.setStyle(SkPaint::kStroke_Style); |
73 return paint; | 184 return paint; |
74 } | 185 } |
75 | 186 |
| 187 #ifdef _SKIA_SUPPORT_ |
76 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) { | 188 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) { |
77 SkPaint paint = DebugClipPaint(); | 189 SkPaint paint = DebugClipPaint(); |
78 canvas->drawRect(rect, paint); | 190 canvas->drawRect(rect, paint); |
79 } | 191 } |
| 192 #endif |
80 | 193 |
81 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) { | 194 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) { |
82 SkPaint paint = DebugClipPaint(); | 195 SkPaint paint = DebugClipPaint(); |
83 canvas->drawPath(path, paint); | 196 canvas->drawPath(path, paint); |
84 } | 197 } |
85 | 198 |
86 #else // DRAW_SKIA_CLIP | 199 #else // DRAW_SKIA_CLIP |
87 | 200 |
| 201 #ifdef _SKIA_SUPPORT_ |
88 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} | 202 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} |
| 203 #endif |
| 204 |
89 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} | 205 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} |
90 | 206 |
91 #endif // DRAW_SKIA_CLIP | 207 #endif // DRAW_SKIA_CLIP |
92 | 208 |
93 #undef SHOW_SKIA_PATH | 209 #undef SHOW_SKIA_PATH |
94 #undef DRAW_SKIA_CLIP | 210 #undef DRAW_SKIA_CLIP |
95 | 211 |
| 212 #ifdef _SKIA_SUPPORT_ |
96 static void DebugValidate(const CFX_DIBitmap* bitmap, | 213 static void DebugValidate(const CFX_DIBitmap* bitmap, |
97 const CFX_DIBitmap* device) { | 214 const CFX_DIBitmap* device) { |
98 if (bitmap) { | 215 if (bitmap) { |
99 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); | 216 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); |
100 if (bitmap->GetBPP() == 32) { | 217 if (bitmap->GetBPP() == 32) { |
101 bitmap->DebugVerifyBitmapIsPreMultiplied(); | 218 bitmap->DebugVerifyBitmapIsPreMultiplied(); |
102 } | 219 } |
103 } | 220 } |
104 if (device) { | 221 if (device) { |
105 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); | 222 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); |
106 if (device->GetBPP() == 32) { | 223 if (device->GetBPP() == 32) { |
107 device->DebugVerifyBitmapIsPreMultiplied(); | 224 device->DebugVerifyBitmapIsPreMultiplied(); |
108 } | 225 } |
109 } | 226 } |
110 } | 227 } |
| 228 #endif |
111 | 229 |
112 SkPath BuildPath(const CFX_PathData* pPathData) { | 230 SkPath BuildPath(const CFX_PathData* pPathData) { |
113 SkPath skPath; | 231 SkPath skPath; |
114 const CFX_PathData* pFPath = pPathData; | 232 const CFX_PathData* pFPath = pPathData; |
115 int nPoints = pFPath->GetPointCount(); | 233 int nPoints = pFPath->GetPointCount(); |
116 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 234 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
117 for (int i = 0; i < nPoints; i++) { | 235 for (int i = 0; i < nPoints; i++) { |
118 FX_FLOAT x = pPoints[i].m_PointX; | 236 FX_FLOAT x = pPoints[i].m_PointX; |
119 FX_FLOAT y = pPoints[i].m_PointY; | 237 FX_FLOAT y = pPoints[i].m_PointY; |
120 int point_type = pPoints[i].m_Flag & FXPT_TYPE; | 238 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
(...skipping 12 matching lines...) Expand all Loading... |
133 } | 251 } |
134 return skPath; | 252 return skPath; |
135 } | 253 } |
136 | 254 |
137 SkMatrix ToSkMatrix(const CFX_Matrix& m) { | 255 SkMatrix ToSkMatrix(const CFX_Matrix& m) { |
138 SkMatrix skMatrix; | 256 SkMatrix skMatrix; |
139 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | 257 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); |
140 return skMatrix; | 258 return skMatrix; |
141 } | 259 } |
142 | 260 |
| 261 #ifdef _SKIA_SUPPORT_ |
143 // use when pdf's y-axis points up insead of down | 262 // use when pdf's y-axis points up insead of down |
144 SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) { | 263 SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) { |
145 SkMatrix skMatrix; | 264 SkMatrix skMatrix; |
146 skMatrix.setAll(m.a * flip, -m.c * flip, m.e, m.b * flip, -m.d * flip, m.f, 0, | 265 skMatrix.setAll(m.a * flip, -m.c * flip, m.e, m.b * flip, -m.d * flip, m.f, 0, |
147 0, 1); | 266 0, 1); |
148 return skMatrix; | 267 return skMatrix; |
149 } | 268 } |
| 269 #endif |
150 | 270 |
151 SkBlendMode GetSkiaBlendMode(int blend_type) { | 271 SkBlendMode GetSkiaBlendMode(int blend_type) { |
152 switch (blend_type) { | 272 switch (blend_type) { |
153 case FXDIB_BLEND_MULTIPLY: | 273 case FXDIB_BLEND_MULTIPLY: |
154 return SkBlendMode::kMultiply; | 274 return SkBlendMode::kMultiply; |
155 case FXDIB_BLEND_SCREEN: | 275 case FXDIB_BLEND_SCREEN: |
156 return SkBlendMode::kScreen; | 276 return SkBlendMode::kScreen; |
157 case FXDIB_BLEND_OVERLAY: | 277 case FXDIB_BLEND_OVERLAY: |
158 return SkBlendMode::kOverlay; | 278 return SkBlendMode::kOverlay; |
159 case FXDIB_BLEND_DARKEN: | 279 case FXDIB_BLEND_DARKEN: |
(...skipping 19 matching lines...) Expand all Loading... |
179 case FXDIB_BLEND_COLOR: | 299 case FXDIB_BLEND_COLOR: |
180 return SkBlendMode::kColor; | 300 return SkBlendMode::kColor; |
181 case FXDIB_BLEND_LUMINOSITY: | 301 case FXDIB_BLEND_LUMINOSITY: |
182 return SkBlendMode::kLuminosity; | 302 return SkBlendMode::kLuminosity; |
183 case FXDIB_BLEND_NORMAL: | 303 case FXDIB_BLEND_NORMAL: |
184 default: | 304 default: |
185 return SkBlendMode::kSrcOver; | 305 return SkBlendMode::kSrcOver; |
186 } | 306 } |
187 } | 307 } |
188 | 308 |
| 309 #ifdef _SKIA_SUPPORT_ |
189 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { | 310 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { |
190 if (pFunc->CountInputs() != 1) | 311 if (pFunc->CountInputs() != 1) |
191 return false; | 312 return false; |
192 if (pFunc->m_Exponent != 1) | 313 if (pFunc->m_Exponent != 1) |
193 return false; | 314 return false; |
194 if (pFunc->m_nOrigOutputs != 3) | 315 if (pFunc->m_nOrigOutputs != 3) |
195 return false; | 316 return false; |
196 skColors->push( | 317 skColors->push( |
197 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), | 318 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), |
198 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), | 319 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 colorType = SkColorType::kUnknown_SkColorType; | 583 colorType = SkColorType::kUnknown_SkColorType; |
463 } | 584 } |
464 SkImageInfo imageInfo = | 585 SkImageInfo imageInfo = |
465 SkImageInfo::Make(width, height, colorType, alphaType); | 586 SkImageInfo::Make(width, height, colorType, alphaType); |
466 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, | 587 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, |
467 nullptr); | 588 nullptr); |
468 *widthPtr = width; | 589 *widthPtr = width; |
469 *heightPtr = height; | 590 *heightPtr = height; |
470 return true; | 591 return true; |
471 } | 592 } |
| 593 #endif |
472 | 594 |
473 } // namespace | 595 } // namespace |
474 | 596 |
475 // Encapsulate the state used for successive text and path draws so that | 597 // Encapsulate the state used for successive text and path draws so that |
476 // they can be combined. | 598 // they can be combined. |
477 class SkiaState { | 599 class SkiaState { |
478 public: | 600 public: |
479 enum class Clip { | 601 enum class Clip { |
480 kSave, | 602 kSave, |
481 kPath, | 603 kPath, |
482 }; | 604 }; |
483 | 605 |
484 // mark all cached state as uninitialized | 606 // mark all cached state as uninitialized |
485 SkiaState() | 607 SkiaState() |
486 : m_pFont(nullptr), | 608 : m_pFont(nullptr), |
487 m_fontSize(0), | 609 m_fontSize(0), |
488 m_fillColor(0), | 610 m_fillColor(0), |
489 m_strokeColor(0), | 611 m_strokeColor(0), |
490 m_blendType(0), | 612 m_blendType(0), |
491 m_commandIndex(0), | 613 m_commandIndex(0), |
| 614 #if _SKIA_SUPPORT_ |
492 m_drawText(false), | 615 m_drawText(false), |
| 616 #endif |
493 m_drawPath(false), | 617 m_drawPath(false), |
494 m_fillPath(false), | 618 m_fillPath(false), |
495 m_debugDisable(false) {} | 619 m_debugDisable(true) { |
| 620 } |
496 | 621 |
497 bool DrawPath(const CFX_PathData* pPathData, | 622 bool DrawPath(const CFX_PathData* pPathData, |
498 const CFX_Matrix* pMatrix, | 623 const CFX_Matrix* pMatrix, |
499 const CFX_GraphStateData* pDrawState, | 624 const CFX_GraphStateData* pDrawState, |
500 uint32_t fill_color, | 625 uint32_t fill_color, |
501 uint32_t stroke_color, | 626 uint32_t stroke_color, |
502 int fill_mode, | 627 int fill_mode, |
503 int blend_type, | 628 int blend_type, |
504 CFX_SkiaDeviceDriver* pDriver) { | 629 CFX_SkiaDeviceDriver* pDriver) { |
505 if (m_debugDisable) | 630 if (m_debugDisable) |
506 return false; | 631 return false; |
507 if (m_commandIndex < m_commands.count()) | 632 if (m_commandIndex < m_commands.count()) |
508 FlushCommands(pDriver); | 633 FlushCommands(pDriver); |
| 634 #if _SKIA_SUPPORT_ |
509 if (m_drawText) | 635 if (m_drawText) |
510 FlushText(pDriver); | 636 FlushText(pDriver); |
| 637 #endif |
511 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, | 638 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, |
512 fill_mode, blend_type)) { | 639 fill_mode, blend_type)) { |
513 FlushPath(pDriver); | 640 FlushPath(pDriver); |
514 } | 641 } |
515 if (!m_drawPath) { | 642 if (!m_drawPath) { |
516 m_skPath.reset(); | 643 m_skPath.reset(); |
517 m_fillPath = (fill_mode & 3) && fill_color; | 644 m_fillPath = (fill_mode & 3) && fill_color; |
518 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 645 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
519 ? SkPath::kEvenOdd_FillType | 646 ? SkPath::kEvenOdd_FillType |
520 : SkPath::kWinding_FillType); | 647 : SkPath::kWinding_FillType); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 DebugShowSkiaPath(m_skPath); | 694 DebugShowSkiaPath(m_skPath); |
568 DebugShowCanvasMatrix(skCanvas); | 695 DebugShowCanvasMatrix(skCanvas); |
569 skPaint.setStyle(SkPaint::kStroke_Style); | 696 skPaint.setStyle(SkPaint::kStroke_Style); |
570 skPaint.setColor(m_strokeColor); | 697 skPaint.setColor(m_strokeColor); |
571 skCanvas->drawPath(m_skPath, skPaint); | 698 skCanvas->drawPath(m_skPath, skPaint); |
572 } | 699 } |
573 skCanvas->restore(); | 700 skCanvas->restore(); |
574 m_drawPath = false; | 701 m_drawPath = false; |
575 } | 702 } |
576 | 703 |
| 704 #ifdef _SKIA_SUPPORT_ |
577 bool DrawText(int nChars, | 705 bool DrawText(int nChars, |
578 const FXTEXT_CHARPOS* pCharPos, | 706 const FXTEXT_CHARPOS* pCharPos, |
579 CFX_Font* pFont, | 707 CFX_Font* pFont, |
580 const CFX_Matrix* pMatrix, | 708 const CFX_Matrix* pMatrix, |
581 FX_FLOAT font_size, | 709 FX_FLOAT font_size, |
582 uint32_t color, | 710 uint32_t color, |
583 CFX_SkiaDeviceDriver* pDriver) { | 711 CFX_SkiaDeviceDriver* pDriver) { |
584 if (m_debugDisable) | 712 if (m_debugDisable) |
585 return false; | 713 return false; |
586 if (m_commandIndex < m_commands.count()) | 714 if (m_commandIndex < m_commands.count()) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 skPaint.setSubpixelText(true); | 758 skPaint.setSubpixelText(true); |
631 skPaint.setHinting(SkPaint::kNo_Hinting); | 759 skPaint.setHinting(SkPaint::kNo_Hinting); |
632 SkCanvas* skCanvas = pDriver->SkiaCanvas(); | 760 SkCanvas* skCanvas = pDriver->SkiaCanvas(); |
633 skCanvas->save(); | 761 skCanvas->save(); |
634 skCanvas->concat(skMatrix); | 762 skCanvas->concat(skMatrix); |
635 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, | 763 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, |
636 m_positions.begin(), skPaint); | 764 m_positions.begin(), skPaint); |
637 skCanvas->restore(); | 765 skCanvas->restore(); |
638 m_drawText = false; | 766 m_drawText = false; |
639 } | 767 } |
| 768 #endif |
640 | 769 |
641 bool SetClipFill(const CFX_PathData* pPathData, | 770 bool SetClipFill(const CFX_PathData* pPathData, |
642 const CFX_Matrix* pMatrix, | 771 const CFX_Matrix* pMatrix, |
643 int fill_mode, | 772 int fill_mode, |
644 CFX_SkiaDeviceDriver* pDriver) { | 773 CFX_SkiaDeviceDriver* pDriver) { |
645 if (m_debugDisable) | 774 if (m_debugDisable) |
646 return false; | 775 return false; |
647 SkPath skClipPath = BuildPath(pPathData); | 776 SkPath skClipPath = BuildPath(pPathData); |
648 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 777 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
649 ? SkPath::kEvenOdd_FillType | 778 ? SkPath::kEvenOdd_FillType |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 for (int index = 0; index < pState->m_DashCount; ++index) { | 948 for (int index = 0; index < pState->m_DashCount; ++index) { |
820 if (pState->m_DashArray[index] != refState.m_DashArray[index]) | 949 if (pState->m_DashArray[index] != refState.m_DashArray[index]) |
821 return false; | 950 return false; |
822 } | 951 } |
823 return true; | 952 return true; |
824 } | 953 } |
825 | 954 |
826 void Flush(CFX_SkiaDeviceDriver* pDriver) { | 955 void Flush(CFX_SkiaDeviceDriver* pDriver) { |
827 if (m_drawPath) | 956 if (m_drawPath) |
828 FlushPath(pDriver); | 957 FlushPath(pDriver); |
| 958 #ifdef _SKIA_SUPPORT_ |
829 if (m_drawText) | 959 if (m_drawText) |
830 FlushText(pDriver); | 960 FlushText(pDriver); |
| 961 #endif |
831 } | 962 } |
832 | 963 |
833 #ifdef SK_DEBUG | 964 #ifdef SK_DEBUG |
834 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { | 965 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { |
835 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); | 966 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); |
836 pDriver->m_pCanvas->getClipStack()->dump(); | 967 pDriver->m_pCanvas->getClipStack()->dump(); |
837 SkDebugf("Cache:\n"); | 968 SkDebugf("Cache:\n"); |
838 for (int index = 0; index < m_commands.count(); ++index) { | 969 for (int index = 0; index < m_commands.count(); ++index) { |
839 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); | 970 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); |
840 switch (m_commands[index]) { | 971 switch (m_commands[index]) { |
(...skipping 22 matching lines...) Expand all Loading... |
863 CFX_Matrix m_drawMatrix; | 994 CFX_Matrix m_drawMatrix; |
864 CFX_GraphStateData m_clipState; | 995 CFX_GraphStateData m_clipState; |
865 CFX_GraphStateData m_drawState; | 996 CFX_GraphStateData m_drawState; |
866 CFX_Matrix m_clipMatrix; | 997 CFX_Matrix m_clipMatrix; |
867 CFX_Font* m_pFont; | 998 CFX_Font* m_pFont; |
868 FX_FLOAT m_fontSize; | 999 FX_FLOAT m_fontSize; |
869 uint32_t m_fillColor; | 1000 uint32_t m_fillColor; |
870 uint32_t m_strokeColor; | 1001 uint32_t m_strokeColor; |
871 int m_blendType; | 1002 int m_blendType; |
872 int m_commandIndex; // active position in clip command stack | 1003 int m_commandIndex; // active position in clip command stack |
| 1004 #ifdef _SKIA_SUPPORT_ |
873 bool m_drawText; | 1005 bool m_drawText; |
| 1006 #endif |
874 bool m_drawPath; | 1007 bool m_drawPath; |
875 bool m_fillPath; | 1008 bool m_fillPath; |
876 bool m_debugDisable; // turn off cache for debugging | 1009 bool m_debugDisable; // turn off cache for debugging |
877 }; | 1010 }; |
878 | 1011 |
879 // convert a stroking path to scanlines | 1012 // convert a stroking path to scanlines |
880 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, | 1013 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, |
881 const CFX_GraphStateData* pGraphState, | 1014 const CFX_GraphStateData* pGraphState, |
882 const SkMatrix& matrix) { | 1015 const SkMatrix& matrix) { |
883 SkPaint::Cap cap; | 1016 SkPaint::Cap cap; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 } | 1075 } |
943 | 1076 |
944 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 1077 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
945 bool bRgbByteOrder, | 1078 bool bRgbByteOrder, |
946 CFX_DIBitmap* pOriDevice, | 1079 CFX_DIBitmap* pOriDevice, |
947 bool bGroupKnockout) | 1080 bool bGroupKnockout) |
948 : m_pBitmap(pBitmap), | 1081 : m_pBitmap(pBitmap), |
949 m_pOriDevice(pOriDevice), | 1082 m_pOriDevice(pOriDevice), |
950 m_pRecorder(nullptr), | 1083 m_pRecorder(nullptr), |
951 m_pCache(new SkiaState), | 1084 m_pCache(new SkiaState), |
| 1085 #ifndef _SKIA_SUPPORT_ |
| 1086 m_pClipRgn(nullptr), |
| 1087 m_FillFlags(0), |
| 1088 m_bRgbByteOrder(bRgbByteOrder), |
| 1089 #endif |
952 m_bGroupKnockout(bGroupKnockout) { | 1090 m_bGroupKnockout(bGroupKnockout) { |
953 SkBitmap skBitmap; | 1091 SkBitmap skBitmap; |
954 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); | 1092 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); |
955 SkImageInfo imageInfo = SkImageInfo::Make( | 1093 SkImageInfo imageInfo = SkImageInfo::Make( |
956 pBitmap->GetWidth(), pBitmap->GetHeight(), | 1094 pBitmap->GetWidth(), pBitmap->GetHeight(), |
957 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, | 1095 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, |
958 kOpaque_SkAlphaType); | 1096 kOpaque_SkAlphaType); |
959 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), | 1097 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), |
960 nullptr, /* to do : set color table */ | 1098 nullptr, // FIXME(caryclark) set color table |
961 nullptr, nullptr); | 1099 nullptr, nullptr); |
962 m_pCanvas = new SkCanvas(skBitmap); | 1100 m_pCanvas = new SkCanvas(skBitmap); |
963 if (m_bGroupKnockout) | |
964 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' | |
965 } | 1101 } |
966 | 1102 |
| 1103 #ifdef _SKIA_SUPPORT_ |
967 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) | 1104 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) |
968 : m_pBitmap(nullptr), | 1105 : m_pBitmap(nullptr), |
969 m_pOriDevice(nullptr), | 1106 m_pOriDevice(nullptr), |
970 m_pRecorder(new SkPictureRecorder), | 1107 m_pRecorder(new SkPictureRecorder), |
971 m_pCache(new SkiaState), | 1108 m_pCache(new SkiaState), |
972 m_bGroupKnockout(false) { | 1109 m_bGroupKnockout(false) { |
973 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); | 1110 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); |
974 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 1111 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
975 } | 1112 } |
976 | 1113 |
977 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) | 1114 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) |
978 : m_pBitmap(nullptr), | 1115 : m_pBitmap(nullptr), |
979 m_pOriDevice(nullptr), | 1116 m_pOriDevice(nullptr), |
980 m_pRecorder(recorder), | 1117 m_pRecorder(recorder), |
981 m_pCache(new SkiaState), | 1118 m_pCache(new SkiaState), |
982 m_bGroupKnockout(false) { | 1119 m_bGroupKnockout(false) { |
983 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 1120 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
984 } | 1121 } |
| 1122 #endif |
985 | 1123 |
986 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 1124 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
987 Flush(); | 1125 Flush(); |
988 if (!m_pRecorder) | 1126 if (!m_pRecorder) |
989 delete m_pCanvas; | 1127 delete m_pCanvas; |
990 } | 1128 } |
991 | 1129 |
992 void CFX_SkiaDeviceDriver::Flush() { | 1130 void CFX_SkiaDeviceDriver::Flush() { |
993 m_pCache->Flush(this); | 1131 m_pCache->Flush(this); |
994 m_pCache->FlushCommands(this); | 1132 m_pCache->FlushCommands(this); |
995 } | 1133 } |
996 | 1134 |
997 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 1135 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
998 const FXTEXT_CHARPOS* pCharPos, | 1136 const FXTEXT_CHARPOS* pCharPos, |
999 CFX_Font* pFont, | 1137 CFX_Font* pFont, |
1000 const CFX_Matrix* pObject2Device, | 1138 const CFX_Matrix* pObject2Device, |
1001 FX_FLOAT font_size, | 1139 FX_FLOAT font_size, |
1002 uint32_t color) { | 1140 uint32_t color) { |
| 1141 #ifdef _SKIA_SUPPORT_ |
1003 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, | 1142 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, |
1004 color, this)) { | 1143 color, this)) { |
1005 return true; | 1144 return true; |
1006 } | 1145 } |
1007 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); | 1146 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); |
1008 SkPaint paint; | 1147 SkPaint paint; |
1009 paint.setAntiAlias(true); | 1148 paint.setAntiAlias(true); |
1010 paint.setColor(color); | 1149 paint.setColor(color); |
1011 paint.setTypeface(typeface); | 1150 paint.setTypeface(typeface); |
1012 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1151 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
1013 paint.setHinting(SkPaint::kNo_Hinting); | 1152 paint.setHinting(SkPaint::kNo_Hinting); |
1014 paint.setTextSize(font_size); | 1153 paint.setTextSize(font_size); |
1015 paint.setSubpixelText(true); | 1154 paint.setSubpixelText(true); |
1016 m_pCanvas->save(); | 1155 m_pCanvas->save(); |
1017 SkScalar flip = font_size < 0 ? -1 : 1; | 1156 SkScalar flip = font_size < 0 ? -1 : 1; |
1018 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); | 1157 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); |
1019 m_pCanvas->concat(skMatrix); | 1158 m_pCanvas->concat(skMatrix); |
1020 SkTDArray<SkPoint> positions; | 1159 SkTDArray<SkPoint> positions; |
1021 positions.setCount(nChars); | 1160 positions.setCount(nChars); |
1022 SkTDArray<uint16_t> glyphs; | 1161 SkTDArray<uint16_t> glyphs; |
1023 glyphs.setCount(nChars); | 1162 glyphs.setCount(nChars); |
1024 for (int index = 0; index < nChars; ++index) { | 1163 for (int index = 0; index < nChars; ++index) { |
1025 const FXTEXT_CHARPOS& cp = pCharPos[index]; | 1164 const FXTEXT_CHARPOS& cp = pCharPos[index]; |
1026 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; | 1165 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; |
1027 glyphs[index] = (uint16_t)cp.m_GlyphIndex; | 1166 glyphs[index] = (uint16_t)cp.m_GlyphIndex; |
1028 } | 1167 } |
1029 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); | 1168 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); |
1030 m_pCanvas->restore(); | 1169 m_pCanvas->restore(); |
1031 return true; | 1170 return true; |
| 1171 #else |
| 1172 return false; |
| 1173 #endif |
1032 } | 1174 } |
1033 | 1175 |
1034 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { | 1176 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { |
1035 switch (caps_id) { | 1177 switch (caps_id) { |
1036 case FXDC_DEVICE_CLASS: | 1178 case FXDC_DEVICE_CLASS: |
1037 return FXDC_DISPLAY; | 1179 return FXDC_DISPLAY; |
| 1180 #ifdef _SKIA_SUPPORT_ |
1038 case FXDC_PIXEL_WIDTH: | 1181 case FXDC_PIXEL_WIDTH: |
1039 return m_pCanvas->imageInfo().width(); | 1182 return m_pCanvas->imageInfo().width(); |
1040 case FXDC_PIXEL_HEIGHT: | 1183 case FXDC_PIXEL_HEIGHT: |
1041 return m_pCanvas->imageInfo().height(); | 1184 return m_pCanvas->imageInfo().height(); |
1042 case FXDC_BITS_PIXEL: | 1185 case FXDC_BITS_PIXEL: |
1043 return 32; | 1186 return 32; |
1044 case FXDC_HORZ_SIZE: | 1187 case FXDC_HORZ_SIZE: |
1045 case FXDC_VERT_SIZE: | 1188 case FXDC_VERT_SIZE: |
1046 return 0; | 1189 return 0; |
1047 case FXDC_RENDER_CAPS: | 1190 case FXDC_RENDER_CAPS: |
1048 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | | 1191 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | |
1049 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT | | 1192 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT | |
1050 FXRC_FILLSTROKE_PATH | FXRC_SHADING; | 1193 FXRC_FILLSTROKE_PATH | FXRC_SHADING; |
| 1194 #else |
| 1195 case FXDC_PIXEL_WIDTH: |
| 1196 return m_pBitmap->GetWidth(); |
| 1197 case FXDC_PIXEL_HEIGHT: |
| 1198 return m_pBitmap->GetHeight(); |
| 1199 case FXDC_BITS_PIXEL: |
| 1200 return m_pBitmap->GetBPP(); |
| 1201 case FXDC_HORZ_SIZE: |
| 1202 case FXDC_VERT_SIZE: |
| 1203 return 0; |
| 1204 case FXDC_RENDER_CAPS: { |
| 1205 int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | |
| 1206 FXRC_BLEND_MODE | FXRC_SOFT_CLIP; |
| 1207 if (m_pBitmap->HasAlpha()) { |
| 1208 flags |= FXRC_ALPHA_OUTPUT; |
| 1209 } else if (m_pBitmap->IsAlphaMask()) { |
| 1210 if (m_pBitmap->GetBPP() == 1) { |
| 1211 flags |= FXRC_BITMASK_OUTPUT; |
| 1212 } else { |
| 1213 flags |= FXRC_BYTEMASK_OUTPUT; |
| 1214 } |
| 1215 } |
| 1216 if (m_pBitmap->IsCmykImage()) { |
| 1217 flags |= FXRC_CMYK_OUTPUT; |
| 1218 } |
| 1219 return flags; |
| 1220 } |
| 1221 #endif |
1051 } | 1222 } |
1052 return 0; | 1223 return 0; |
1053 } | 1224 } |
1054 | 1225 |
1055 void CFX_SkiaDeviceDriver::SaveState() { | 1226 void CFX_SkiaDeviceDriver::SaveState() { |
| 1227 #ifdef _SKIA_SUPPORT_ |
1056 if (!m_pCache->ClipSave(this)) | 1228 if (!m_pCache->ClipSave(this)) |
1057 m_pCanvas->save(); | 1229 m_pCanvas->save(); |
| 1230 #else |
| 1231 std::unique_ptr<CFX_ClipRgn> pClip; |
| 1232 if (m_pClipRgn) |
| 1233 pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn); |
| 1234 m_StateStack.push_back(std::move(pClip)); |
| 1235 #endif |
1058 } | 1236 } |
1059 | 1237 |
1060 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { | 1238 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { |
| 1239 #ifdef _SKIA_SUPPORT_ |
1061 if (!m_pCache->ClipRestore(this)) | 1240 if (!m_pCache->ClipRestore(this)) |
1062 m_pCanvas->restore(); | 1241 m_pCanvas->restore(); |
1063 if (bKeepSaved) | 1242 if (bKeepSaved) |
1064 SaveState(); | 1243 SaveState(); |
| 1244 #else |
| 1245 m_pClipRgn.reset(); |
| 1246 |
| 1247 if (m_StateStack.empty()) |
| 1248 return; |
| 1249 |
| 1250 if (bKeepSaved) { |
| 1251 if (m_StateStack.back()) |
| 1252 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back()); |
| 1253 } else { |
| 1254 m_pClipRgn = std::move(m_StateStack.back()); |
| 1255 m_StateStack.pop_back(); |
| 1256 } |
| 1257 #endif |
1065 } | 1258 } |
1066 | 1259 |
| 1260 #ifndef _SKIA_SUPPORT_ |
| 1261 void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox, |
| 1262 const SkPath& path) { |
| 1263 FX_RECT path_rect(clipBox.left, clipBox.top, clipBox.right + 1, |
| 1264 clipBox.bottom + 1); |
| 1265 path_rect.Intersect(m_pClipRgn->GetBox()); |
| 1266 CFX_DIBitmapRef mask; |
| 1267 CFX_DIBitmap* pThisLayer = mask.Emplace(); |
| 1268 pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask); |
| 1269 pThisLayer->Clear(0); |
| 1270 |
| 1271 SkImageInfo imageInfo = |
| 1272 SkImageInfo::Make(pThisLayer->GetWidth(), pThisLayer->GetHeight(), |
| 1273 SkColorType::kAlpha_8_SkColorType, kOpaque_SkAlphaType); |
| 1274 SkBitmap bitmap; |
| 1275 bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(), |
| 1276 pThisLayer->GetPitch(), nullptr, nullptr, nullptr); |
| 1277 SkCanvas* canvas = new SkCanvas(bitmap); |
| 1278 canvas->translate( |
| 1279 clipBox.left, |
| 1280 clipBox.top); // FIXME(caryclark) wrong sign(s)? upside down? |
| 1281 SkPaint paint; |
| 1282 paint.setAntiAlias((m_FillFlags & FXFILL_NOPATHSMOOTH) == 0); |
| 1283 canvas->drawPath(path, paint); |
| 1284 std::unique_ptr<uint8_t, FxFreeDeleter> raw_buf; |
| 1285 raw_buf.reset( |
| 1286 FX_Alloc2D(uint8_t, pThisLayer->GetWidth(), pThisLayer->GetHeight())); |
| 1287 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); |
| 1288 delete canvas; |
| 1289 } |
| 1290 #endif |
| 1291 |
1067 bool CFX_SkiaDeviceDriver::SetClip_PathFill( | 1292 bool CFX_SkiaDeviceDriver::SetClip_PathFill( |
1068 const CFX_PathData* pPathData, // path info | 1293 const CFX_PathData* pPathData, // path info |
1069 const CFX_Matrix* pObject2Device, // flips object's y-axis | 1294 const CFX_Matrix* pObject2Device, // flips object's y-axis |
1070 int fill_mode // fill mode, WINDING or ALTERNATE | 1295 int fill_mode // fill mode, WINDING or ALTERNATE |
1071 ) { | 1296 ) { |
1072 CFX_Matrix identity; | 1297 CFX_Matrix identity; |
1073 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; | 1298 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; |
| 1299 #ifdef _SKIA_SUPPORT_ |
1074 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this)) | 1300 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this)) |
1075 return true; | 1301 return true; |
| 1302 #else |
| 1303 m_FillFlags = fill_mode; |
| 1304 if (!m_pClipRgn) { |
| 1305 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( |
| 1306 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 1307 } |
| 1308 #endif |
1076 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 1309 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
1077 CFX_FloatRect rectf; | 1310 CFX_FloatRect rectf; |
1078 if (pPathData->IsRect(deviceMatrix, &rectf)) { | 1311 if (pPathData->IsRect(deviceMatrix, &rectf)) { |
1079 rectf.Intersect( | 1312 rectf.Intersect( |
1080 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 1313 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
1081 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 1314 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 1315 #ifdef _SKIA_SUPPORT_ |
1082 // note that PDF's y-axis goes up; Skia's y-axis goes down | 1316 // note that PDF's y-axis goes up; Skia's y-axis goes down |
1083 SkRect skClipRect = | 1317 SkRect skClipRect = |
1084 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); | 1318 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); |
1085 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); | 1319 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); |
1086 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); | 1320 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); |
| 1321 #else |
| 1322 FX_RECT rect = rectf.GetOuterRect(); |
| 1323 m_pClipRgn->IntersectRect(rect); |
| 1324 #endif |
1087 return true; | 1325 return true; |
1088 } | 1326 } |
1089 } | 1327 } |
1090 SkPath skClipPath = BuildPath(pPathData); | 1328 SkPath skClipPath = BuildPath(pPathData); |
1091 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 1329 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
1092 ? SkPath::kEvenOdd_FillType | 1330 ? SkPath::kEvenOdd_FillType |
1093 : SkPath::kWinding_FillType); | 1331 : SkPath::kWinding_FillType); |
1094 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); | 1332 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); |
1095 skClipPath.transform(skMatrix); | 1333 skClipPath.transform(skMatrix); |
1096 DebugShowSkiaPath(skClipPath); | 1334 DebugShowSkiaPath(skClipPath); |
1097 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); | 1335 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); |
1098 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); | 1336 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); |
1099 | 1337 #ifndef _SKIA_SUPPORT_ |
| 1338 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 1339 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 1340 SetClipMask(clipBox, skClipPath); |
| 1341 #endif |
1100 return true; | 1342 return true; |
1101 } | 1343 } |
1102 | 1344 |
1103 bool CFX_SkiaDeviceDriver::SetClip_PathStroke( | 1345 bool CFX_SkiaDeviceDriver::SetClip_PathStroke( |
1104 const CFX_PathData* pPathData, // path info | 1346 const CFX_PathData* pPathData, // path info |
1105 const CFX_Matrix* pObject2Device, // optional transformation | 1347 const CFX_Matrix* pObject2Device, // optional transformation |
1106 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 1348 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
1107 ) { | 1349 ) { |
| 1350 #ifdef _SKIA_SUPPORT_ |
1108 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this)) | 1351 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this)) |
1109 return true; | 1352 return true; |
| 1353 #else |
| 1354 if (!m_pClipRgn) { |
| 1355 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( |
| 1356 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 1357 } |
| 1358 #endif |
1110 // build path data | 1359 // build path data |
1111 SkPath skPath = BuildPath(pPathData); | 1360 SkPath skPath = BuildPath(pPathData); |
1112 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | 1361 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); |
1113 SkPaint skPaint; | 1362 SkPaint skPaint; |
1114 PaintStroke(&skPaint, pGraphState, skMatrix); | 1363 PaintStroke(&skPaint, pGraphState, skMatrix); |
1115 SkPath dst_path; | 1364 SkPath dst_path; |
1116 skPaint.getFillPath(skPath, &dst_path); | 1365 skPaint.getFillPath(skPath, &dst_path); |
1117 dst_path.transform(skMatrix); | 1366 dst_path.transform(skMatrix); |
1118 DebugDrawSkiaClipPath(m_pCanvas, dst_path); | 1367 DebugDrawSkiaClipPath(m_pCanvas, dst_path); |
| 1368 #ifdef _SKIA_SUPPORT_ |
1119 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); | 1369 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); |
| 1370 #else |
| 1371 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 1372 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 1373 SetClipMask(clipBox, dst_path); |
| 1374 #endif |
1120 return true; | 1375 return true; |
1121 } | 1376 } |
1122 | 1377 |
1123 bool CFX_SkiaDeviceDriver::DrawPath( | 1378 bool CFX_SkiaDeviceDriver::DrawPath( |
1124 const CFX_PathData* pPathData, // path info | 1379 const CFX_PathData* pPathData, // path info |
1125 const CFX_Matrix* pObject2Device, // optional transformation | 1380 const CFX_Matrix* pObject2Device, // optional transformation |
1126 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 1381 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
1127 uint32_t fill_color, // fill color | 1382 uint32_t fill_color, // fill color |
1128 uint32_t stroke_color, // stroke color | 1383 uint32_t stroke_color, // stroke color |
1129 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 1384 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
1130 int blend_type) { | 1385 int blend_type) { |
1131 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, | 1386 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, |
1132 stroke_color, fill_mode, blend_type, this)) { | 1387 stroke_color, fill_mode, blend_type, this)) { |
1133 return true; | 1388 return true; |
1134 } | 1389 } |
1135 SkIRect rect; | 1390 SkIRect rect; |
1136 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 1391 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
1137 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 1392 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
1138 SkMatrix skMatrix; | 1393 SkMatrix skMatrix; |
1139 if (pObject2Device) | 1394 if (pObject2Device) |
1140 skMatrix = ToSkMatrix(*pObject2Device); | 1395 skMatrix = ToSkMatrix(*pObject2Device); |
1141 else | 1396 else |
1142 skMatrix.setIdentity(); | 1397 skMatrix.setIdentity(); |
1143 SkPaint skPaint; | 1398 SkPaint skPaint; |
1144 skPaint.setAntiAlias(true); | 1399 skPaint.setAntiAlias(true); |
| 1400 if (fill_mode & FXFILL_FULLCOVER) |
| 1401 skPaint.setBlendMode(SkBlendMode::kPlus); |
1145 int stroke_alpha = FXARGB_A(stroke_color); | 1402 int stroke_alpha = FXARGB_A(stroke_color); |
1146 if (pGraphState && stroke_alpha) | 1403 if (pGraphState && stroke_alpha) |
1147 PaintStroke(&skPaint, pGraphState, skMatrix); | 1404 PaintStroke(&skPaint, pGraphState, skMatrix); |
1148 SkPath skPath = BuildPath(pPathData); | 1405 SkPath skPath = BuildPath(pPathData); |
1149 m_pCanvas->save(); | 1406 m_pCanvas->save(); |
1150 m_pCanvas->concat(skMatrix); | 1407 m_pCanvas->concat(skMatrix); |
1151 if ((fill_mode & 3) && fill_color) { | 1408 if ((fill_mode & 3) && fill_color) { |
1152 skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 1409 skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
1153 ? SkPath::kEvenOdd_FillType | 1410 ? SkPath::kEvenOdd_FillType |
1154 : SkPath::kWinding_FillType); | 1411 : SkPath::kWinding_FillType); |
1155 SkPath strokePath; | 1412 SkPath strokePath; |
1156 const SkPath* fillPath = &skPath; | 1413 const SkPath* fillPath = &skPath; |
1157 if (pGraphState && stroke_alpha) { | 1414 if (pGraphState && stroke_alpha) { |
1158 SkAlpha fillA = SkColorGetA(fill_color); | 1415 if (m_bGroupKnockout) { |
1159 SkAlpha strokeA = SkColorGetA(stroke_color); | |
1160 if (fillA && fillA < 0xFF && strokeA && strokeA < 0xFF) { | |
1161 skPaint.getFillPath(skPath, &strokePath); | 1416 skPaint.getFillPath(skPath, &strokePath); |
1162 if (Op(skPath, strokePath, SkPathOp::kDifference_SkPathOp, | 1417 if (Op(skPath, strokePath, SkPathOp::kDifference_SkPathOp, |
1163 &strokePath)) { | 1418 &strokePath)) { |
1164 fillPath = &strokePath; | 1419 fillPath = &strokePath; |
1165 } | 1420 } |
1166 } | 1421 } |
1167 } | 1422 } |
1168 skPaint.setStyle(SkPaint::kFill_Style); | 1423 skPaint.setStyle(SkPaint::kFill_Style); |
1169 skPaint.setColor(fill_color); | 1424 skPaint.setColor(fill_color); |
1170 m_pCanvas->drawPath(*fillPath, skPaint); | 1425 m_pCanvas->drawPath(*fillPath, skPaint); |
(...skipping 25 matching lines...) Expand all Loading... |
1196 spaint.setAntiAlias(true); | 1451 spaint.setAntiAlias(true); |
1197 spaint.setColor(fill_color); | 1452 spaint.setColor(fill_color); |
1198 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); | 1453 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); |
1199 | 1454 |
1200 m_pCanvas->drawRect( | 1455 m_pCanvas->drawRect( |
1201 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 1456 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
1202 spaint); | 1457 spaint); |
1203 return true; | 1458 return true; |
1204 } | 1459 } |
1205 | 1460 |
| 1461 #ifdef _SKIA_SUPPORT_ |
1206 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, | 1462 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, |
1207 const CFX_Matrix* pMatrix, | 1463 const CFX_Matrix* pMatrix, |
1208 const FX_RECT& clip_rect, | 1464 const FX_RECT& clip_rect, |
1209 int alpha, | 1465 int alpha, |
1210 bool bAlphaMode) { | 1466 bool bAlphaMode) { |
1211 if (kAxialShading != pPattern->GetShadingType() && | 1467 if (kAxialShading != pPattern->GetShadingType() && |
1212 kRadialShading != pPattern->GetShadingType()) { | 1468 kRadialShading != pPattern->GetShadingType()) { |
1213 // TODO(caryclark) more types | 1469 // TODO(caryclark) more types |
1214 return false; | 1470 return false; |
1215 } | 1471 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 skPath.transform(inverse); | 1585 skPath.transform(inverse); |
1330 } | 1586 } |
1331 m_pCanvas->save(); | 1587 m_pCanvas->save(); |
1332 if (!skClip.isEmpty()) | 1588 if (!skClip.isEmpty()) |
1333 m_pCanvas->clipPath(skClip, SkCanvas::kIntersect_Op, true); | 1589 m_pCanvas->clipPath(skClip, SkCanvas::kIntersect_Op, true); |
1334 m_pCanvas->concat(skMatrix); | 1590 m_pCanvas->concat(skMatrix); |
1335 m_pCanvas->drawPath(skPath, paint); | 1591 m_pCanvas->drawPath(skPath, paint); |
1336 m_pCanvas->restore(); | 1592 m_pCanvas->restore(); |
1337 return true; | 1593 return true; |
1338 } | 1594 } |
| 1595 #endif |
1339 | 1596 |
1340 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { | 1597 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { |
1341 return m_pBitmap->GetBuffer(); | 1598 return m_pBitmap->GetBuffer(); |
1342 } | 1599 } |
1343 | 1600 |
1344 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 1601 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
1345 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead | 1602 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead |
1346 pRect->left = 0; | 1603 pRect->left = 0; |
1347 pRect->top = 0; | 1604 pRect->top = 0; |
1348 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 1605 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
1349 pRect->right = canvasSize.width(); | 1606 pRect->right = canvasSize.width(); |
1350 pRect->bottom = canvasSize.height(); | 1607 pRect->bottom = canvasSize.height(); |
1351 return true; | 1608 return true; |
1352 } | 1609 } |
1353 | 1610 |
1354 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { | 1611 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { |
1355 if (!m_pBitmap) | 1612 if (!m_pBitmap) |
1356 return true; | 1613 return true; |
1357 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); | 1614 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); |
1358 if (!srcBuffer) | 1615 if (!srcBuffer) |
1359 return true; | 1616 return true; |
| 1617 #ifdef _SKIA_SUPPORT_ |
1360 int srcWidth = m_pBitmap->GetWidth(); | 1618 int srcWidth = m_pBitmap->GetWidth(); |
1361 int srcHeight = m_pBitmap->GetHeight(); | 1619 int srcHeight = m_pBitmap->GetHeight(); |
1362 int srcRowBytes = srcWidth * sizeof(uint32_t); | 1620 int srcRowBytes = srcWidth * sizeof(uint32_t); |
1363 SkImageInfo srcImageInfo = SkImageInfo::Make( | 1621 SkImageInfo srcImageInfo = SkImageInfo::Make( |
1364 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1622 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1365 SkBitmap skSrcBitmap; | 1623 SkBitmap skSrcBitmap; |
1366 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, | 1624 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, |
1367 nullptr, nullptr); | 1625 nullptr, nullptr); |
1368 SkASSERT(pBitmap); | 1626 SkASSERT(pBitmap); |
1369 uint8_t* dstBuffer = pBitmap->GetBuffer(); | 1627 uint8_t* dstBuffer = pBitmap->GetBuffer(); |
1370 SkASSERT(dstBuffer); | 1628 SkASSERT(dstBuffer); |
1371 int dstWidth = pBitmap->GetWidth(); | 1629 int dstWidth = pBitmap->GetWidth(); |
1372 int dstHeight = pBitmap->GetHeight(); | 1630 int dstHeight = pBitmap->GetHeight(); |
1373 int dstRowBytes = dstWidth * sizeof(uint32_t); | 1631 int dstRowBytes = dstWidth * sizeof(uint32_t); |
1374 SkImageInfo dstImageInfo = SkImageInfo::Make( | 1632 SkImageInfo dstImageInfo = SkImageInfo::Make( |
1375 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1633 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1376 SkBitmap skDstBitmap; | 1634 SkBitmap skDstBitmap; |
1377 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, | 1635 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, |
1378 nullptr, nullptr); | 1636 nullptr, nullptr); |
1379 SkCanvas canvas(skDstBitmap); | 1637 SkCanvas canvas(skDstBitmap); |
1380 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); | 1638 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); |
1381 return true; | 1639 return true; |
| 1640 #else |
| 1641 FX_RECT rect(left, top, left + pBitmap->GetWidth(), |
| 1642 top + pBitmap->GetHeight()); |
| 1643 CFX_DIBitmap* pBack = nullptr; |
| 1644 if (m_pOriDevice) { |
| 1645 pBack = m_pOriDevice->Clone(&rect); |
| 1646 if (!pBack) |
| 1647 return true; |
| 1648 |
| 1649 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), |
| 1650 m_pBitmap, 0, 0); |
| 1651 } else { |
| 1652 pBack = m_pBitmap->Clone(&rect); |
| 1653 if (!pBack) |
| 1654 return true; |
| 1655 } |
| 1656 |
| 1657 bool bRet = true; |
| 1658 left = std::min(left, 0); |
| 1659 top = std::min(top, 0); |
| 1660 if (m_bRgbByteOrder) { |
| 1661 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), |
| 1662 pBack, left, top); |
| 1663 } else { |
| 1664 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, |
| 1665 left, top); |
| 1666 } |
| 1667 delete pBack; |
| 1668 return bRet; |
| 1669 #endif |
1382 } | 1670 } |
1383 | 1671 |
1384 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { | 1672 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { |
1385 return m_pOriDevice; | 1673 return m_pOriDevice; |
1386 } | 1674 } |
1387 | 1675 |
1388 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 1676 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
1389 uint32_t argb, | 1677 uint32_t argb, |
1390 const FX_RECT* pSrcRect, | 1678 const FX_RECT* pSrcRect, |
1391 int left, | 1679 int left, |
1392 int top, | 1680 int top, |
1393 int blend_type) { | 1681 int blend_type) { |
1394 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1682 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1395 return true; | 1683 return true; |
1396 | 1684 |
| 1685 #ifdef _SKIA_SUPPORT_ |
1397 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, | 1686 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
1398 top + pBitmap->GetHeight()); | 1687 top + pBitmap->GetHeight()); |
1399 void* dummy; | 1688 void* dummy; |
1400 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); | 1689 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
| 1690 #else |
| 1691 if (pBitmap->IsAlphaMask()) { |
| 1692 return m_pBitmap->CompositeMask( |
| 1693 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, |
| 1694 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(), |
| 1695 m_bRgbByteOrder, 0, nullptr); |
| 1696 } |
| 1697 return m_pBitmap->CompositeBitmap( |
| 1698 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, |
| 1699 pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); |
| 1700 #endif |
1401 } | 1701 } |
1402 | 1702 |
1403 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 1703 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
1404 uint32_t argb, | 1704 uint32_t argb, |
1405 int dest_left, | 1705 int dest_left, |
1406 int dest_top, | 1706 int dest_top, |
1407 int dest_width, | 1707 int dest_width, |
1408 int dest_height, | 1708 int dest_height, |
1409 const FX_RECT* pClipRect, | 1709 const FX_RECT* pClipRect, |
1410 uint32_t flags, | 1710 uint32_t flags, |
1411 int blend_type) { | 1711 int blend_type) { |
| 1712 #ifdef _SKIA_SUPPORT_ |
1412 if (!m_pBitmap->GetBuffer()) | 1713 if (!m_pBitmap->GetBuffer()) |
1413 return true; | 1714 return true; |
1414 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, | 1715 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
1415 dest_top + dest_height); | 1716 dest_top + dest_height); |
1416 | 1717 |
1417 m_pCanvas->save(); | 1718 m_pCanvas->save(); |
1418 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, | 1719 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, |
1419 pClipRect->right, pClipRect->top); | 1720 pClipRect->right, pClipRect->top); |
1420 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); | 1721 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); |
1421 void* dummy; | 1722 void* dummy; |
1422 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); | 1723 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); |
1423 m_pCanvas->restore(); | 1724 m_pCanvas->restore(); |
1424 | 1725 |
1425 return result; | 1726 return result; |
| 1727 #else |
| 1728 if (dest_width == pSource->GetWidth() && |
| 1729 dest_height == pSource->GetHeight()) { |
| 1730 FX_RECT rect(0, 0, dest_width, dest_height); |
| 1731 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type); |
| 1732 } |
| 1733 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, |
| 1734 dest_top + dest_height); |
| 1735 dest_rect.Normalize(); |
| 1736 FX_RECT dest_clip = dest_rect; |
| 1737 dest_clip.Intersect(*pClipRect); |
| 1738 CFX_BitmapComposer composer; |
| 1739 composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false, |
| 1740 false, false, m_bRgbByteOrder, 0, nullptr, blend_type); |
| 1741 dest_clip.Offset(-dest_rect.left, -dest_rect.top); |
| 1742 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, |
| 1743 dest_clip, flags); |
| 1744 if (stretcher.Start()) |
| 1745 stretcher.Continue(nullptr); |
| 1746 return true; |
| 1747 #endif |
1426 } | 1748 } |
1427 | 1749 |
1428 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 1750 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1429 int bitmap_alpha, | 1751 int bitmap_alpha, |
1430 uint32_t argb, | 1752 uint32_t argb, |
1431 const CFX_Matrix* pMatrix, | 1753 const CFX_Matrix* pMatrix, |
1432 uint32_t render_flags, | 1754 uint32_t render_flags, |
1433 void*& handle, | 1755 void*& handle, |
1434 int blend_type) { | 1756 int blend_type) { |
| 1757 #ifdef _SKIA_SUPPORT_ |
1435 DebugValidate(m_pBitmap, m_pOriDevice); | 1758 DebugValidate(m_pBitmap, m_pOriDevice); |
1436 SkColorTable* ct = nullptr; | 1759 SkColorTable* ct = nullptr; |
1437 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1760 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
1438 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; | 1761 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; |
1439 SkBitmap skBitmap; | 1762 SkBitmap skBitmap; |
1440 int width, height; | 1763 int width, height; |
1441 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, | 1764 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, |
1442 &height, false)) { | 1765 &height, false)) { |
1443 return false; | 1766 return false; |
1444 } | 1767 } |
(...skipping 18 matching lines...) Expand all Loading... |
1463 m_pBitmap->SetPixel(x, y, skBitmap.getColor(src.fX, src.fY)); | 1786 m_pBitmap->SetPixel(x, y, skBitmap.getColor(src.fX, src.fY)); |
1464 } | 1787 } |
1465 } | 1788 } |
1466 } else { | 1789 } else { |
1467 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); | 1790 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); |
1468 } | 1791 } |
1469 m_pCanvas->restore(); | 1792 m_pCanvas->restore(); |
1470 if (ct) | 1793 if (ct) |
1471 ct->unref(); | 1794 ct->unref(); |
1472 DebugValidate(m_pBitmap, m_pOriDevice); | 1795 DebugValidate(m_pBitmap, m_pOriDevice); |
| 1796 #else |
| 1797 if (!m_pBitmap->GetBuffer()) |
| 1798 return true; |
| 1799 |
| 1800 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; |
| 1801 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, |
| 1802 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); |
| 1803 handle = pRenderer; |
| 1804 #endif |
1473 return true; | 1805 return true; |
1474 } | 1806 } |
1475 | 1807 |
1476 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { | 1808 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
| 1809 #ifdef _SKIA_SUPPORT_ |
1477 return false; | 1810 return false; |
| 1811 #else |
| 1812 if (!m_pBitmap->GetBuffer()) { |
| 1813 return true; |
| 1814 } |
| 1815 return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause); |
| 1816 #endif |
1478 } | 1817 } |
1479 | 1818 |
| 1819 #ifdef _SKIA_SUPPORT_ |
1480 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { | 1820 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { |
1481 void* buffer = pDIBitmap->GetBuffer(); | 1821 void* buffer = pDIBitmap->GetBuffer(); |
1482 if (!buffer) | 1822 if (!buffer) |
1483 return; | 1823 return; |
1484 if (pDIBitmap->GetBPP() != 32) { | 1824 if (pDIBitmap->GetBPP() != 32) { |
1485 return; | 1825 return; |
1486 } | 1826 } |
1487 int height = pDIBitmap->GetHeight(); | 1827 int height = pDIBitmap->GetHeight(); |
1488 int width = pDIBitmap->GetWidth(); | 1828 int width = pDIBitmap->GetWidth(); |
1489 int rowBytes = pDIBitmap->GetPitch(); | 1829 int rowBytes = pDIBitmap->GetPitch(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1890 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1551 return true; | 1891 return true; |
1552 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, | 1892 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, |
1553 dest_top + pBitmap->GetHeight()); | 1893 dest_top + pBitmap->GetHeight()); |
1554 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); | 1894 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); |
1555 } | 1895 } |
1556 | 1896 |
1557 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { | 1897 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { |
1558 m_pCanvas->clear(color); | 1898 m_pCanvas->clear(color); |
1559 } | 1899 } |
| 1900 #endif |
1560 | 1901 |
1561 void CFX_SkiaDeviceDriver::Dump() const { | 1902 void CFX_SkiaDeviceDriver::Dump() const { |
1562 #ifdef SK_DEBUG | 1903 #ifdef SK_DEBUG |
1563 if (m_pCache) | 1904 if (m_pCache) |
1564 m_pCache->Dump(this); | 1905 m_pCache->Dump(this); |
1565 #endif | 1906 #endif |
1566 } | 1907 } |
1567 | 1908 |
| 1909 #ifdef _SKIA_SUPPORT_ |
1568 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { | 1910 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { |
1569 if (m_pOriDevice) | 1911 if (m_pOriDevice) |
1570 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); | 1912 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); |
1571 } | 1913 } |
| 1914 #endif |
1572 | 1915 |
1573 CFX_FxgeDevice::CFX_FxgeDevice() { | 1916 CFX_FxgeDevice::CFX_FxgeDevice() { |
| 1917 #ifdef _SKIA_SUPPORT_ |
1574 m_bOwnedBitmap = false; | 1918 m_bOwnedBitmap = false; |
| 1919 #endif |
1575 } | 1920 } |
1576 | 1921 |
| 1922 #ifdef _SKIA_SUPPORT_ |
1577 void CFX_FxgeDevice::Clear(uint32_t color) { | 1923 void CFX_FxgeDevice::Clear(uint32_t color) { |
1578 CFX_SkiaDeviceDriver* skDriver = | 1924 CFX_SkiaDeviceDriver* skDriver = |
1579 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1925 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1580 skDriver->Clear(color); | 1926 skDriver->Clear(color); |
1581 } | 1927 } |
1582 | 1928 |
1583 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { | 1929 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { |
1584 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); | 1930 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); |
1585 SetDeviceDriver(pdfium::WrapUnique(skDriver)); | 1931 SetDeviceDriver(pdfium::WrapUnique(skDriver)); |
1586 return skDriver->GetRecorder(); | 1932 return skDriver->GetRecorder(); |
1587 } | 1933 } |
| 1934 #endif |
1588 | 1935 |
1589 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, | 1936 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, |
1590 bool bRgbByteOrder, | 1937 bool bRgbByteOrder, |
1591 CFX_DIBitmap* pOriDevice, | 1938 CFX_DIBitmap* pOriDevice, |
1592 bool bGroupKnockout) { | 1939 bool bGroupKnockout) { |
1593 if (!pBitmap) | 1940 if (!pBitmap) |
1594 return false; | 1941 return false; |
1595 SetBitmap(pBitmap); | 1942 SetBitmap(pBitmap); |
1596 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>( | 1943 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>( |
1597 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); | 1944 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); |
1598 return true; | 1945 return true; |
1599 } | 1946 } |
1600 | 1947 |
| 1948 #ifdef _SKIA_SUPPORT_ |
1601 bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { | 1949 bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { |
1602 if (!recorder) | 1950 if (!recorder) |
1603 return false; | 1951 return false; |
1604 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); | 1952 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); |
1605 return true; | 1953 return true; |
1606 } | 1954 } |
| 1955 #endif |
1607 | 1956 |
1608 bool CFX_FxgeDevice::Create(int width, | 1957 bool CFX_FxgeDevice::Create(int width, |
1609 int height, | 1958 int height, |
1610 FXDIB_Format format, | 1959 FXDIB_Format format, |
1611 CFX_DIBitmap* pOriDevice) { | 1960 CFX_DIBitmap* pOriDevice) { |
1612 m_bOwnedBitmap = true; | 1961 m_bOwnedBitmap = true; |
1613 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 1962 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
1614 if (!pBitmap->Create(width, height, format)) { | 1963 if (!pBitmap->Create(width, height, format)) { |
1615 delete pBitmap; | 1964 delete pBitmap; |
1616 return false; | 1965 return false; |
1617 } | 1966 } |
1618 SetBitmap(pBitmap); | 1967 SetBitmap(pBitmap); |
1619 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, false, | 1968 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, false, |
1620 pOriDevice, false)); | 1969 pOriDevice, false)); |
1621 return true; | 1970 return true; |
1622 } | 1971 } |
1623 | 1972 |
1624 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1973 CFX_FxgeDevice::~CFX_FxgeDevice() { |
| 1974 #ifdef _SKIA_SUPPORT_ |
1625 Flush(); | 1975 Flush(); |
1626 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately | 1976 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately |
1627 if (m_bOwnedBitmap && GetBitmap()) | 1977 if (m_bOwnedBitmap && GetBitmap()) |
1628 delete GetBitmap(); | 1978 delete GetBitmap(); |
| 1979 #endif |
1629 } | 1980 } |
1630 | 1981 |
| 1982 #ifdef _SKIA_SUPPORT_ |
1631 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { | 1983 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { |
1632 #ifdef SK_DEBUG | 1984 #ifdef SK_DEBUG |
1633 CFX_SkiaDeviceDriver* skDriver = | 1985 CFX_SkiaDeviceDriver* skDriver = |
1634 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1986 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1635 if (skDriver) | 1987 if (skDriver) |
1636 skDriver->DebugVerifyBitmapIsPreMultiplied(); | 1988 skDriver->DebugVerifyBitmapIsPreMultiplied(); |
1637 #endif | 1989 #endif |
1638 } | 1990 } |
1639 | 1991 |
1640 bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, | 1992 bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, |
(...skipping 25 matching lines...) Expand all Loading... |
1666 uint8_t g = SkGetPackedG32(srcRow[x]); | 2018 uint8_t g = SkGetPackedG32(srcRow[x]); |
1667 uint8_t b = SkGetPackedB32(srcRow[x]); | 2019 uint8_t b = SkGetPackedB32(srcRow[x]); |
1668 SkA32Assert(a); | 2020 SkA32Assert(a); |
1669 SkASSERT(r <= a); | 2021 SkASSERT(r <= a); |
1670 SkASSERT(g <= a); | 2022 SkASSERT(g <= a); |
1671 SkASSERT(b <= a); | 2023 SkASSERT(b <= a); |
1672 } | 2024 } |
1673 } | 2025 } |
1674 #endif | 2026 #endif |
1675 } | 2027 } |
| 2028 #endif |
| 2029 |
| 2030 #ifndef _SKIA_SUPPORT_ |
| 2031 class CFX_Renderer { |
| 2032 private: |
| 2033 int m_Alpha, m_Red, m_Green, m_Blue, m_Gray; |
| 2034 uint32_t m_Color; |
| 2035 bool m_bFullCover; |
| 2036 bool m_bRgbByteOrder; |
| 2037 CFX_DIBitmap* m_pOriDevice; |
| 2038 FX_RECT m_ClipBox; |
| 2039 const CFX_DIBitmap* m_pClipMask; |
| 2040 CFX_DIBitmap* m_pDevice; |
| 2041 const CFX_ClipRgn* m_pClipRgn; |
| 2042 void (CFX_Renderer::*composite_span)(uint8_t*, |
| 2043 int, |
| 2044 int, |
| 2045 int, |
| 2046 uint8_t*, |
| 2047 int, |
| 2048 int, |
| 2049 uint8_t*, |
| 2050 uint8_t*); |
| 2051 |
| 2052 public: |
| 2053 void prepare(unsigned) {} |
| 2054 |
| 2055 void CompositeSpan(uint8_t* dest_scan, |
| 2056 uint8_t* ori_scan, |
| 2057 int Bpp, |
| 2058 bool bDestAlpha, |
| 2059 int span_left, |
| 2060 int span_len, |
| 2061 uint8_t* cover_scan, |
| 2062 int clip_left, |
| 2063 int clip_right, |
| 2064 uint8_t* clip_scan) { |
| 2065 ASSERT(!m_pDevice->IsCmykImage()); |
| 2066 int col_start = span_left < clip_left ? clip_left - span_left : 0; |
| 2067 int col_end = (span_left + span_len) < clip_right |
| 2068 ? span_len |
| 2069 : (clip_right - span_left); |
| 2070 if (Bpp) { |
| 2071 dest_scan += col_start * Bpp; |
| 2072 ori_scan += col_start * Bpp; |
| 2073 } else { |
| 2074 dest_scan += col_start / 8; |
| 2075 ori_scan += col_start / 8; |
| 2076 } |
| 2077 if (m_bRgbByteOrder) { |
| 2078 if (Bpp == 4 && bDestAlpha) { |
| 2079 for (int col = col_start; col < col_end; col++) { |
| 2080 int src_alpha; |
| 2081 if (clip_scan) { |
| 2082 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2083 } else { |
| 2084 src_alpha = m_Alpha; |
| 2085 } |
| 2086 uint8_t dest_alpha = |
| 2087 ori_scan[3] + src_alpha - ori_scan[3] * src_alpha / 255; |
| 2088 dest_scan[3] = dest_alpha; |
| 2089 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 2090 if (m_bFullCover) { |
| 2091 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio); |
| 2092 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio); |
| 2093 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio); |
| 2094 dest_scan++; |
| 2095 ori_scan++; |
| 2096 } else { |
| 2097 int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio); |
| 2098 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio); |
| 2099 int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio); |
| 2100 ori_scan++; |
| 2101 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]); |
| 2102 dest_scan++; |
| 2103 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]); |
| 2104 dest_scan++; |
| 2105 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]); |
| 2106 dest_scan += 2; |
| 2107 } |
| 2108 } |
| 2109 return; |
| 2110 } |
| 2111 if (Bpp == 3 || Bpp == 4) { |
| 2112 for (int col = col_start; col < col_end; col++) { |
| 2113 int src_alpha; |
| 2114 if (clip_scan) { |
| 2115 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2116 } else { |
| 2117 src_alpha = m_Alpha; |
| 2118 } |
| 2119 int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, src_alpha); |
| 2120 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha); |
| 2121 int b = FXDIB_ALPHA_MERGE(*ori_scan, m_Blue, src_alpha); |
| 2122 ori_scan += Bpp - 2; |
| 2123 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]); |
| 2124 dest_scan++; |
| 2125 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]); |
| 2126 dest_scan++; |
| 2127 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]); |
| 2128 dest_scan += Bpp - 2; |
| 2129 } |
| 2130 } |
| 2131 return; |
| 2132 } |
| 2133 if (Bpp == 4 && bDestAlpha) { |
| 2134 for (int col = col_start; col < col_end; col++) { |
| 2135 int src_alpha; |
| 2136 if (clip_scan) { |
| 2137 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2138 } else { |
| 2139 src_alpha = m_Alpha; |
| 2140 } |
| 2141 int src_alpha_covered = src_alpha * cover_scan[col] / 255; |
| 2142 if (src_alpha_covered == 0) { |
| 2143 dest_scan += 4; |
| 2144 continue; |
| 2145 } |
| 2146 if (cover_scan[col] == 255) { |
| 2147 dest_scan[3] = src_alpha_covered; |
| 2148 *dest_scan++ = m_Blue; |
| 2149 *dest_scan++ = m_Green; |
| 2150 *dest_scan = m_Red; |
| 2151 dest_scan += 2; |
| 2152 continue; |
| 2153 } else { |
| 2154 if (dest_scan[3] == 0) { |
| 2155 dest_scan[3] = src_alpha_covered; |
| 2156 *dest_scan++ = m_Blue; |
| 2157 *dest_scan++ = m_Green; |
| 2158 *dest_scan = m_Red; |
| 2159 dest_scan += 2; |
| 2160 continue; |
| 2161 } |
| 2162 uint8_t cover = cover_scan[col]; |
| 2163 dest_scan[3] = FXDIB_ALPHA_MERGE(dest_scan[3], src_alpha, cover); |
| 2164 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, cover); |
| 2165 dest_scan++; |
| 2166 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, cover); |
| 2167 dest_scan++; |
| 2168 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, cover); |
| 2169 dest_scan += 2; |
| 2170 } |
| 2171 } |
| 2172 return; |
| 2173 } |
| 2174 if (Bpp == 3 || Bpp == 4) { |
| 2175 for (int col = col_start; col < col_end; col++) { |
| 2176 int src_alpha; |
| 2177 if (clip_scan) { |
| 2178 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2179 } else { |
| 2180 src_alpha = m_Alpha; |
| 2181 } |
| 2182 if (m_bFullCover) { |
| 2183 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha); |
| 2184 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha); |
| 2185 *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha); |
| 2186 dest_scan += Bpp - 2; |
| 2187 ori_scan += Bpp - 2; |
| 2188 continue; |
| 2189 } |
| 2190 int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha); |
| 2191 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha); |
| 2192 int r = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha); |
| 2193 ori_scan += Bpp - 2; |
| 2194 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]); |
| 2195 dest_scan++; |
| 2196 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]); |
| 2197 dest_scan++; |
| 2198 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]); |
| 2199 dest_scan += Bpp - 2; |
| 2200 continue; |
| 2201 } |
| 2202 return; |
| 2203 } |
| 2204 if (Bpp == 1) { |
| 2205 for (int col = col_start; col < col_end; col++) { |
| 2206 int src_alpha; |
| 2207 if (clip_scan) { |
| 2208 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2209 } else { |
| 2210 src_alpha = m_Alpha; |
| 2211 } |
| 2212 if (m_bFullCover) { |
| 2213 *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha); |
| 2214 } else { |
| 2215 int gray = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha); |
| 2216 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, cover_scan[col]); |
| 2217 dest_scan++; |
| 2218 } |
| 2219 } |
| 2220 } else { |
| 2221 int index = 0; |
| 2222 if (m_pDevice->GetPalette()) { |
| 2223 for (int i = 0; i < 2; i++) { |
| 2224 if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) { |
| 2225 index = i; |
| 2226 } |
| 2227 } |
| 2228 } else { |
| 2229 index = ((uint8_t)m_Color == 0xff) ? 1 : 0; |
| 2230 } |
| 2231 uint8_t* dest_scan1 = dest_scan; |
| 2232 for (int col = col_start; col < col_end; col++) { |
| 2233 int src_alpha; |
| 2234 if (clip_scan) { |
| 2235 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2236 } else { |
| 2237 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2238 } |
| 2239 if (src_alpha) { |
| 2240 if (!index) { |
| 2241 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8)); |
| 2242 } else { |
| 2243 *dest_scan1 |= 1 << (7 - (col + span_left) % 8); |
| 2244 } |
| 2245 } |
| 2246 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8; |
| 2247 } |
| 2248 } |
| 2249 } |
| 2250 |
| 2251 void CompositeSpan1bpp(uint8_t* dest_scan, |
| 2252 int Bpp, |
| 2253 int span_left, |
| 2254 int span_len, |
| 2255 uint8_t* cover_scan, |
| 2256 int clip_left, |
| 2257 int clip_right, |
| 2258 uint8_t* clip_scan, |
| 2259 uint8_t* dest_extra_alpha_scan) { |
| 2260 ASSERT(!m_bRgbByteOrder); |
| 2261 ASSERT(!m_pDevice->IsCmykImage()); |
| 2262 int col_start = span_left < clip_left ? clip_left - span_left : 0; |
| 2263 int col_end = (span_left + span_len) < clip_right |
| 2264 ? span_len |
| 2265 : (clip_right - span_left); |
| 2266 dest_scan += col_start / 8; |
| 2267 int index = 0; |
| 2268 if (m_pDevice->GetPalette()) { |
| 2269 for (int i = 0; i < 2; i++) { |
| 2270 if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) { |
| 2271 index = i; |
| 2272 } |
| 2273 } |
| 2274 } else { |
| 2275 index = ((uint8_t)m_Color == 0xff) ? 1 : 0; |
| 2276 } |
| 2277 uint8_t* dest_scan1 = dest_scan; |
| 2278 for (int col = col_start; col < col_end; col++) { |
| 2279 int src_alpha; |
| 2280 if (clip_scan) { |
| 2281 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2282 } else { |
| 2283 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2284 } |
| 2285 if (src_alpha) { |
| 2286 if (!index) { |
| 2287 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8)); |
| 2288 } else { |
| 2289 *dest_scan1 |= 1 << (7 - (col + span_left) % 8); |
| 2290 } |
| 2291 } |
| 2292 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8; |
| 2293 } |
| 2294 } |
| 2295 |
| 2296 void CompositeSpanGray(uint8_t* dest_scan, |
| 2297 int Bpp, |
| 2298 int span_left, |
| 2299 int span_len, |
| 2300 uint8_t* cover_scan, |
| 2301 int clip_left, |
| 2302 int clip_right, |
| 2303 uint8_t* clip_scan, |
| 2304 uint8_t* dest_extra_alpha_scan) { |
| 2305 ASSERT(!m_bRgbByteOrder); |
| 2306 int col_start = span_left < clip_left ? clip_left - span_left : 0; |
| 2307 int col_end = (span_left + span_len) < clip_right |
| 2308 ? span_len |
| 2309 : (clip_right - span_left); |
| 2310 dest_scan += col_start; |
| 2311 if (dest_extra_alpha_scan) { |
| 2312 for (int col = col_start; col < col_end; col++) { |
| 2313 int src_alpha; |
| 2314 if (m_bFullCover) { |
| 2315 if (clip_scan) { |
| 2316 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2317 } else { |
| 2318 src_alpha = m_Alpha; |
| 2319 } |
| 2320 } else { |
| 2321 if (clip_scan) { |
| 2322 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2323 } else { |
| 2324 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2325 } |
| 2326 } |
| 2327 if (src_alpha) { |
| 2328 if (src_alpha == 255) { |
| 2329 *dest_scan = m_Gray; |
| 2330 *dest_extra_alpha_scan = m_Alpha; |
| 2331 } else { |
| 2332 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha - |
| 2333 (*dest_extra_alpha_scan) * src_alpha / 255; |
| 2334 *dest_extra_alpha_scan++ = dest_alpha; |
| 2335 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 2336 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio); |
| 2337 dest_scan++; |
| 2338 continue; |
| 2339 } |
| 2340 } |
| 2341 dest_extra_alpha_scan++; |
| 2342 dest_scan++; |
| 2343 } |
| 2344 } else { |
| 2345 for (int col = col_start; col < col_end; col++) { |
| 2346 int src_alpha; |
| 2347 if (clip_scan) { |
| 2348 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2349 } else { |
| 2350 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2351 } |
| 2352 if (src_alpha) { |
| 2353 if (src_alpha == 255) { |
| 2354 *dest_scan = m_Gray; |
| 2355 } else { |
| 2356 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha); |
| 2357 } |
| 2358 } |
| 2359 dest_scan++; |
| 2360 } |
| 2361 } |
| 2362 } |
| 2363 |
| 2364 void CompositeSpanARGB(uint8_t* dest_scan, |
| 2365 int Bpp, |
| 2366 int span_left, |
| 2367 int span_len, |
| 2368 uint8_t* cover_scan, |
| 2369 int clip_left, |
| 2370 int clip_right, |
| 2371 uint8_t* clip_scan, |
| 2372 uint8_t* dest_extra_alpha_scan) { |
| 2373 int col_start = span_left < clip_left ? clip_left - span_left : 0; |
| 2374 int col_end = (span_left + span_len) < clip_right |
| 2375 ? span_len |
| 2376 : (clip_right - span_left); |
| 2377 dest_scan += col_start * Bpp; |
| 2378 if (m_bRgbByteOrder) { |
| 2379 for (int col = col_start; col < col_end; col++) { |
| 2380 int src_alpha; |
| 2381 if (m_bFullCover) { |
| 2382 if (clip_scan) { |
| 2383 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2384 } else { |
| 2385 src_alpha = m_Alpha; |
| 2386 } |
| 2387 } else { |
| 2388 if (clip_scan) { |
| 2389 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2390 } else { |
| 2391 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2392 } |
| 2393 } |
| 2394 if (src_alpha) { |
| 2395 if (src_alpha == 255) { |
| 2396 *(uint32_t*)dest_scan = m_Color; |
| 2397 } else { |
| 2398 uint8_t dest_alpha = |
| 2399 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255; |
| 2400 dest_scan[3] = dest_alpha; |
| 2401 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 2402 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); |
| 2403 dest_scan++; |
| 2404 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); |
| 2405 dest_scan++; |
| 2406 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); |
| 2407 dest_scan += 2; |
| 2408 continue; |
| 2409 } |
| 2410 } |
| 2411 dest_scan += 4; |
| 2412 } |
| 2413 return; |
| 2414 } |
| 2415 for (int col = col_start; col < col_end; col++) { |
| 2416 int src_alpha; |
| 2417 if (m_bFullCover) { |
| 2418 if (clip_scan) { |
| 2419 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2420 } else { |
| 2421 src_alpha = m_Alpha; |
| 2422 } |
| 2423 } else { |
| 2424 if (clip_scan) { |
| 2425 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2426 } else { |
| 2427 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2428 } |
| 2429 } |
| 2430 if (src_alpha) { |
| 2431 if (src_alpha == 255) { |
| 2432 *(uint32_t*)dest_scan = m_Color; |
| 2433 } else { |
| 2434 if (dest_scan[3] == 0) { |
| 2435 dest_scan[3] = src_alpha; |
| 2436 *dest_scan++ = m_Blue; |
| 2437 *dest_scan++ = m_Green; |
| 2438 *dest_scan = m_Red; |
| 2439 dest_scan += 2; |
| 2440 continue; |
| 2441 } |
| 2442 uint8_t dest_alpha = |
| 2443 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255; |
| 2444 dest_scan[3] = dest_alpha; |
| 2445 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 2446 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); |
| 2447 dest_scan++; |
| 2448 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); |
| 2449 dest_scan++; |
| 2450 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); |
| 2451 dest_scan += 2; |
| 2452 continue; |
| 2453 } |
| 2454 } |
| 2455 dest_scan += Bpp; |
| 2456 } |
| 2457 } |
| 2458 |
| 2459 void CompositeSpanRGB(uint8_t* dest_scan, |
| 2460 int Bpp, |
| 2461 int span_left, |
| 2462 int span_len, |
| 2463 uint8_t* cover_scan, |
| 2464 int clip_left, |
| 2465 int clip_right, |
| 2466 uint8_t* clip_scan, |
| 2467 uint8_t* dest_extra_alpha_scan) { |
| 2468 int col_start = span_left < clip_left ? clip_left - span_left : 0; |
| 2469 int col_end = (span_left + span_len) < clip_right |
| 2470 ? span_len |
| 2471 : (clip_right - span_left); |
| 2472 dest_scan += col_start * Bpp; |
| 2473 if (m_bRgbByteOrder) { |
| 2474 for (int col = col_start; col < col_end; col++) { |
| 2475 int src_alpha; |
| 2476 if (clip_scan) { |
| 2477 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2478 } else { |
| 2479 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2480 } |
| 2481 if (src_alpha) { |
| 2482 if (src_alpha == 255) { |
| 2483 if (Bpp == 4) { |
| 2484 *(uint32_t*)dest_scan = m_Color; |
| 2485 } else if (Bpp == 3) { |
| 2486 *dest_scan++ = m_Red; |
| 2487 *dest_scan++ = m_Green; |
| 2488 *dest_scan++ = m_Blue; |
| 2489 continue; |
| 2490 } |
| 2491 } else { |
| 2492 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha); |
| 2493 dest_scan++; |
| 2494 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha); |
| 2495 dest_scan++; |
| 2496 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha); |
| 2497 dest_scan += Bpp - 2; |
| 2498 continue; |
| 2499 } |
| 2500 } |
| 2501 dest_scan += Bpp; |
| 2502 } |
| 2503 return; |
| 2504 } |
| 2505 if (Bpp == 3 && dest_extra_alpha_scan) { |
| 2506 for (int col = col_start; col < col_end; col++) { |
| 2507 int src_alpha; |
| 2508 if (m_bFullCover) { |
| 2509 if (clip_scan) { |
| 2510 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2511 } else { |
| 2512 src_alpha = m_Alpha; |
| 2513 } |
| 2514 } else { |
| 2515 if (clip_scan) { |
| 2516 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2517 } else { |
| 2518 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2519 } |
| 2520 } |
| 2521 if (src_alpha) { |
| 2522 if (src_alpha == 255) { |
| 2523 *dest_scan++ = (uint8_t)m_Blue; |
| 2524 *dest_scan++ = (uint8_t)m_Green; |
| 2525 *dest_scan++ = (uint8_t)m_Red; |
| 2526 *dest_extra_alpha_scan++ = (uint8_t)m_Alpha; |
| 2527 continue; |
| 2528 } else { |
| 2529 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha - |
| 2530 (*dest_extra_alpha_scan) * src_alpha / 255; |
| 2531 *dest_extra_alpha_scan++ = dest_alpha; |
| 2532 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 2533 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); |
| 2534 dest_scan++; |
| 2535 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); |
| 2536 dest_scan++; |
| 2537 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); |
| 2538 dest_scan++; |
| 2539 continue; |
| 2540 } |
| 2541 } |
| 2542 dest_extra_alpha_scan++; |
| 2543 dest_scan += Bpp; |
| 2544 } |
| 2545 } else { |
| 2546 for (int col = col_start; col < col_end; col++) { |
| 2547 int src_alpha; |
| 2548 if (m_bFullCover) { |
| 2549 if (clip_scan) { |
| 2550 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2551 } else { |
| 2552 src_alpha = m_Alpha; |
| 2553 } |
| 2554 } else { |
| 2555 if (clip_scan) { |
| 2556 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2557 } else { |
| 2558 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2559 } |
| 2560 } |
| 2561 if (src_alpha) { |
| 2562 if (src_alpha == 255) { |
| 2563 if (Bpp == 4) { |
| 2564 *(uint32_t*)dest_scan = m_Color; |
| 2565 } else if (Bpp == 3) { |
| 2566 *dest_scan++ = m_Blue; |
| 2567 *dest_scan++ = m_Green; |
| 2568 *dest_scan++ = m_Red; |
| 2569 continue; |
| 2570 } |
| 2571 } else { |
| 2572 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha); |
| 2573 dest_scan++; |
| 2574 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha); |
| 2575 dest_scan++; |
| 2576 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha); |
| 2577 dest_scan += Bpp - 2; |
| 2578 continue; |
| 2579 } |
| 2580 } |
| 2581 dest_scan += Bpp; |
| 2582 } |
| 2583 } |
| 2584 } |
| 2585 |
| 2586 void CompositeSpanCMYK(uint8_t* dest_scan, |
| 2587 int Bpp, |
| 2588 int span_left, |
| 2589 int span_len, |
| 2590 uint8_t* cover_scan, |
| 2591 int clip_left, |
| 2592 int clip_right, |
| 2593 uint8_t* clip_scan, |
| 2594 uint8_t* dest_extra_alpha_scan) { |
| 2595 ASSERT(!m_bRgbByteOrder); |
| 2596 int col_start = span_left < clip_left ? clip_left - span_left : 0; |
| 2597 int col_end = (span_left + span_len) < clip_right |
| 2598 ? span_len |
| 2599 : (clip_right - span_left); |
| 2600 dest_scan += col_start * 4; |
| 2601 if (dest_extra_alpha_scan) { |
| 2602 for (int col = col_start; col < col_end; col++) { |
| 2603 int src_alpha; |
| 2604 if (m_bFullCover) { |
| 2605 if (clip_scan) { |
| 2606 src_alpha = m_Alpha * clip_scan[col] / 255; |
| 2607 } else { |
| 2608 src_alpha = m_Alpha; |
| 2609 } |
| 2610 } else { |
| 2611 if (clip_scan) { |
| 2612 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2613 } else { |
| 2614 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2615 } |
| 2616 } |
| 2617 if (src_alpha) { |
| 2618 if (src_alpha == 255) { |
| 2619 *(FX_CMYK*)dest_scan = m_Color; |
| 2620 *dest_extra_alpha_scan = (uint8_t)m_Alpha; |
| 2621 } else { |
| 2622 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha - |
| 2623 (*dest_extra_alpha_scan) * src_alpha / 255; |
| 2624 *dest_extra_alpha_scan++ = dest_alpha; |
| 2625 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 2626 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); |
| 2627 dest_scan++; |
| 2628 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); |
| 2629 dest_scan++; |
| 2630 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); |
| 2631 dest_scan++; |
| 2632 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio); |
| 2633 dest_scan++; |
| 2634 continue; |
| 2635 } |
| 2636 } |
| 2637 dest_extra_alpha_scan++; |
| 2638 dest_scan += 4; |
| 2639 } |
| 2640 } else { |
| 2641 for (int col = col_start; col < col_end; col++) { |
| 2642 int src_alpha; |
| 2643 if (clip_scan) { |
| 2644 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; |
| 2645 } else { |
| 2646 src_alpha = m_Alpha * cover_scan[col] / 255; |
| 2647 } |
| 2648 if (src_alpha) { |
| 2649 if (src_alpha == 255) { |
| 2650 *(FX_CMYK*)dest_scan = m_Color; |
| 2651 } else { |
| 2652 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha); |
| 2653 dest_scan++; |
| 2654 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha); |
| 2655 dest_scan++; |
| 2656 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha); |
| 2657 dest_scan++; |
| 2658 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha); |
| 2659 dest_scan++; |
| 2660 continue; |
| 2661 } |
| 2662 } |
| 2663 dest_scan += 4; |
| 2664 } |
| 2665 } |
| 2666 } |
| 2667 |
| 2668 template <class Scanline> |
| 2669 void render(const Scanline& sl) { |
| 2670 if (!m_pOriDevice && !composite_span) { |
| 2671 return; |
| 2672 } |
| 2673 int y = sl.y(); |
| 2674 if (y < m_ClipBox.top || y >= m_ClipBox.bottom) { |
| 2675 return; |
| 2676 } |
| 2677 uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y; |
| 2678 uint8_t* dest_scan_extra_alpha = nullptr; |
| 2679 CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask; |
| 2680 if (pAlphaMask) { |
| 2681 dest_scan_extra_alpha = |
| 2682 pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y; |
| 2683 } |
| 2684 uint8_t* ori_scan = nullptr; |
| 2685 if (m_pOriDevice) { |
| 2686 ori_scan = m_pOriDevice->GetBuffer() + m_pOriDevice->GetPitch() * y; |
| 2687 } |
| 2688 int Bpp = m_pDevice->GetBPP() / 8; |
| 2689 bool bDestAlpha = m_pDevice->HasAlpha() || m_pDevice->IsAlphaMask(); |
| 2690 unsigned num_spans = sl.num_spans(); |
| 2691 typename Scanline::const_iterator span = sl.begin(); |
| 2692 while (1) { |
| 2693 int x = span->x; |
| 2694 ASSERT(span->len > 0); |
| 2695 uint8_t* dest_pos = nullptr; |
| 2696 uint8_t* dest_extra_alpha_pos = nullptr; |
| 2697 uint8_t* ori_pos = nullptr; |
| 2698 if (Bpp) { |
| 2699 ori_pos = ori_scan ? ori_scan + x * Bpp : nullptr; |
| 2700 dest_pos = dest_scan + x * Bpp; |
| 2701 dest_extra_alpha_pos = |
| 2702 dest_scan_extra_alpha ? dest_scan_extra_alpha + x : nullptr; |
| 2703 } else { |
| 2704 dest_pos = dest_scan + x / 8; |
| 2705 ori_pos = ori_scan ? ori_scan + x / 8 : nullptr; |
| 2706 } |
| 2707 uint8_t* clip_pos = nullptr; |
| 2708 if (m_pClipMask) { |
| 2709 clip_pos = m_pClipMask->GetBuffer() + |
| 2710 (y - m_ClipBox.top) * m_pClipMask->GetPitch() + x - |
| 2711 m_ClipBox.left; |
| 2712 } |
| 2713 if (ori_pos) { |
| 2714 CompositeSpan(dest_pos, ori_pos, Bpp, bDestAlpha, x, span->len, |
| 2715 span->covers, m_ClipBox.left, m_ClipBox.right, clip_pos); |
| 2716 } else { |
| 2717 (this->*composite_span)(dest_pos, Bpp, x, span->len, span->covers, |
| 2718 m_ClipBox.left, m_ClipBox.right, clip_pos, |
| 2719 dest_extra_alpha_pos); |
| 2720 } |
| 2721 if (--num_spans == 0) { |
| 2722 break; |
| 2723 } |
| 2724 ++span; |
| 2725 } |
| 2726 } |
| 2727 |
| 2728 bool Init(CFX_DIBitmap* pDevice, |
| 2729 CFX_DIBitmap* pOriDevice, |
| 2730 const CFX_ClipRgn* pClipRgn, |
| 2731 uint32_t color, |
| 2732 bool bFullCover, |
| 2733 bool bRgbByteOrder, |
| 2734 int alpha_flag = 0, |
| 2735 void* pIccTransform = nullptr) { |
| 2736 m_pDevice = pDevice; |
| 2737 m_pClipRgn = pClipRgn; |
| 2738 composite_span = nullptr; |
| 2739 m_bRgbByteOrder = bRgbByteOrder; |
| 2740 m_pOriDevice = pOriDevice; |
| 2741 if (m_pClipRgn) { |
| 2742 m_ClipBox = m_pClipRgn->GetBox(); |
| 2743 } else { |
| 2744 m_ClipBox.left = m_ClipBox.top = 0; |
| 2745 m_ClipBox.right = m_pDevice->GetWidth(); |
| 2746 m_ClipBox.bottom = m_pDevice->GetHeight(); |
| 2747 } |
| 2748 m_pClipMask = nullptr; |
| 2749 if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) { |
| 2750 m_pClipMask = m_pClipRgn->GetMask().GetObject(); |
| 2751 } |
| 2752 m_bFullCover = bFullCover; |
| 2753 bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag); |
| 2754 bool bDeviceCMYK = pDevice->IsCmykImage(); |
| 2755 m_Alpha = bObjectCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); |
| 2756 CCodec_IccModule* pIccModule = nullptr; |
| 2757 if (!CFX_GEModule::Get()->GetCodecModule() || |
| 2758 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
| 2759 pIccTransform = nullptr; |
| 2760 } else { |
| 2761 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 2762 } |
| 2763 if (m_pDevice->GetBPP() == 8) { |
| 2764 ASSERT(!m_bRgbByteOrder); |
| 2765 composite_span = &CFX_Renderer::CompositeSpanGray; |
| 2766 if (m_pDevice->IsAlphaMask()) { |
| 2767 m_Gray = 255; |
| 2768 } else { |
| 2769 if (pIccTransform) { |
| 2770 uint8_t gray; |
| 2771 color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
| 2772 pIccModule->TranslateScanline(pIccTransform, &gray, |
| 2773 (const uint8_t*)&color, 1); |
| 2774 m_Gray = gray; |
| 2775 } else { |
| 2776 if (bObjectCMYK) { |
| 2777 uint8_t r, g, b; |
| 2778 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), |
| 2779 FXSYS_GetYValue(color), FXSYS_GetKValue(color), |
| 2780 r, g, b); |
| 2781 m_Gray = FXRGB2GRAY(r, g, b); |
| 2782 } else { |
| 2783 m_Gray = |
| 2784 FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color)); |
| 2785 } |
| 2786 } |
| 2787 } |
| 2788 return true; |
| 2789 } |
| 2790 if (bDeviceCMYK) { |
| 2791 ASSERT(!m_bRgbByteOrder); |
| 2792 composite_span = &CFX_Renderer::CompositeSpanCMYK; |
| 2793 if (bObjectCMYK) { |
| 2794 m_Color = FXCMYK_TODIB(color); |
| 2795 if (pIccTransform) { |
| 2796 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color, |
| 2797 (const uint8_t*)&m_Color, 1); |
| 2798 } |
| 2799 } else { |
| 2800 if (!pIccTransform) { |
| 2801 return false; |
| 2802 } |
| 2803 color = FXARGB_TODIB(color); |
| 2804 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color, |
| 2805 (const uint8_t*)&color, 1); |
| 2806 } |
| 2807 m_Red = ((uint8_t*)&m_Color)[0]; |
| 2808 m_Green = ((uint8_t*)&m_Color)[1]; |
| 2809 m_Blue = ((uint8_t*)&m_Color)[2]; |
| 2810 m_Gray = ((uint8_t*)&m_Color)[3]; |
| 2811 } else { |
| 2812 composite_span = (pDevice->GetFormat() == FXDIB_Argb) |
| 2813 ? &CFX_Renderer::CompositeSpanARGB |
| 2814 : &CFX_Renderer::CompositeSpanRGB; |
| 2815 if (pIccTransform) { |
| 2816 color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
| 2817 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color, |
| 2818 (const uint8_t*)&color, 1); |
| 2819 ((uint8_t*)&m_Color)[3] = m_Alpha; |
| 2820 m_Red = ((uint8_t*)&m_Color)[2]; |
| 2821 m_Green = ((uint8_t*)&m_Color)[1]; |
| 2822 m_Blue = ((uint8_t*)&m_Color)[0]; |
| 2823 if (m_bRgbByteOrder) { |
| 2824 m_Color = FXARGB_TODIB(m_Color); |
| 2825 m_Color = FXARGB_TOBGRORDERDIB(m_Color); |
| 2826 } |
| 2827 } else { |
| 2828 if (bObjectCMYK) { |
| 2829 uint8_t r, g, b; |
| 2830 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), |
| 2831 FXSYS_GetYValue(color), FXSYS_GetKValue(color), r, |
| 2832 g, b); |
| 2833 m_Color = FXARGB_MAKE(m_Alpha, r, g, b); |
| 2834 if (m_bRgbByteOrder) { |
| 2835 m_Color = FXARGB_TOBGRORDERDIB(m_Color); |
| 2836 } else { |
| 2837 m_Color = FXARGB_TODIB(m_Color); |
| 2838 } |
| 2839 m_Red = r; |
| 2840 m_Green = g; |
| 2841 m_Blue = b; |
| 2842 } else { |
| 2843 if (m_bRgbByteOrder) { |
| 2844 m_Color = FXARGB_TOBGRORDERDIB(color); |
| 2845 } else { |
| 2846 m_Color = FXARGB_TODIB(color); |
| 2847 } |
| 2848 ArgbDecode(color, m_Alpha, m_Red, m_Green, m_Blue); |
| 2849 } |
| 2850 } |
| 2851 } |
| 2852 if (m_pDevice->GetBPP() == 1) { |
| 2853 composite_span = &CFX_Renderer::CompositeSpan1bpp; |
| 2854 } |
| 2855 return true; |
| 2856 } |
| 2857 }; |
| 2858 |
| 2859 #endif |
OLD | NEW |