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/fxge/include/fx_ge.h" | 5 #include "core/fxge/include/fx_ge.h" |
6 | 6 |
7 #if defined(_SKIA_SUPPORT_) | 7 #if defined(_SKIA_SUPPORT_) |
| 8 #include <algorithm> |
| 9 #include <vector> |
| 10 |
8 #include "core/fxcodec/include/fx_codec.h" | 11 #include "core/fxcodec/include/fx_codec.h" |
9 | 12 |
10 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" | 13 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" |
11 #include "core/fpdfapi/fpdf_page/pageint.h" | 14 #include "core/fpdfapi/fpdf_page/pageint.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
15 #include "core/fxge/skia/fx_skia_device.h" | 18 #include "core/fxge/skia/fx_skia_device.h" |
16 | 19 |
17 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 if (!m_pRecorder) | 587 if (!m_pRecorder) |
585 delete m_pCanvas; | 588 delete m_pCanvas; |
586 } | 589 } |
587 | 590 |
588 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 591 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
589 const FXTEXT_CHARPOS* pCharPos, | 592 const FXTEXT_CHARPOS* pCharPos, |
590 CFX_Font* pFont, | 593 CFX_Font* pFont, |
591 CFX_FontCache* pCache, | 594 CFX_FontCache* pCache, |
592 const CFX_Matrix* pObject2Device, | 595 const CFX_Matrix* pObject2Device, |
593 FX_FLOAT font_size, | 596 FX_FLOAT font_size, |
594 uint32_t color, | 597 uint32_t color) { |
595 int alpha_flag, | |
596 void* pIccTransform) { | |
597 sk_sp<SkTypeface> typeface(SkSafeRef(pCache->GetDeviceCache(pFont))); | 598 sk_sp<SkTypeface> typeface(SkSafeRef(pCache->GetDeviceCache(pFont))); |
598 SkPaint paint; | 599 SkPaint paint; |
599 paint.setAntiAlias(true); | 600 paint.setAntiAlias(true); |
600 paint.setColor(color); | 601 paint.setColor(color); |
601 paint.setTypeface(typeface); | 602 paint.setTypeface(typeface); |
602 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 603 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
603 paint.setTextSize(font_size); | 604 paint.setTextSize(font_size); |
604 paint.setSubpixelText(true); | 605 paint.setSubpixelText(true); |
605 m_pCanvas->save(); | 606 m_pCanvas->save(); |
606 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); | 607 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 return TRUE; | 703 return TRUE; |
703 } | 704 } |
704 | 705 |
705 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 706 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( |
706 const CFX_PathData* pPathData, // path info | 707 const CFX_PathData* pPathData, // path info |
707 const CFX_Matrix* pObject2Device, // optional transformation | 708 const CFX_Matrix* pObject2Device, // optional transformation |
708 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 709 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
709 uint32_t fill_color, // fill color | 710 uint32_t fill_color, // fill color |
710 uint32_t stroke_color, // stroke color | 711 uint32_t stroke_color, // stroke color |
711 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 712 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
712 int alpha_flag, | |
713 void* pIccTransform, | |
714 int blend_type) { | 713 int blend_type) { |
715 SkIRect rect; | 714 SkIRect rect; |
716 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 715 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
717 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 716 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
718 SkMatrix skMatrix; | 717 SkMatrix skMatrix; |
719 if (pObject2Device) | 718 if (pObject2Device) |
720 skMatrix = ToSkMatrix(*pObject2Device); | 719 skMatrix = ToSkMatrix(*pObject2Device); |
721 else | 720 else |
722 skMatrix.setIdentity(); | 721 skMatrix.setIdentity(); |
723 SkPaint skPaint; | 722 SkPaint skPaint; |
724 skPaint.setAntiAlias(true); | 723 skPaint.setAntiAlias(true); |
725 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 724 int stroke_alpha = FXARGB_A(stroke_color); |
726 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) | |
727 : FXARGB_A(stroke_color); | |
728 if (pGraphState && stroke_alpha) | 725 if (pGraphState && stroke_alpha) |
729 PaintStroke(&skPaint, pGraphState, skMatrix); | 726 PaintStroke(&skPaint, pGraphState, skMatrix); |
730 SkPath skPath = BuildPath(pPathData); | 727 SkPath skPath = BuildPath(pPathData); |
731 m_pCanvas->save(); | 728 m_pCanvas->save(); |
732 m_pCanvas->concat(skMatrix); | 729 m_pCanvas->concat(skMatrix); |
733 if ((fill_mode & 3) && fill_color) { | 730 if ((fill_mode & 3) && fill_color) { |
734 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING | 731 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
735 ? SkPath::kWinding_FillType | 732 ? SkPath::kWinding_FillType |
736 : SkPath::kEvenOdd_FillType); | 733 : SkPath::kEvenOdd_FillType); |
737 SkPath strokePath; | 734 SkPath strokePath; |
(...skipping 17 matching lines...) Expand all Loading... |
755 DebugShowSkiaPath(skPath); | 752 DebugShowSkiaPath(skPath); |
756 DebugShowCanvasMatrix(m_pCanvas); | 753 DebugShowCanvasMatrix(m_pCanvas); |
757 skPaint.setStyle(SkPaint::kStroke_Style); | 754 skPaint.setStyle(SkPaint::kStroke_Style); |
758 skPaint.setColor(stroke_color); | 755 skPaint.setColor(stroke_color); |
759 m_pCanvas->drawPath(skPath, skPaint); | 756 m_pCanvas->drawPath(skPath, skPaint); |
760 } | 757 } |
761 m_pCanvas->restore(); | 758 m_pCanvas->restore(); |
762 return TRUE; | 759 return TRUE; |
763 } | 760 } |
764 | 761 |
765 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, | 762 FX_BOOL CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, |
766 uint32_t fill_color, | 763 uint32_t fill_color, |
767 int alpha_flag, | 764 int blend_type) { |
768 void* pIccTransform, | |
769 int blend_type) { | |
770 SkPaint spaint; | 765 SkPaint spaint; |
771 spaint.setAntiAlias(true); | 766 spaint.setAntiAlias(true); |
772 spaint.setColor(fill_color); | 767 spaint.setColor(fill_color); |
773 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); | 768 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); |
774 | 769 |
775 m_pCanvas->drawRect( | 770 m_pCanvas->drawRect( |
776 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 771 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
777 spaint); | 772 spaint); |
778 return TRUE; | 773 return TRUE; |
779 } | 774 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 pRect->left = 0; | 912 pRect->left = 0; |
918 pRect->top = 0; | 913 pRect->top = 0; |
919 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 914 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
920 pRect->right = canvasSize.width(); | 915 pRect->right = canvasSize.width(); |
921 pRect->bottom = canvasSize.height(); | 916 pRect->bottom = canvasSize.height(); |
922 return TRUE; | 917 return TRUE; |
923 } | 918 } |
924 | 919 |
925 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 920 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
926 int left, | 921 int left, |
927 int top, | 922 int top) { |
928 void* pIccTransform, | |
929 FX_BOOL bDEdge) { | |
930 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 923 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
931 return TRUE; | 924 return TRUE; |
932 if (bDEdge) { | 925 |
933 if (m_bRgbByteOrder) { | |
934 RgbByteOrderTransferBitmap(pBitmap, 0, 0, pBitmap->GetWidth(), | |
935 pBitmap->GetHeight(), m_pBitmap, left, top); | |
936 } else { | |
937 return pBitmap->TransferBitmap(0, 0, pBitmap->GetWidth(), | |
938 pBitmap->GetHeight(), m_pBitmap, left, top, | |
939 pIccTransform); | |
940 } | |
941 return TRUE; | |
942 } | |
943 FX_RECT rect(left, top, left + pBitmap->GetWidth(), | 926 FX_RECT rect(left, top, left + pBitmap->GetWidth(), |
944 top + pBitmap->GetHeight()); | 927 top + pBitmap->GetHeight()); |
945 CFX_DIBitmap* pBack; | 928 CFX_DIBitmap* pBack; |
946 if (m_pOriDevice) { | 929 if (m_pOriDevice) { |
947 pBack = m_pOriDevice->Clone(&rect); | 930 pBack = m_pOriDevice->Clone(&rect); |
948 if (!pBack) | 931 if (!pBack) |
949 return TRUE; | 932 return TRUE; |
| 933 |
950 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), | 934 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), |
951 m_pBitmap, 0, 0); | 935 m_pBitmap, 0, 0); |
952 } else { | 936 } else { |
953 pBack = m_pBitmap->Clone(&rect); | 937 pBack = m_pBitmap->Clone(&rect); |
954 if (!pBack) | 938 if (!pBack) |
955 return TRUE; | 939 return TRUE; |
956 } | 940 } |
| 941 |
957 FX_BOOL bRet = TRUE; | 942 FX_BOOL bRet = TRUE; |
958 left = left >= 0 ? 0 : left; | 943 left = std::min(left, 0); |
959 top = top >= 0 ? 0 : top; | 944 top = std::min(top, 0); |
960 if (m_bRgbByteOrder) { | 945 if (m_bRgbByteOrder) { |
961 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), | 946 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), |
962 pBack, left, top); | 947 pBack, left, top); |
963 } else { | 948 } else { |
964 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, | 949 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, |
965 left, top, pIccTransform); | 950 left, top, nullptr); |
966 } | 951 } |
967 delete pBack; | 952 delete pBack; |
968 return bRet; | 953 return bRet; |
969 } | 954 } |
970 | 955 |
971 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 956 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
972 uint32_t argb, | 957 uint32_t argb, |
973 const FX_RECT* pSrcRect, | 958 const FX_RECT* pSrcRect, |
974 int left, | 959 int left, |
975 int top, | 960 int top, |
976 int blend_type, | 961 int blend_type) { |
977 int alpha_flag, | |
978 void* pIccTransform) { | |
979 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 962 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
980 return TRUE; | 963 return TRUE; |
981 | 964 |
982 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, | 965 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
983 top + pBitmap->GetHeight()); | 966 top + pBitmap->GetHeight()); |
984 void* dummy; | 967 void* dummy; |
985 return this->StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, alpha_flag, | 968 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
986 pIccTransform, blend_type); | |
987 } | 969 } |
988 | 970 |
989 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 971 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
990 uint32_t argb, | 972 uint32_t argb, |
991 int dest_left, | 973 int dest_left, |
992 int dest_top, | 974 int dest_top, |
993 int dest_width, | 975 int dest_width, |
994 int dest_height, | 976 int dest_height, |
995 const FX_RECT* pClipRect, | 977 const FX_RECT* pClipRect, |
996 uint32_t flags, | 978 uint32_t flags, |
997 int alpha_flag, | |
998 void* pIccTransform, | |
999 int blend_type) { | 979 int blend_type) { |
1000 if (!m_pBitmap->GetBuffer()) | 980 if (!m_pBitmap->GetBuffer()) |
1001 return TRUE; | 981 return TRUE; |
1002 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, | 982 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
1003 dest_top + dest_height); | 983 dest_top + dest_height); |
1004 | 984 |
1005 m_pCanvas->save(); | 985 m_pCanvas->save(); |
1006 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, | 986 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, |
1007 pClipRect->right, pClipRect->top); | 987 pClipRect->right, pClipRect->top); |
1008 m_pCanvas->clipRect(skClipRect); | 988 m_pCanvas->clipRect(skClipRect); |
1009 void* dummy; | 989 void* dummy; |
1010 FX_BOOL result = this->StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, | 990 FX_BOOL result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); |
1011 alpha_flag, pIccTransform, blend_type); | |
1012 m_pCanvas->restore(); | 991 m_pCanvas->restore(); |
1013 | 992 |
1014 return result; | 993 return result; |
1015 } | 994 } |
1016 | 995 |
1017 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 996 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1018 int bitmap_alpha, | 997 int bitmap_alpha, |
1019 uint32_t argb, | 998 uint32_t argb, |
1020 const CFX_Matrix* pMatrix, | 999 const CFX_Matrix* pMatrix, |
1021 uint32_t render_flags, | 1000 uint32_t render_flags, |
1022 void*& handle, | 1001 void*& handle, |
1023 int alpha_flag, | |
1024 void* pIccTransform, | |
1025 int blend_type) { | 1002 int blend_type) { |
1026 DebugValidate(m_pBitmap, m_pOriDevice); | 1003 DebugValidate(m_pBitmap, m_pOriDevice); |
1027 SkColorType colorType = pSource->IsAlphaMask() | 1004 SkColorType colorType = pSource->IsAlphaMask() |
1028 ? SkColorType::kAlpha_8_SkColorType | 1005 ? SkColorType::kAlpha_8_SkColorType |
1029 : SkColorType::kGray_8_SkColorType; | 1006 : SkColorType::kGray_8_SkColorType; |
1030 SkAlphaType alphaType = | 1007 SkAlphaType alphaType = |
1031 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; | 1008 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; |
1032 SkColorTable* ct = nullptr; | 1009 SkColorTable* ct = nullptr; |
1033 void* buffer = pSource->GetBuffer(); | 1010 void* buffer = pSource->GetBuffer(); |
1034 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1011 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 SetDeviceDriver(pDriver); | 1151 SetDeviceDriver(pDriver); |
1175 return true; | 1152 return true; |
1176 } | 1153 } |
1177 | 1154 |
1178 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1155 CFX_FxgeDevice::~CFX_FxgeDevice() { |
1179 if (m_bOwnedBitmap && GetBitmap()) | 1156 if (m_bOwnedBitmap && GetBitmap()) |
1180 delete GetBitmap(); | 1157 delete GetBitmap(); |
1181 } | 1158 } |
1182 | 1159 |
1183 void CFX_FxgeDevice::PreMultiply() { | 1160 void CFX_FxgeDevice::PreMultiply() { |
1184 (static_cast<CFX_SkiaDeviceDriver*>(this->GetDeviceDriver()))->PreMultiply(); | 1161 (static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()))->PreMultiply(); |
1185 } | 1162 } |
1186 | 1163 |
1187 #endif | 1164 #endif |
OLD | NEW |