Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1174)

Side by Side Diff: core/fxge/skia/fx_skia_device.cpp

Issue 1812263002: fix windows build; add blend modes (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/include/fxge/fx_ge.h" 5 #include "core/include/fxge/fx_ge.h"
6 6
7 #if defined(_SKIA_SUPPORT_) 7 #if defined(_SKIA_SUPPORT_)
8 #include "core/include/fxcodec/fx_codec.h" 8 #include "core/include/fxcodec/fx_codec.h"
9 9
10 #include "core/fxge/agg/fx_agg_driver.h" 10 #include "core/fxge/agg/fx_agg_driver.h"
(...skipping 19 matching lines...) Expand all
30 path.dump(&stream, false, false); 30 path.dump(&stream, false, false);
31 printf("%s\n", buffer); 31 printf("%s\n", buffer);
32 #endif // SHOW_SKIA_PATH 32 #endif // SHOW_SKIA_PATH
33 } 33 }
34 34
35 static void DebugShowCanvasMatrix(const SkCanvas* canvas) { 35 static void DebugShowCanvasMatrix(const SkCanvas* canvas) {
36 #if SHOW_SKIA_PATH 36 #if SHOW_SKIA_PATH
37 SkMatrix matrix = canvas->getTotalMatrix(); 37 SkMatrix matrix = canvas->getTotalMatrix();
38 SkScalar m[9]; 38 SkScalar m[9];
39 matrix.get9(m); 39 matrix.get9(m);
40 printf("(%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], m[4], m[5 ], m[6], 40 printf("(%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], m[4],
41 m[7], m[8]); 41 m[5], m[6], m[7], m[8]);
42 #endif // SHOW_SKIA_PATH 42 #endif // SHOW_SKIA_PATH
43 } 43 }
44 44
45 #if DRAW_SKIA_CLIP 45 #if DRAW_SKIA_CLIP
46 46
47 static SkPaint DebugClipPaint() { 47 static SkPaint DebugClipPaint() {
48 SkPaint paint; 48 SkPaint paint;
49 paint.setAntiAlias(true); 49 paint.setAntiAlias(true);
50 paint.setColor(SK_ColorGREEN); 50 paint.setColor(SK_ColorGREEN);
51 paint.setStyle(SkPaint::kStroke_Style); 51 paint.setStyle(SkPaint::kStroke_Style);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; 90 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY;
91 skPath.cubicTo(x, y, x2, y2, x3, y3); 91 skPath.cubicTo(x, y, x2, y2, x3, y3);
92 i += 2; 92 i += 2;
93 } 93 }
94 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) 94 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE)
95 skPath.close(); 95 skPath.close();
96 } 96 }
97 return skPath; 97 return skPath;
98 } 98 }
99 99
100 static SkMatrix ToSkMatrix(const CFX_Matrix& m) {
101 SkMatrix skMatrix;
102 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1);
103 return skMatrix;
104 }
105
106 // use when pdf's y-axis points up insead of down
107 static SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m) {
108 SkMatrix skMatrix;
109 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1);
110 return skMatrix;
111 }
112
113 static SkXfermode::Mode GetSkiaBlendMode(int blend_type) {
114 switch (blend_type) {
115 case FXDIB_BLEND_MULTIPLY:
116 return SkXfermode::kMultiply_Mode;
117 case FXDIB_BLEND_SCREEN:
118 return SkXfermode::kScreen_Mode;
119 case FXDIB_BLEND_OVERLAY:
120 return SkXfermode::kOverlay_Mode;
121 case FXDIB_BLEND_DARKEN:
122 return SkXfermode::kDarken_Mode;
123 case FXDIB_BLEND_LIGHTEN:
124 return SkXfermode::kLighten_Mode;
125 case FXDIB_BLEND_COLORDODGE:
126 return SkXfermode::kColorDodge_Mode;
127 case FXDIB_BLEND_COLORBURN:
128 return SkXfermode::kColorBurn_Mode;
129 case FXDIB_BLEND_HARDLIGHT:
130 return SkXfermode::kHardLight_Mode;
131 case FXDIB_BLEND_SOFTLIGHT:
132 return SkXfermode::kSoftLight_Mode;
133 case FXDIB_BLEND_DIFFERENCE:
134 return SkXfermode::kDifference_Mode;
135 case FXDIB_BLEND_EXCLUSION:
136 return SkXfermode::kExclusion_Mode;
137 case FXDIB_BLEND_HUE:
138 return SkXfermode::kHue_Mode;
139 case FXDIB_BLEND_SATURATION:
140 return SkXfermode::kSaturation_Mode;
141 case FXDIB_BLEND_COLOR:
142 return SkXfermode::kColor_Mode;
143 case FXDIB_BLEND_LUMINOSITY:
144 return SkXfermode::kLuminosity_Mode;
145 case FXDIB_BLEND_NORMAL:
146 default:
147 return SkXfermode::kSrcOver_Mode;
148 }
149 }
150
100 // convert a stroking path to scanlines 151 // convert a stroking path to scanlines
101 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, 152 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
102 const CFX_GraphStateData* pGraphState, 153 const CFX_GraphStateData* pGraphState,
103 const SkMatrix& matrix) { 154 const SkMatrix& matrix) {
104 SkPaint::Cap cap; 155 SkPaint::Cap cap;
105 switch (pGraphState->m_LineCap) { 156 switch (pGraphState->m_LineCap) {
106 case CFX_GraphStateData::LineCapRound: 157 case CFX_GraphStateData::LineCapRound:
107 cap = SkPaint::kRound_Cap; 158 cap = SkPaint::kRound_Cap;
108 break; 159 break;
109 case CFX_GraphStateData::LineCapSquare: 160 case CFX_GraphStateData::LineCapSquare:
(...skipping 15 matching lines...) Expand all
125 join = SkPaint::kMiter_Join; 176 join = SkPaint::kMiter_Join;
126 break; 177 break;
127 } 178 }
128 SkMatrix inverse; 179 SkMatrix inverse;
129 if (!matrix.invert(&inverse)) 180 if (!matrix.invert(&inverse))
130 return; // give up if the matrix is degenerate, and not invertable 181 return; // give up if the matrix is degenerate, and not invertable
131 inverse.set(SkMatrix::kMTransX, 0); 182 inverse.set(SkMatrix::kMTransX, 0);
132 inverse.set(SkMatrix::kMTransY, 0); 183 inverse.set(SkMatrix::kMTransY, 0);
133 SkVector deviceUnits[2] = {{0, 1}, {1, 0}}; 184 SkVector deviceUnits[2] = {{0, 1}, {1, 0}};
134 inverse.mapPoints(deviceUnits, SK_ARRAY_COUNT(deviceUnits)); 185 inverse.mapPoints(deviceUnits, SK_ARRAY_COUNT(deviceUnits));
135 FX_FLOAT width = SkTMax(pGraphState->m_LineWidth, 186 FX_FLOAT width =
136 SkTMin(deviceUnits[0].length(), deviceUnits[1].length( ))); 187 SkTMax(pGraphState->m_LineWidth,
188 SkTMin(deviceUnits[0].length(), deviceUnits[1].length()));
137 if (pGraphState->m_DashArray) { 189 if (pGraphState->m_DashArray) {
138 int count = (pGraphState->m_DashCount + 1) / 2; 190 int count = (pGraphState->m_DashCount + 1) / 2;
139 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); 191 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar));
140 // Set dash pattern 192 // Set dash pattern
141 for (int i = 0; i < count; i++) { 193 for (int i = 0; i < count; i++) {
142 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; 194 FX_FLOAT on = pGraphState->m_DashArray[i * 2];
143 if (on <= 0.000001f) 195 if (on <= 0.000001f)
144 on = 1.f / 10; 196 on = 1.f / 10;
145 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount 197 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount
146 ? on 198 ? on
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 m_pCanvas = m_pRecorder->getRecordingCanvas(); 248 m_pCanvas = m_pRecorder->getRecordingCanvas();
197 m_ditherBits = 0; 249 m_ditherBits = 0;
198 } 250 }
199 251
200 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { 252 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() {
201 if (!m_pRecorder) 253 if (!m_pRecorder)
202 delete m_pCanvas; 254 delete m_pCanvas;
203 delete m_pAggDriver; 255 delete m_pAggDriver;
204 } 256 }
205 257
206 static SkMatrix ToSkMatrix(const CFX_Matrix& m) {
207 SkMatrix skMatrix;
208 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1);
209 return skMatrix;
210 }
211
212 // use when pdf's y-axis points up insead of down
213 static SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m) {
214 SkMatrix skMatrix;
215 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1);
216 return skMatrix;
217 }
218
219 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, 258 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars,
220 const FXTEXT_CHARPOS* pCharPos, 259 const FXTEXT_CHARPOS* pCharPos,
221 CFX_Font* pFont, 260 CFX_Font* pFont,
222 CFX_FontCache* pCache, 261 CFX_FontCache* pCache,
223 const CFX_Matrix* pObject2Device, 262 const CFX_Matrix* pObject2Device,
224 FX_FLOAT font_size, 263 FX_FLOAT font_size,
225 FX_DWORD color, 264 FX_DWORD color,
226 int alpha_flag, 265 int alpha_flag,
227 void* pIccTransform) { 266 void* pIccTransform) {
228 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( 267 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled 377 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled
339 int alpha_flag, 378 int alpha_flag,
340 void* pIccTransform, 379 void* pIccTransform,
341 int blend_type) { 380 int blend_type) {
342 SkIRect rect; 381 SkIRect rect;
343 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), 382 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH),
344 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 383 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
345 SkPath skPath = BuildPath(pPathData); 384 SkPath skPath = BuildPath(pPathData);
346 SkPaint spaint; 385 SkPaint spaint;
347 spaint.setAntiAlias(true); 386 spaint.setAntiAlias(true);
387 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type));
348 m_pCanvas->save(); 388 m_pCanvas->save();
349 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); 389 SkMatrix skMatrix = ToSkMatrix(*pObject2Device);
350 m_pCanvas->concat(skMatrix); 390 m_pCanvas->concat(skMatrix);
351 if ((fill_mode & 3) && fill_color) { 391 if ((fill_mode & 3) && fill_color) {
352 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING 392 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING
353 ? SkPath::kWinding_FillType 393 ? SkPath::kWinding_FillType
354 : SkPath::kEvenOdd_FillType); 394 : SkPath::kEvenOdd_FillType);
355 395
356 spaint.setStyle(SkPaint::kFill_Style); 396 spaint.setStyle(SkPaint::kFill_Style);
357 spaint.setColor(fill_color); 397 spaint.setColor(fill_color);
(...skipping 15 matching lines...) Expand all
373 } 413 }
374 414
375 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, 415 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect,
376 FX_DWORD fill_color, 416 FX_DWORD fill_color,
377 int alpha_flag, 417 int alpha_flag,
378 void* pIccTransform, 418 void* pIccTransform,
379 int blend_type) { 419 int blend_type) {
380 SkPaint spaint; 420 SkPaint spaint;
381 spaint.setAntiAlias(true); 421 spaint.setAntiAlias(true);
382 spaint.setColor(fill_color); 422 spaint.setColor(fill_color);
423 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type));
383 424
384 m_pCanvas->drawRect( 425 m_pCanvas->drawRect(
385 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), 426 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom),
386 spaint); 427 spaint);
387 return TRUE; 428 return TRUE;
388 } 429 }
389 430
390 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { 431 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) {
391 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead 432 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead
392 pRect->left = 0; 433 pRect->left = 0;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 const CFX_Matrix& m = *pMatrix; 547 const CFX_Matrix& m = *pMatrix;
507 // note that PDF's y-axis goes up; Skia's y-axis goes down 548 // note that PDF's y-axis goes up; Skia's y-axis goes down
508 if (landscape) 549 if (landscape)
509 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1); 550 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1);
510 else 551 else
511 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1); 552 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1);
512 m_pCanvas->concat(skMatrix); 553 m_pCanvas->concat(skMatrix);
513 SkPaint paint; 554 SkPaint paint;
514 paint.setAntiAlias(true); 555 paint.setAntiAlias(true);
515 paint.setFilterQuality(kHigh_SkFilterQuality); 556 paint.setFilterQuality(kHigh_SkFilterQuality);
557 paint.setXfermodeMode(GetSkiaBlendMode(blend_type));
516 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); 558 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint);
517 m_pCanvas->restore(); 559 m_pCanvas->restore();
518 return TRUE; 560 return TRUE;
519 } 561 }
520 562
521 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { 563 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) {
522 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause); 564 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause);
523 } 565 }
524 566
525 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { 567 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 SetDeviceDriver(pDriver); 616 SetDeviceDriver(pDriver);
575 return TRUE; 617 return TRUE;
576 } 618 }
577 619
578 CFX_SkiaDevice::~CFX_SkiaDevice() { 620 CFX_SkiaDevice::~CFX_SkiaDevice() {
579 if (m_bOwnedBitmap && GetBitmap()) 621 if (m_bOwnedBitmap && GetBitmap())
580 delete GetBitmap(); 622 delete GetBitmap();
581 } 623 }
582 624
583 #endif 625 #endif
OLDNEW
« no previous file with comments | « core/fxge/skia/fx_skia_device.h ('k') | skia/skia_library.gypi » ('j') | skia/skia_library.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698