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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 return TRUE; | 698 return TRUE; |
698 } | 699 } |
699 | 700 |
700 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 701 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( |
701 const CFX_PathData* pPathData, // path info | 702 const CFX_PathData* pPathData, // path info |
702 const CFX_Matrix* pObject2Device, // optional transformation | 703 const CFX_Matrix* pObject2Device, // optional transformation |
703 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 704 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
704 uint32_t fill_color, // fill color | 705 uint32_t fill_color, // fill color |
705 uint32_t stroke_color, // stroke color | 706 uint32_t stroke_color, // stroke color |
706 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 707 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
707 int alpha_flag, | |
708 void* pIccTransform, | |
709 int blend_type) { | 708 int blend_type) { |
710 SkIRect rect; | 709 SkIRect rect; |
711 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 710 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
712 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 711 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
713 SkMatrix skMatrix; | 712 SkMatrix skMatrix; |
714 if (pObject2Device) | 713 if (pObject2Device) |
715 skMatrix = ToSkMatrix(*pObject2Device); | 714 skMatrix = ToSkMatrix(*pObject2Device); |
716 else | 715 else |
717 skMatrix.setIdentity(); | 716 skMatrix.setIdentity(); |
718 SkPaint skPaint; | 717 SkPaint skPaint; |
719 skPaint.setAntiAlias(true); | 718 skPaint.setAntiAlias(true); |
720 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 719 int stroke_alpha = FXARGB_A(stroke_color); |
721 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) | |
722 : FXARGB_A(stroke_color); | |
723 if (pGraphState && stroke_alpha) | 720 if (pGraphState && stroke_alpha) |
724 PaintStroke(&skPaint, pGraphState, skMatrix); | 721 PaintStroke(&skPaint, pGraphState, skMatrix); |
725 SkPath skPath = BuildPath(pPathData); | 722 SkPath skPath = BuildPath(pPathData); |
726 m_pCanvas->save(); | 723 m_pCanvas->save(); |
727 m_pCanvas->concat(skMatrix); | 724 m_pCanvas->concat(skMatrix); |
728 if ((fill_mode & 3) && fill_color) { | 725 if ((fill_mode & 3) && fill_color) { |
729 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING | 726 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
730 ? SkPath::kWinding_FillType | 727 ? SkPath::kWinding_FillType |
731 : SkPath::kEvenOdd_FillType); | 728 : SkPath::kEvenOdd_FillType); |
732 SkPath strokePath; | 729 SkPath strokePath; |
(...skipping 17 matching lines...) Expand all Loading... |
750 DebugShowSkiaPath(skPath); | 747 DebugShowSkiaPath(skPath); |
751 DebugShowCanvasMatrix(m_pCanvas); | 748 DebugShowCanvasMatrix(m_pCanvas); |
752 skPaint.setStyle(SkPaint::kStroke_Style); | 749 skPaint.setStyle(SkPaint::kStroke_Style); |
753 skPaint.setColor(stroke_color); | 750 skPaint.setColor(stroke_color); |
754 m_pCanvas->drawPath(skPath, skPaint); | 751 m_pCanvas->drawPath(skPath, skPaint); |
755 } | 752 } |
756 m_pCanvas->restore(); | 753 m_pCanvas->restore(); |
757 return TRUE; | 754 return TRUE; |
758 } | 755 } |
759 | 756 |
760 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, | 757 FX_BOOL CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, |
761 uint32_t fill_color, | 758 uint32_t fill_color, |
762 int alpha_flag, | 759 int blend_type) { |
763 void* pIccTransform, | |
764 int blend_type) { | |
765 SkPaint spaint; | 760 SkPaint spaint; |
766 spaint.setAntiAlias(true); | 761 spaint.setAntiAlias(true); |
767 spaint.setColor(fill_color); | 762 spaint.setColor(fill_color); |
768 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); | 763 spaint.setXfermodeMode(GetSkiaBlendMode(blend_type)); |
769 | 764 |
770 m_pCanvas->drawRect( | 765 m_pCanvas->drawRect( |
771 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 766 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
772 spaint); | 767 spaint); |
773 return TRUE; | 768 return TRUE; |
774 } | 769 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 pRect->left = 0; | 907 pRect->left = 0; |
913 pRect->top = 0; | 908 pRect->top = 0; |
914 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 909 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
915 pRect->right = canvasSize.width(); | 910 pRect->right = canvasSize.width(); |
916 pRect->bottom = canvasSize.height(); | 911 pRect->bottom = canvasSize.height(); |
917 return TRUE; | 912 return TRUE; |
918 } | 913 } |
919 | 914 |
920 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 915 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
921 int left, | 916 int left, |
922 int top, | 917 int top) { |
923 void* pIccTransform, | |
924 FX_BOOL bDEdge) { | |
925 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 918 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
926 return TRUE; | 919 return TRUE; |
927 if (bDEdge) { | 920 |
928 if (m_bRgbByteOrder) { | |
929 RgbByteOrderTransferBitmap(pBitmap, 0, 0, pBitmap->GetWidth(), | |
930 pBitmap->GetHeight(), m_pBitmap, left, top); | |
931 } else { | |
932 return pBitmap->TransferBitmap(0, 0, pBitmap->GetWidth(), | |
933 pBitmap->GetHeight(), m_pBitmap, left, top, | |
934 pIccTransform); | |
935 } | |
936 return TRUE; | |
937 } | |
938 FX_RECT rect(left, top, left + pBitmap->GetWidth(), | 921 FX_RECT rect(left, top, left + pBitmap->GetWidth(), |
939 top + pBitmap->GetHeight()); | 922 top + pBitmap->GetHeight()); |
940 CFX_DIBitmap* pBack; | 923 CFX_DIBitmap* pBack; |
941 if (m_pOriDevice) { | 924 if (m_pOriDevice) { |
942 pBack = m_pOriDevice->Clone(&rect); | 925 pBack = m_pOriDevice->Clone(&rect); |
943 if (!pBack) | 926 if (!pBack) |
944 return TRUE; | 927 return TRUE; |
| 928 |
945 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), | 929 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), |
946 m_pBitmap, 0, 0); | 930 m_pBitmap, 0, 0); |
947 } else { | 931 } else { |
948 pBack = m_pBitmap->Clone(&rect); | 932 pBack = m_pBitmap->Clone(&rect); |
949 if (!pBack) | 933 if (!pBack) |
950 return TRUE; | 934 return TRUE; |
951 } | 935 } |
| 936 |
952 FX_BOOL bRet = TRUE; | 937 FX_BOOL bRet = TRUE; |
953 left = left >= 0 ? 0 : left; | 938 left = std::min(left, 0); |
954 top = top >= 0 ? 0 : top; | 939 top = std::min(top, 0); |
955 if (m_bRgbByteOrder) { | 940 if (m_bRgbByteOrder) { |
956 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), | 941 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), |
957 pBack, left, top); | 942 pBack, left, top); |
958 } else { | 943 } else { |
959 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, | 944 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, |
960 left, top, pIccTransform); | 945 left, top, nullptr); |
961 } | 946 } |
962 delete pBack; | 947 delete pBack; |
963 return bRet; | 948 return bRet; |
964 } | 949 } |
965 | 950 |
966 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 951 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
967 uint32_t argb, | 952 uint32_t argb, |
968 const FX_RECT* pSrcRect, | 953 const FX_RECT* pSrcRect, |
969 int left, | 954 int left, |
970 int top, | 955 int top, |
971 int blend_type, | 956 int blend_type) { |
972 int alpha_flag, | |
973 void* pIccTransform) { | |
974 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 957 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
975 return TRUE; | 958 return TRUE; |
976 | 959 |
977 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, | 960 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
978 top + pBitmap->GetHeight()); | 961 top + pBitmap->GetHeight()); |
979 void* dummy; | 962 void* dummy; |
980 return this->StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, alpha_flag, | 963 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
981 pIccTransform, blend_type); | |
982 } | 964 } |
983 | 965 |
984 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 966 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
985 uint32_t argb, | 967 uint32_t argb, |
986 int dest_left, | 968 int dest_left, |
987 int dest_top, | 969 int dest_top, |
988 int dest_width, | 970 int dest_width, |
989 int dest_height, | 971 int dest_height, |
990 const FX_RECT* pClipRect, | 972 const FX_RECT* pClipRect, |
991 uint32_t flags, | 973 uint32_t flags, |
992 int alpha_flag, | |
993 void* pIccTransform, | |
994 int blend_type) { | 974 int blend_type) { |
995 if (!m_pBitmap->GetBuffer()) | 975 if (!m_pBitmap->GetBuffer()) |
996 return TRUE; | 976 return TRUE; |
997 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, | 977 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
998 dest_top + dest_height); | 978 dest_top + dest_height); |
999 | 979 |
1000 m_pCanvas->save(); | 980 m_pCanvas->save(); |
1001 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, | 981 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, |
1002 pClipRect->right, pClipRect->top); | 982 pClipRect->right, pClipRect->top); |
1003 m_pCanvas->clipRect(skClipRect); | 983 m_pCanvas->clipRect(skClipRect); |
1004 void* dummy; | 984 void* dummy; |
1005 FX_BOOL result = this->StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, | 985 FX_BOOL result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); |
1006 alpha_flag, pIccTransform, blend_type); | |
1007 m_pCanvas->restore(); | 986 m_pCanvas->restore(); |
1008 | 987 |
1009 return result; | 988 return result; |
1010 } | 989 } |
1011 | 990 |
1012 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 991 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1013 int bitmap_alpha, | 992 int bitmap_alpha, |
1014 uint32_t argb, | 993 uint32_t argb, |
1015 const CFX_Matrix* pMatrix, | 994 const CFX_Matrix* pMatrix, |
1016 uint32_t render_flags, | 995 uint32_t render_flags, |
1017 void*& handle, | 996 void*& handle, |
1018 int alpha_flag, | |
1019 void* pIccTransform, | |
1020 int blend_type) { | 997 int blend_type) { |
1021 DebugValidate(m_pBitmap, m_pOriDevice); | 998 DebugValidate(m_pBitmap, m_pOriDevice); |
1022 SkColorType colorType = pSource->IsAlphaMask() | 999 SkColorType colorType = pSource->IsAlphaMask() |
1023 ? SkColorType::kAlpha_8_SkColorType | 1000 ? SkColorType::kAlpha_8_SkColorType |
1024 : SkColorType::kGray_8_SkColorType; | 1001 : SkColorType::kGray_8_SkColorType; |
1025 SkAlphaType alphaType = | 1002 SkAlphaType alphaType = |
1026 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; | 1003 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; |
1027 SkColorTable* ct = nullptr; | 1004 SkColorTable* ct = nullptr; |
1028 void* buffer = pSource->GetBuffer(); | 1005 void* buffer = pSource->GetBuffer(); |
1029 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1006 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 SetDeviceDriver(pDriver); | 1146 SetDeviceDriver(pDriver); |
1170 return true; | 1147 return true; |
1171 } | 1148 } |
1172 | 1149 |
1173 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1150 CFX_FxgeDevice::~CFX_FxgeDevice() { |
1174 if (m_bOwnedBitmap && GetBitmap()) | 1151 if (m_bOwnedBitmap && GetBitmap()) |
1175 delete GetBitmap(); | 1152 delete GetBitmap(); |
1176 } | 1153 } |
1177 | 1154 |
1178 void CFX_FxgeDevice::PreMultiply() { | 1155 void CFX_FxgeDevice::PreMultiply() { |
1179 (static_cast<CFX_SkiaDeviceDriver*>(this->GetDeviceDriver()))->PreMultiply(); | 1156 (static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()))->PreMultiply(); |
1180 } | 1157 } |
1181 | 1158 |
1182 #endif | 1159 #endif |
OLD | NEW |