Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/include/fxge/fx_ge.h" | 5 #include "core/include/fxge/fx_ge.h" |
| 6 | 6 |
| 7 #if defined(_SKIA_SUPPORT_) | 7 #if defined(_SKIA_SUPPORT_) |
| 8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
| 9 | 9 |
| 10 #include "core/fxge/agg/fx_agg_driver.h" | 10 #include "core/fxge/agg/fx_agg_driver.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 static void DebugShowSkiaPath(const SkPath& path) { | 25 static void DebugShowSkiaPath(const SkPath& path) { |
| 26 #if SHOW_SKIA_PATH | 26 #if SHOW_SKIA_PATH |
| 27 char buffer[4096]; | 27 char buffer[4096]; |
| 28 sk_bzero(buffer, sizeof(buffer)); | 28 sk_bzero(buffer, sizeof(buffer)); |
| 29 SkMemoryWStream stream(buffer, sizeof(buffer)); | 29 SkMemoryWStream stream(buffer, sizeof(buffer)); |
| 30 path.dump(&stream, false, false); | 30 path.dump(&stream, false, false); |
| 31 printf("%s\n", buffer); | 31 printf("%s\n", buffer); |
| 32 #endif // SHOW_SKIA_PATH | 32 #endif // SHOW_SKIA_PATH |
| 33 } | 33 } |
| 34 | 34 |
| 35 static void DebugShowCanvasMatrix(const SkCanvas* canvas) { | |
| 36 #if SHOW_SKIA_PATH | |
| 37 SkMatrix matrix = canvas->getTotalMatrix(); | |
| 38 SkScalar m[9]; | |
| 39 matrix.get9(m); | |
| 40 printf("(%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], m[4], m[5 ], m[6], | |
|
Tom Sepez
2016/03/17 16:05:50
nit: 80 cols.
caryclark
2016/03/18 18:22:12
Done.
| |
| 41 m[7], m[8]); | |
| 42 #endif // SHOW_SKIA_PATH | |
| 43 } | |
| 44 | |
| 35 #if DRAW_SKIA_CLIP | 45 #if DRAW_SKIA_CLIP |
| 36 | 46 |
| 37 static SkPaint DebugClipPaint() { | 47 static SkPaint DebugClipPaint() { |
| 38 SkPaint paint; | 48 SkPaint paint; |
| 39 paint.setAntiAlias(true); | 49 paint.setAntiAlias(true); |
| 40 paint.setColor(SK_ColorGREEN); | 50 paint.setColor(SK_ColorGREEN); |
| 41 paint.setStyle(SkPaint::kStroke_Style); | 51 paint.setStyle(SkPaint::kStroke_Style); |
| 42 return paint; | 52 return paint; |
| 43 } | 53 } |
| 44 | 54 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 #else // DRAW_SKIA_CLIP | 65 #else // DRAW_SKIA_CLIP |
| 56 | 66 |
| 57 static void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} | 67 static void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} |
| 58 static void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} | 68 static void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} |
| 59 | 69 |
| 60 #endif // DRAW_SKIA_CLIP | 70 #endif // DRAW_SKIA_CLIP |
| 61 | 71 |
| 62 #undef SHOW_SKIA_PATH | 72 #undef SHOW_SKIA_PATH |
| 63 #undef DRAW_SKIA_CLIP | 73 #undef DRAW_SKIA_CLIP |
| 64 | 74 |
| 65 static SkPath BuildPath(const CFX_PathData* pPathData, | 75 static SkPath BuildPath(const CFX_PathData* pPathData) { |
| 66 const CFX_Matrix* pObject2Device) { | |
| 67 SkPath skPath; | 76 SkPath skPath; |
| 68 const CFX_PathData* pFPath = pPathData; | 77 const CFX_PathData* pFPath = pPathData; |
| 69 int nPoints = pFPath->GetPointCount(); | 78 int nPoints = pFPath->GetPointCount(); |
| 70 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 79 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
| 71 for (int i = 0; i < nPoints; i++) { | 80 for (int i = 0; i < nPoints; i++) { |
| 72 FX_FLOAT x = pPoints[i].m_PointX; | 81 FX_FLOAT x = pPoints[i].m_PointX; |
| 73 FX_FLOAT y = pPoints[i].m_PointY; | 82 FX_FLOAT y = pPoints[i].m_PointY; |
| 74 if (pObject2Device) | |
| 75 pObject2Device->Transform(x, y); | |
| 76 int point_type = pPoints[i].m_Flag & FXPT_TYPE; | 83 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
| 77 if (point_type == FXPT_MOVETO) { | 84 if (point_type == FXPT_MOVETO) { |
| 78 skPath.moveTo(x, y); | 85 skPath.moveTo(x, y); |
| 79 } else if (point_type == FXPT_LINETO) { | 86 } else if (point_type == FXPT_LINETO) { |
| 80 skPath.lineTo(x, y); | 87 skPath.lineTo(x, y); |
| 81 } else if (point_type == FXPT_BEZIERTO) { | 88 } else if (point_type == FXPT_BEZIERTO) { |
| 82 FX_FLOAT x2 = pPoints[i + 1].m_PointX, y2 = pPoints[i + 1].m_PointY; | 89 FX_FLOAT x2 = pPoints[i + 1].m_PointX, y2 = pPoints[i + 1].m_PointY; |
| 83 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; | 90 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; |
| 84 if (pObject2Device) { | |
| 85 pObject2Device->Transform(x2, y2); | |
| 86 pObject2Device->Transform(x3, y3); | |
| 87 } | |
| 88 skPath.cubicTo(x, y, x2, y2, x3, y3); | 91 skPath.cubicTo(x, y, x2, y2, x3, y3); |
| 89 i += 2; | 92 i += 2; |
| 90 } | 93 } |
| 91 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 94 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) |
| 92 skPath.close(); | 95 skPath.close(); |
| 93 } | 96 } |
| 94 return skPath; | 97 return skPath; |
| 95 } | 98 } |
| 96 | 99 |
| 97 // convert a stroking path to scanlines | 100 // convert a stroking path to scanlines |
| 98 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, | 101 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, |
| 99 const CFX_GraphStateData* pGraphState) { | 102 const CFX_GraphStateData* pGraphState, |
| 103 const SkMatrix& matrix) { | |
| 100 SkPaint::Cap cap; | 104 SkPaint::Cap cap; |
| 101 switch (pGraphState->m_LineCap) { | 105 switch (pGraphState->m_LineCap) { |
| 102 case CFX_GraphStateData::LineCapRound: | 106 case CFX_GraphStateData::LineCapRound: |
| 103 cap = SkPaint::kRound_Cap; | 107 cap = SkPaint::kRound_Cap; |
| 104 break; | 108 break; |
| 105 case CFX_GraphStateData::LineCapSquare: | 109 case CFX_GraphStateData::LineCapSquare: |
| 106 cap = SkPaint::kSquare_Cap; | 110 cap = SkPaint::kSquare_Cap; |
| 107 break; | 111 break; |
| 108 default: | 112 default: |
| 109 cap = SkPaint::kButt_Cap; | 113 cap = SkPaint::kButt_Cap; |
| 110 break; | 114 break; |
| 111 } | 115 } |
| 112 SkPaint::Join join; | 116 SkPaint::Join join; |
| 113 switch (pGraphState->m_LineJoin) { | 117 switch (pGraphState->m_LineJoin) { |
| 114 case CFX_GraphStateData::LineJoinRound: | 118 case CFX_GraphStateData::LineJoinRound: |
| 115 join = SkPaint::kRound_Join; | 119 join = SkPaint::kRound_Join; |
| 116 break; | 120 break; |
| 117 case CFX_GraphStateData::LineJoinBevel: | 121 case CFX_GraphStateData::LineJoinBevel: |
| 118 join = SkPaint::kBevel_Join; | 122 join = SkPaint::kBevel_Join; |
| 119 break; | 123 break; |
| 120 default: | 124 default: |
| 121 join = SkPaint::kMiter_Join; | 125 join = SkPaint::kMiter_Join; |
| 122 break; | 126 break; |
| 123 } | 127 } |
| 124 FX_FLOAT width = pGraphState->m_LineWidth; | 128 SkMatrix inverse; |
| 125 | 129 if (!matrix.invert(&inverse)) |
| 130 return; // give up if the matrix is degenerate, and not invertable | |
| 131 inverse.set(SkMatrix::kMTransX, 0); | |
| 132 inverse.set(SkMatrix::kMTransY, 0); | |
| 133 SkVector deviceUnits[2] = {{0, 1}, {1, 0}}; | |
| 134 inverse.mapPoints(deviceUnits, SK_ARRAY_COUNT(deviceUnits)); | |
| 135 FX_FLOAT width = SkTMax(pGraphState->m_LineWidth, | |
| 136 SkTMin(deviceUnits[0].length(), deviceUnits[1].length( ))); | |
|
Tom Sepez
2016/03/17 16:05:50
nit: ditto. git cl format should have fixed these
caryclark
2016/03/18 18:22:12
Done.
| |
| 126 if (pGraphState->m_DashArray) { | 137 if (pGraphState->m_DashArray) { |
| 127 int count = (pGraphState->m_DashCount + 1) / 2; | 138 int count = (pGraphState->m_DashCount + 1) / 2; |
| 128 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); | 139 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); |
| 129 // Set dash pattern | 140 // Set dash pattern |
| 130 for (int i = 0; i < count; i++) { | 141 for (int i = 0; i < count; i++) { |
| 131 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; | 142 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; |
| 132 if (on <= 0.000001f) | 143 if (on <= 0.000001f) |
| 133 on = 1.f / 10; | 144 on = 1.f / 10; |
| 134 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount | 145 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount |
| 135 ? on | 146 ? on |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 196 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
| 186 m_ditherBits = 0; | 197 m_ditherBits = 0; |
| 187 } | 198 } |
| 188 | 199 |
| 189 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 200 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
| 190 if (!m_pRecorder) | 201 if (!m_pRecorder) |
| 191 delete m_pCanvas; | 202 delete m_pCanvas; |
| 192 delete m_pAggDriver; | 203 delete m_pAggDriver; |
| 193 } | 204 } |
| 194 | 205 |
| 206 static SkMatrix ToSkMatrix(const CFX_Matrix& m) { | |
|
Tom Sepez
2016/03/17 16:05:50
nit: an we put these up top in the file with the
caryclark
2016/03/18 18:22:12
Done.
| |
| 207 SkMatrix skMatrix; | |
| 208 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | |
|
Tom Sepez
2016/03/17 16:05:50
nit: Pity SkMatrix doesn't have a constructor of t
caryclark
2016/03/18 18:22:12
Would you like a bug filed to request this feature
| |
| 209 return skMatrix; | |
| 210 } | |
| 211 | |
| 212 // use when pdf's y-axis points up insead of down | |
| 213 static SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m) { | |
| 214 SkMatrix skMatrix; | |
| 215 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1); | |
| 216 return skMatrix; | |
| 217 } | |
| 218 | |
| 195 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 219 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
| 196 const FXTEXT_CHARPOS* pCharPos, | 220 const FXTEXT_CHARPOS* pCharPos, |
| 197 CFX_Font* pFont, | 221 CFX_Font* pFont, |
| 198 CFX_FontCache* pCache, | 222 CFX_FontCache* pCache, |
| 199 const CFX_Matrix* pObject2Device, | 223 const CFX_Matrix* pObject2Device, |
| 200 FX_FLOAT font_size, | 224 FX_FLOAT font_size, |
| 201 FX_DWORD color, | 225 FX_DWORD color, |
| 202 int alpha_flag, | 226 int alpha_flag, |
| 203 void* pIccTransform) { | 227 void* pIccTransform) { |
| 204 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( | 228 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( |
| 205 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); | 229 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); |
| 206 SkPaint paint; | 230 SkPaint paint; |
| 207 paint.setAntiAlias(true); | 231 paint.setAntiAlias(true); |
| 208 paint.setColor(color); | 232 paint.setColor(color); |
| 209 paint.setTypeface(typeface); | 233 paint.setTypeface(typeface); |
| 210 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 234 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 211 paint.setTextSize(font_size); | 235 paint.setTextSize(font_size); |
| 212 m_pCanvas->save(); | 236 m_pCanvas->save(); |
| 213 SkMatrix skMatrix; | 237 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); |
| 214 const CFX_Matrix& m = *pObject2Device; | |
| 215 // note that PDF's y-axis goes up; Skia's y-axis goes down | |
| 216 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1); | |
| 217 m_pCanvas->concat(skMatrix); | 238 m_pCanvas->concat(skMatrix); |
| 218 for (int index = 0; index < nChars; ++index) { | 239 for (int index = 0; index < nChars; ++index) { |
| 219 const FXTEXT_CHARPOS& cp = pCharPos[index]; | 240 const FXTEXT_CHARPOS& cp = pCharPos[index]; |
| 220 uint16_t glyph = (uint16_t)cp.m_GlyphIndex; | 241 uint16_t glyph = (uint16_t)cp.m_GlyphIndex; |
| 221 m_pCanvas->drawText(&glyph, 2, cp.m_OriginX, cp.m_OriginY, paint); | 242 m_pCanvas->drawText(&glyph, 2, cp.m_OriginX, cp.m_OriginY, paint); |
| 222 } | 243 } |
| 223 m_pCanvas->restore(); | 244 m_pCanvas->restore(); |
| 224 return TRUE; | 245 return TRUE; |
| 225 } | 246 } |
| 226 | 247 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 241 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | | 262 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | |
| 242 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT; | 263 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT; |
| 243 case FXDC_DITHER_BITS: | 264 case FXDC_DITHER_BITS: |
| 244 return m_ditherBits; | 265 return m_ditherBits; |
| 245 } | 266 } |
| 246 return 0; | 267 return 0; |
| 247 } | 268 } |
| 248 | 269 |
| 249 void CFX_SkiaDeviceDriver::SaveState() { | 270 void CFX_SkiaDeviceDriver::SaveState() { |
| 250 m_pCanvas->save(); | 271 m_pCanvas->save(); |
| 251 if (m_pAggDriver) | |
| 252 m_pAggDriver->SaveState(); | |
| 253 } | 272 } |
| 254 | 273 |
| 255 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved) { | 274 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved) { |
| 256 if (m_pAggDriver) | |
| 257 m_pAggDriver->RestoreState(bKeepSaved); | |
| 258 m_pCanvas->restore(); | 275 m_pCanvas->restore(); |
| 259 if (bKeepSaved) | 276 if (bKeepSaved) |
| 260 m_pCanvas->save(); | 277 m_pCanvas->save(); |
| 261 } | 278 } |
| 262 | 279 |
| 263 void CFX_SkiaDeviceDriver::SetClipMask( | |
| 264 agg::rasterizer_scanline_aa& rasterizer) { | |
| 265 if (m_pAggDriver) | |
| 266 m_pAggDriver->SetClipMask(rasterizer); | |
| 267 } | |
| 268 | |
| 269 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( | 280 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( |
| 270 const CFX_PathData* pPathData, // path info | 281 const CFX_PathData* pPathData, // path info |
| 271 const CFX_Matrix* pObject2Device, // flips object's y-axis | 282 const CFX_Matrix* pObject2Device, // flips object's y-axis |
| 272 int fill_mode // fill mode, WINDING or ALTERNATE | 283 int fill_mode // fill mode, WINDING or ALTERNATE |
| 273 ) { | 284 ) { |
| 274 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 285 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
| 275 CFX_FloatRect rectf; | 286 CFX_FloatRect rectf; |
| 276 if (pPathData->IsRect(pObject2Device, &rectf)) { | 287 if (pPathData->IsRect(pObject2Device, &rectf)) { |
| 277 rectf.Intersect( | 288 rectf.Intersect( |
| 278 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 289 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 279 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 290 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 280 // note that PDF's y-axis goes up; Skia's y-axis goes down | 291 // note that PDF's y-axis goes up; Skia's y-axis goes down |
| 281 SkRect skClipRect = | 292 SkRect skClipRect = |
| 282 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); | 293 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); |
| 283 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); | 294 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); |
| 284 m_pCanvas->clipRect(skClipRect); | 295 m_pCanvas->clipRect(skClipRect); |
| 285 return TRUE; | 296 return TRUE; |
| 286 } | 297 } |
| 287 } | 298 } |
| 288 SkPath skClipPath = BuildPath(pPathData, pObject2Device); | 299 SkPath skClipPath = BuildPath(pPathData); |
| 289 skClipPath.setFillType((fill_mode & 3) == FXFILL_WINDING | 300 skClipPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
| 290 ? SkPath::kWinding_FillType | 301 ? SkPath::kWinding_FillType |
| 291 : SkPath::kEvenOdd_FillType); | 302 : SkPath::kEvenOdd_FillType); |
| 303 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | |
|
Tom Sepez
2016/03/17 16:05:50
nit: local not needed.
caryclark
2016/03/18 18:22:12
While that's strictly true, it is easier to debug
| |
| 304 skClipPath.transform(skMatrix); | |
| 292 DebugShowSkiaPath(skClipPath); | 305 DebugShowSkiaPath(skClipPath); |
| 293 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); | 306 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); |
| 294 m_pCanvas->clipPath(skClipPath); | 307 m_pCanvas->clipPath(skClipPath); |
| 295 | 308 |
| 296 return TRUE; | 309 return TRUE; |
| 297 } | 310 } |
| 298 | 311 |
| 299 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( | 312 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( |
| 300 const CFX_PathData* pPathData, // path info | 313 const CFX_PathData* pPathData, // path info |
| 301 const CFX_Matrix* pObject2Device, // optional transformation | 314 const CFX_Matrix* pObject2Device, // optional transformation |
| 302 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 315 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
| 303 ) { | 316 ) { |
| 304 // build path data | 317 // build path data |
| 305 SkPath skPath = BuildPath(pPathData, NULL); | 318 SkPath skPath = BuildPath(pPathData); |
| 306 skPath.setFillType(SkPath::kWinding_FillType); | 319 skPath.setFillType(SkPath::kWinding_FillType); |
| 307 | 320 |
| 321 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | |
| 308 SkPaint spaint; | 322 SkPaint spaint; |
| 309 PaintStroke(&spaint, pGraphState); | 323 PaintStroke(&spaint, pGraphState, skMatrix); |
| 310 SkPath dst_path; | 324 SkPath dst_path; |
| 311 spaint.getFillPath(skPath, &dst_path); | 325 spaint.getFillPath(skPath, &dst_path); |
| 326 dst_path.transform(skMatrix); | |
| 312 DebugDrawSkiaClipPath(m_pCanvas, dst_path); | 327 DebugDrawSkiaClipPath(m_pCanvas, dst_path); |
| 313 m_pCanvas->clipPath(dst_path); | 328 m_pCanvas->clipPath(dst_path); |
| 314 return TRUE; | 329 return TRUE; |
| 315 } | 330 } |
| 316 | 331 |
| 317 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizer( | |
| 318 agg::rasterizer_scanline_aa& rasterizer, | |
| 319 FX_DWORD color, | |
| 320 FX_BOOL bFullCover, | |
| 321 FX_BOOL bGroupKnockout, | |
| 322 int alpha_flag, | |
| 323 void* pIccTransform) { | |
| 324 return m_pAggDriver && | |
| 325 m_pAggDriver->RenderRasterizer(rasterizer, color, bFullCover, | |
| 326 bGroupKnockout, alpha_flag, | |
| 327 pIccTransform); | |
| 328 } | |
| 329 | |
| 330 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 332 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( |
| 331 const CFX_PathData* pPathData, // path info | 333 const CFX_PathData* pPathData, // path info |
| 332 const CFX_Matrix* pObject2Device, // optional transformation | 334 const CFX_Matrix* pObject2Device, // optional transformation |
| 333 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 335 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
| 334 FX_DWORD fill_color, // fill color | 336 FX_DWORD fill_color, // fill color |
| 335 FX_DWORD stroke_color, // stroke color | 337 FX_DWORD stroke_color, // stroke color |
| 336 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 338 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
| 337 int alpha_flag, | 339 int alpha_flag, |
| 338 void* pIccTransform, | 340 void* pIccTransform, |
| 339 int blend_type) { | 341 int blend_type) { |
| 340 SkIRect rect; | 342 SkIRect rect; |
| 341 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 343 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 342 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 344 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 343 SkPath skPath = BuildPath(pPathData, pObject2Device); | 345 SkPath skPath = BuildPath(pPathData); |
| 344 SkPaint spaint; | 346 SkPaint spaint; |
| 345 spaint.setAntiAlias(true); | 347 spaint.setAntiAlias(true); |
| 348 m_pCanvas->save(); | |
| 349 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | |
| 350 m_pCanvas->concat(skMatrix); | |
| 346 if ((fill_mode & 3) && fill_color) { | 351 if ((fill_mode & 3) && fill_color) { |
| 347 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING | 352 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
| 348 ? SkPath::kWinding_FillType | 353 ? SkPath::kWinding_FillType |
| 349 : SkPath::kEvenOdd_FillType); | 354 : SkPath::kEvenOdd_FillType); |
| 350 | 355 |
| 351 spaint.setStyle(SkPaint::kFill_Style); | 356 spaint.setStyle(SkPaint::kFill_Style); |
| 352 spaint.setColor(fill_color); | 357 spaint.setColor(fill_color); |
| 353 m_pCanvas->drawPath(skPath, spaint); | 358 m_pCanvas->drawPath(skPath, spaint); |
| 354 } | 359 } |
| 355 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 360 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) |
| 356 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) | 361 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) |
| 357 : FXARGB_A(stroke_color); | 362 : FXARGB_A(stroke_color); |
| 358 | 363 |
| 359 if (pGraphState && stroke_alpha) { | 364 if (pGraphState && stroke_alpha) { |
| 360 spaint.setColor(stroke_color); | 365 spaint.setColor(stroke_color); |
| 361 PaintStroke(&spaint, pGraphState); | 366 PaintStroke(&spaint, pGraphState, skMatrix); |
| 367 DebugShowSkiaPath(skPath); | |
| 368 DebugShowCanvasMatrix(m_pCanvas); | |
| 362 m_pCanvas->drawPath(skPath, spaint); | 369 m_pCanvas->drawPath(skPath, spaint); |
| 363 } | 370 } |
| 364 | 371 m_pCanvas->restore(); |
| 365 return TRUE; | 372 return TRUE; |
| 366 } | 373 } |
| 367 | 374 |
| 368 FX_BOOL CFX_SkiaDeviceDriver::SetPixel(int x, | |
| 369 int y, | |
| 370 FX_DWORD color, | |
| 371 int alpha_flag, | |
| 372 void* pIccTransform) { | |
| 373 return m_pAggDriver && | |
| 374 m_pAggDriver->SetPixel(x, y, color, alpha_flag, pIccTransform); | |
| 375 } | |
| 376 | |
| 377 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, | 375 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, |
| 378 FX_DWORD fill_color, | 376 FX_DWORD fill_color, |
| 379 int alpha_flag, | 377 int alpha_flag, |
| 380 void* pIccTransform, | 378 void* pIccTransform, |
| 381 int blend_type) { | 379 int blend_type) { |
| 382 SkPaint spaint; | 380 SkPaint spaint; |
| 383 spaint.setAntiAlias(true); | 381 spaint.setAntiAlias(true); |
| 384 spaint.setColor(fill_color); | 382 spaint.setColor(fill_color); |
| 385 | 383 |
| 386 m_pCanvas->drawRect( | 384 m_pCanvas->drawRect( |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 m_pCanvas->concat(skMatrix); | 505 m_pCanvas->concat(skMatrix); |
| 508 const CFX_Matrix& m = *pMatrix; | 506 const CFX_Matrix& m = *pMatrix; |
| 509 // note that PDF's y-axis goes up; Skia's y-axis goes down | 507 // note that PDF's y-axis goes up; Skia's y-axis goes down |
| 510 if (landscape) | 508 if (landscape) |
| 511 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | 509 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1); |
| 512 else | 510 else |
| 513 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1); | 511 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1); |
| 514 m_pCanvas->concat(skMatrix); | 512 m_pCanvas->concat(skMatrix); |
| 515 SkPaint paint; | 513 SkPaint paint; |
| 516 paint.setAntiAlias(true); | 514 paint.setAntiAlias(true); |
| 517 paint.setFilterQuality(kLow_SkFilterQuality); | 515 paint.setFilterQuality(kHigh_SkFilterQuality); |
| 518 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); | 516 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); |
| 519 m_pCanvas->restore(); | 517 m_pCanvas->restore(); |
| 520 return TRUE; | 518 return TRUE; |
| 521 } | 519 } |
| 522 | 520 |
| 523 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { | 521 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
| 524 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause); | 522 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause); |
| 525 } | 523 } |
| 526 | 524 |
| 527 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { | 525 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 SetDeviceDriver(pDriver); | 574 SetDeviceDriver(pDriver); |
| 577 return TRUE; | 575 return TRUE; |
| 578 } | 576 } |
| 579 | 577 |
| 580 CFX_SkiaDevice::~CFX_SkiaDevice() { | 578 CFX_SkiaDevice::~CFX_SkiaDevice() { |
| 581 if (m_bOwnedBitmap && GetBitmap()) | 579 if (m_bOwnedBitmap && GetBitmap()) |
| 582 delete GetBitmap(); | 580 delete GetBitmap(); |
| 583 } | 581 } |
| 584 | 582 |
| 585 #endif | 583 #endif |
| OLD | NEW |