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 |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 } | 935 } |
936 spaint->setStyle(SkPaint::kStroke_Style); | 936 spaint->setStyle(SkPaint::kStroke_Style); |
937 spaint->setAntiAlias(true); | 937 spaint->setAntiAlias(true); |
938 spaint->setStrokeWidth(width); | 938 spaint->setStrokeWidth(width); |
939 spaint->setStrokeMiter(pGraphState->m_MiterLimit); | 939 spaint->setStrokeMiter(pGraphState->m_MiterLimit); |
940 spaint->setStrokeCap(cap); | 940 spaint->setStrokeCap(cap); |
941 spaint->setStrokeJoin(join); | 941 spaint->setStrokeJoin(join); |
942 } | 942 } |
943 | 943 |
944 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 944 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
945 FX_BOOL bRgbByteOrder, | 945 bool bRgbByteOrder, |
946 CFX_DIBitmap* pOriDevice, | 946 CFX_DIBitmap* pOriDevice, |
947 FX_BOOL bGroupKnockout) | 947 bool bGroupKnockout) |
948 : m_pBitmap(pBitmap), | 948 : m_pBitmap(pBitmap), |
949 m_pOriDevice(pOriDevice), | 949 m_pOriDevice(pOriDevice), |
950 m_pRecorder(nullptr), | 950 m_pRecorder(nullptr), |
951 m_pCache(new SkiaState), | 951 m_pCache(new SkiaState), |
952 m_bGroupKnockout(bGroupKnockout) { | 952 m_bGroupKnockout(bGroupKnockout) { |
953 SkBitmap skBitmap; | 953 SkBitmap skBitmap; |
954 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); | 954 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); |
955 SkImageInfo imageInfo = SkImageInfo::Make( | 955 SkImageInfo imageInfo = SkImageInfo::Make( |
956 pBitmap->GetWidth(), pBitmap->GetHeight(), | 956 pBitmap->GetWidth(), pBitmap->GetHeight(), |
957 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, | 957 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, |
958 kOpaque_SkAlphaType); | 958 kOpaque_SkAlphaType); |
959 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), | 959 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), |
960 nullptr, /* to do : set color table */ | 960 nullptr, /* to do : set color table */ |
961 nullptr, nullptr); | 961 nullptr, nullptr); |
962 m_pCanvas = new SkCanvas(skBitmap); | 962 m_pCanvas = new SkCanvas(skBitmap); |
963 if (m_bGroupKnockout) | 963 if (m_bGroupKnockout) |
964 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' | 964 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' |
965 } | 965 } |
966 | 966 |
967 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) | 967 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) |
968 : m_pBitmap(nullptr), | 968 : m_pBitmap(nullptr), |
969 m_pOriDevice(nullptr), | 969 m_pOriDevice(nullptr), |
970 m_pRecorder(new SkPictureRecorder), | 970 m_pRecorder(new SkPictureRecorder), |
971 m_pCache(new SkiaState), | 971 m_pCache(new SkiaState), |
972 m_bGroupKnockout(FALSE) { | 972 m_bGroupKnockout(false) { |
973 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); | 973 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); |
974 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 974 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
975 } | 975 } |
976 | 976 |
977 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) | 977 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) |
978 : m_pBitmap(nullptr), | 978 : m_pBitmap(nullptr), |
979 m_pOriDevice(nullptr), | 979 m_pOriDevice(nullptr), |
980 m_pRecorder(recorder), | 980 m_pRecorder(recorder), |
981 m_pCache(new SkiaState), | 981 m_pCache(new SkiaState), |
982 m_bGroupKnockout(FALSE) { | 982 m_bGroupKnockout(false) { |
983 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 983 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
984 } | 984 } |
985 | 985 |
986 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 986 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
987 Flush(); | 987 Flush(); |
988 if (!m_pRecorder) | 988 if (!m_pRecorder) |
989 delete m_pCanvas; | 989 delete m_pCanvas; |
990 } | 990 } |
991 | 991 |
992 void CFX_SkiaDeviceDriver::Flush() { | 992 void CFX_SkiaDeviceDriver::Flush() { |
993 m_pCache->Flush(this); | 993 m_pCache->Flush(this); |
994 m_pCache->FlushCommands(this); | 994 m_pCache->FlushCommands(this); |
995 } | 995 } |
996 | 996 |
997 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 997 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
998 const FXTEXT_CHARPOS* pCharPos, | 998 const FXTEXT_CHARPOS* pCharPos, |
999 CFX_Font* pFont, | 999 CFX_Font* pFont, |
1000 const CFX_Matrix* pObject2Device, | 1000 const CFX_Matrix* pObject2Device, |
1001 FX_FLOAT font_size, | 1001 FX_FLOAT font_size, |
1002 uint32_t color) { | 1002 uint32_t color) { |
1003 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, | 1003 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, |
1004 color, this)) { | 1004 color, this)) { |
1005 return TRUE; | 1005 return true; |
1006 } | 1006 } |
1007 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); | 1007 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); |
1008 SkPaint paint; | 1008 SkPaint paint; |
1009 paint.setAntiAlias(true); | 1009 paint.setAntiAlias(true); |
1010 paint.setColor(color); | 1010 paint.setColor(color); |
1011 paint.setTypeface(typeface); | 1011 paint.setTypeface(typeface); |
1012 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1012 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
1013 paint.setHinting(SkPaint::kNo_Hinting); | 1013 paint.setHinting(SkPaint::kNo_Hinting); |
1014 paint.setTextSize(font_size); | 1014 paint.setTextSize(font_size); |
1015 paint.setSubpixelText(true); | 1015 paint.setSubpixelText(true); |
1016 m_pCanvas->save(); | 1016 m_pCanvas->save(); |
1017 SkScalar flip = font_size < 0 ? -1 : 1; | 1017 SkScalar flip = font_size < 0 ? -1 : 1; |
1018 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); | 1018 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); |
1019 m_pCanvas->concat(skMatrix); | 1019 m_pCanvas->concat(skMatrix); |
1020 SkTDArray<SkPoint> positions; | 1020 SkTDArray<SkPoint> positions; |
1021 positions.setCount(nChars); | 1021 positions.setCount(nChars); |
1022 SkTDArray<uint16_t> glyphs; | 1022 SkTDArray<uint16_t> glyphs; |
1023 glyphs.setCount(nChars); | 1023 glyphs.setCount(nChars); |
1024 for (int index = 0; index < nChars; ++index) { | 1024 for (int index = 0; index < nChars; ++index) { |
1025 const FXTEXT_CHARPOS& cp = pCharPos[index]; | 1025 const FXTEXT_CHARPOS& cp = pCharPos[index]; |
1026 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; | 1026 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; |
1027 glyphs[index] = (uint16_t)cp.m_GlyphIndex; | 1027 glyphs[index] = (uint16_t)cp.m_GlyphIndex; |
1028 } | 1028 } |
1029 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); | 1029 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); |
1030 m_pCanvas->restore(); | 1030 m_pCanvas->restore(); |
1031 return TRUE; | 1031 return true; |
1032 } | 1032 } |
1033 | 1033 |
1034 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { | 1034 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { |
1035 switch (caps_id) { | 1035 switch (caps_id) { |
1036 case FXDC_DEVICE_CLASS: | 1036 case FXDC_DEVICE_CLASS: |
1037 return FXDC_DISPLAY; | 1037 return FXDC_DISPLAY; |
1038 case FXDC_PIXEL_WIDTH: | 1038 case FXDC_PIXEL_WIDTH: |
1039 return m_pCanvas->imageInfo().width(); | 1039 return m_pCanvas->imageInfo().width(); |
1040 case FXDC_PIXEL_HEIGHT: | 1040 case FXDC_PIXEL_HEIGHT: |
1041 return m_pCanvas->imageInfo().height(); | 1041 return m_pCanvas->imageInfo().height(); |
(...skipping 15 matching lines...) Expand all Loading... |
1057 m_pCanvas->save(); | 1057 m_pCanvas->save(); |
1058 } | 1058 } |
1059 | 1059 |
1060 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { | 1060 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { |
1061 if (!m_pCache->ClipRestore(this)) | 1061 if (!m_pCache->ClipRestore(this)) |
1062 m_pCanvas->restore(); | 1062 m_pCanvas->restore(); |
1063 if (bKeepSaved) | 1063 if (bKeepSaved) |
1064 SaveState(); | 1064 SaveState(); |
1065 } | 1065 } |
1066 | 1066 |
1067 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( | 1067 bool CFX_SkiaDeviceDriver::SetClip_PathFill( |
1068 const CFX_PathData* pPathData, // path info | 1068 const CFX_PathData* pPathData, // path info |
1069 const CFX_Matrix* pObject2Device, // flips object's y-axis | 1069 const CFX_Matrix* pObject2Device, // flips object's y-axis |
1070 int fill_mode // fill mode, WINDING or ALTERNATE | 1070 int fill_mode // fill mode, WINDING or ALTERNATE |
1071 ) { | 1071 ) { |
1072 CFX_Matrix identity; | 1072 CFX_Matrix identity; |
1073 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; | 1073 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; |
1074 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this)) | 1074 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this)) |
1075 return TRUE; | 1075 return true; |
1076 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 1076 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
1077 CFX_FloatRect rectf; | 1077 CFX_FloatRect rectf; |
1078 if (pPathData->IsRect(deviceMatrix, &rectf)) { | 1078 if (pPathData->IsRect(deviceMatrix, &rectf)) { |
1079 rectf.Intersect( | 1079 rectf.Intersect( |
1080 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 1080 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
1081 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 1081 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
1082 // note that PDF's y-axis goes up; Skia's y-axis goes down | 1082 // note that PDF's y-axis goes up; Skia's y-axis goes down |
1083 SkRect skClipRect = | 1083 SkRect skClipRect = |
1084 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); | 1084 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); |
1085 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); | 1085 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); |
1086 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); | 1086 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); |
1087 return TRUE; | 1087 return true; |
1088 } | 1088 } |
1089 } | 1089 } |
1090 SkPath skClipPath = BuildPath(pPathData); | 1090 SkPath skClipPath = BuildPath(pPathData); |
1091 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 1091 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
1092 ? SkPath::kEvenOdd_FillType | 1092 ? SkPath::kEvenOdd_FillType |
1093 : SkPath::kWinding_FillType); | 1093 : SkPath::kWinding_FillType); |
1094 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); | 1094 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); |
1095 skClipPath.transform(skMatrix); | 1095 skClipPath.transform(skMatrix); |
1096 DebugShowSkiaPath(skClipPath); | 1096 DebugShowSkiaPath(skClipPath); |
1097 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); | 1097 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); |
1098 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); | 1098 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); |
1099 | 1099 |
1100 return TRUE; | 1100 return true; |
1101 } | 1101 } |
1102 | 1102 |
1103 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( | 1103 bool CFX_SkiaDeviceDriver::SetClip_PathStroke( |
1104 const CFX_PathData* pPathData, // path info | 1104 const CFX_PathData* pPathData, // path info |
1105 const CFX_Matrix* pObject2Device, // optional transformation | 1105 const CFX_Matrix* pObject2Device, // optional transformation |
1106 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 1106 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
1107 ) { | 1107 ) { |
1108 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this)) | 1108 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this)) |
1109 return TRUE; | 1109 return true; |
1110 // build path data | 1110 // build path data |
1111 SkPath skPath = BuildPath(pPathData); | 1111 SkPath skPath = BuildPath(pPathData); |
1112 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | 1112 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); |
1113 SkPaint skPaint; | 1113 SkPaint skPaint; |
1114 PaintStroke(&skPaint, pGraphState, skMatrix); | 1114 PaintStroke(&skPaint, pGraphState, skMatrix); |
1115 SkPath dst_path; | 1115 SkPath dst_path; |
1116 skPaint.getFillPath(skPath, &dst_path); | 1116 skPaint.getFillPath(skPath, &dst_path); |
1117 dst_path.transform(skMatrix); | 1117 dst_path.transform(skMatrix); |
1118 DebugDrawSkiaClipPath(m_pCanvas, dst_path); | 1118 DebugDrawSkiaClipPath(m_pCanvas, dst_path); |
1119 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); | 1119 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); |
1120 return TRUE; | 1120 return true; |
1121 } | 1121 } |
1122 | 1122 |
1123 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 1123 bool CFX_SkiaDeviceDriver::DrawPath( |
1124 const CFX_PathData* pPathData, // path info | 1124 const CFX_PathData* pPathData, // path info |
1125 const CFX_Matrix* pObject2Device, // optional transformation | 1125 const CFX_Matrix* pObject2Device, // optional transformation |
1126 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 1126 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
1127 uint32_t fill_color, // fill color | 1127 uint32_t fill_color, // fill color |
1128 uint32_t stroke_color, // stroke color | 1128 uint32_t stroke_color, // stroke color |
1129 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 1129 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
1130 int blend_type) { | 1130 int blend_type) { |
1131 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, | 1131 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, |
1132 stroke_color, fill_mode, blend_type, this)) { | 1132 stroke_color, fill_mode, blend_type, this)) { |
1133 return TRUE; | 1133 return true; |
1134 } | 1134 } |
1135 SkIRect rect; | 1135 SkIRect rect; |
1136 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 1136 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
1137 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 1137 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
1138 SkMatrix skMatrix; | 1138 SkMatrix skMatrix; |
1139 if (pObject2Device) | 1139 if (pObject2Device) |
1140 skMatrix = ToSkMatrix(*pObject2Device); | 1140 skMatrix = ToSkMatrix(*pObject2Device); |
1141 else | 1141 else |
1142 skMatrix.setIdentity(); | 1142 skMatrix.setIdentity(); |
1143 SkPaint skPaint; | 1143 SkPaint skPaint; |
(...skipping 26 matching lines...) Expand all Loading... |
1170 m_pCanvas->drawPath(*fillPath, skPaint); | 1170 m_pCanvas->drawPath(*fillPath, skPaint); |
1171 } | 1171 } |
1172 if (pGraphState && stroke_alpha) { | 1172 if (pGraphState && stroke_alpha) { |
1173 DebugShowSkiaPath(skPath); | 1173 DebugShowSkiaPath(skPath); |
1174 DebugShowCanvasMatrix(m_pCanvas); | 1174 DebugShowCanvasMatrix(m_pCanvas); |
1175 skPaint.setStyle(SkPaint::kStroke_Style); | 1175 skPaint.setStyle(SkPaint::kStroke_Style); |
1176 skPaint.setColor(stroke_color); | 1176 skPaint.setColor(stroke_color); |
1177 m_pCanvas->drawPath(skPath, skPaint); | 1177 m_pCanvas->drawPath(skPath, skPaint); |
1178 } | 1178 } |
1179 m_pCanvas->restore(); | 1179 m_pCanvas->restore(); |
1180 return TRUE; | 1180 return true; |
1181 } | 1181 } |
1182 | 1182 |
1183 FX_BOOL CFX_SkiaDeviceDriver::DrawCosmeticLine(FX_FLOAT x1, | 1183 bool CFX_SkiaDeviceDriver::DrawCosmeticLine(FX_FLOAT x1, |
1184 FX_FLOAT y1, | 1184 FX_FLOAT y1, |
1185 FX_FLOAT x2, | 1185 FX_FLOAT x2, |
1186 FX_FLOAT y2, | 1186 FX_FLOAT y2, |
1187 uint32_t color, | 1187 uint32_t color, |
1188 int blend_type) { | 1188 int blend_type) { |
1189 return FALSE; | 1189 return false; |
1190 } | 1190 } |
1191 | 1191 |
1192 FX_BOOL CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, | 1192 bool CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, |
1193 uint32_t fill_color, | 1193 uint32_t fill_color, |
1194 int blend_type) { | 1194 int blend_type) { |
1195 SkPaint spaint; | 1195 SkPaint spaint; |
1196 spaint.setAntiAlias(true); | 1196 spaint.setAntiAlias(true); |
1197 spaint.setColor(fill_color); | 1197 spaint.setColor(fill_color); |
1198 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); | 1198 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); |
1199 | 1199 |
1200 m_pCanvas->drawRect( | 1200 m_pCanvas->drawRect( |
1201 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 1201 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
1202 spaint); | 1202 spaint); |
1203 return TRUE; | 1203 return true; |
1204 } | 1204 } |
1205 | 1205 |
1206 FX_BOOL CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, | 1206 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, |
1207 const CFX_Matrix* pMatrix, | 1207 const CFX_Matrix* pMatrix, |
1208 const FX_RECT& clip_rect, | 1208 const FX_RECT& clip_rect, |
1209 int alpha, | 1209 int alpha, |
1210 FX_BOOL bAlphaMode) { | 1210 bool bAlphaMode) { |
1211 if (kAxialShading != pPattern->GetShadingType() && | 1211 if (kAxialShading != pPattern->GetShadingType() && |
1212 kRadialShading != pPattern->GetShadingType()) { | 1212 kRadialShading != pPattern->GetShadingType()) { |
1213 // TODO(caryclark) more types | 1213 // TODO(caryclark) more types |
1214 return false; | 1214 return false; |
1215 } | 1215 } |
1216 const std::vector<std::unique_ptr<CPDF_Function>>& pFuncs = | 1216 const std::vector<std::unique_ptr<CPDF_Function>>& pFuncs = |
1217 pPattern->GetFuncs(); | 1217 pPattern->GetFuncs(); |
1218 int nFuncs = pFuncs.size(); | 1218 int nFuncs = pFuncs.size(); |
1219 if (nFuncs != 1) // TODO(caryclark) remove this restriction | 1219 if (nFuncs != 1) // TODO(caryclark) remove this restriction |
1220 return false; | 1220 return false; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 m_pCanvas->concat(skMatrix); | 1334 m_pCanvas->concat(skMatrix); |
1335 m_pCanvas->drawPath(skPath, paint); | 1335 m_pCanvas->drawPath(skPath, paint); |
1336 m_pCanvas->restore(); | 1336 m_pCanvas->restore(); |
1337 return true; | 1337 return true; |
1338 } | 1338 } |
1339 | 1339 |
1340 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { | 1340 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { |
1341 return m_pBitmap->GetBuffer(); | 1341 return m_pBitmap->GetBuffer(); |
1342 } | 1342 } |
1343 | 1343 |
1344 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 1344 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
1345 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead | 1345 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead |
1346 pRect->left = 0; | 1346 pRect->left = 0; |
1347 pRect->top = 0; | 1347 pRect->top = 0; |
1348 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 1348 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
1349 pRect->right = canvasSize.width(); | 1349 pRect->right = canvasSize.width(); |
1350 pRect->bottom = canvasSize.height(); | 1350 pRect->bottom = canvasSize.height(); |
1351 return TRUE; | 1351 return true; |
1352 } | 1352 } |
1353 | 1353 |
1354 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 1354 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { |
1355 int left, | |
1356 int top) { | |
1357 if (!m_pBitmap) | 1355 if (!m_pBitmap) |
1358 return TRUE; | 1356 return true; |
1359 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); | 1357 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); |
1360 if (!srcBuffer) | 1358 if (!srcBuffer) |
1361 return TRUE; | 1359 return true; |
1362 int srcWidth = m_pBitmap->GetWidth(); | 1360 int srcWidth = m_pBitmap->GetWidth(); |
1363 int srcHeight = m_pBitmap->GetHeight(); | 1361 int srcHeight = m_pBitmap->GetHeight(); |
1364 int srcRowBytes = srcWidth * sizeof(uint32_t); | 1362 int srcRowBytes = srcWidth * sizeof(uint32_t); |
1365 SkImageInfo srcImageInfo = SkImageInfo::Make( | 1363 SkImageInfo srcImageInfo = SkImageInfo::Make( |
1366 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1364 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1367 SkBitmap skSrcBitmap; | 1365 SkBitmap skSrcBitmap; |
1368 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, | 1366 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, |
1369 nullptr, nullptr); | 1367 nullptr, nullptr); |
1370 SkASSERT(pBitmap); | 1368 SkASSERT(pBitmap); |
1371 uint8_t* dstBuffer = pBitmap->GetBuffer(); | 1369 uint8_t* dstBuffer = pBitmap->GetBuffer(); |
1372 SkASSERT(dstBuffer); | 1370 SkASSERT(dstBuffer); |
1373 int dstWidth = pBitmap->GetWidth(); | 1371 int dstWidth = pBitmap->GetWidth(); |
1374 int dstHeight = pBitmap->GetHeight(); | 1372 int dstHeight = pBitmap->GetHeight(); |
1375 int dstRowBytes = dstWidth * sizeof(uint32_t); | 1373 int dstRowBytes = dstWidth * sizeof(uint32_t); |
1376 SkImageInfo dstImageInfo = SkImageInfo::Make( | 1374 SkImageInfo dstImageInfo = SkImageInfo::Make( |
1377 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1375 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1378 SkBitmap skDstBitmap; | 1376 SkBitmap skDstBitmap; |
1379 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, | 1377 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, |
1380 nullptr, nullptr); | 1378 nullptr, nullptr); |
1381 SkCanvas canvas(skDstBitmap); | 1379 SkCanvas canvas(skDstBitmap); |
1382 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); | 1380 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); |
1383 return TRUE; | 1381 return true; |
1384 } | 1382 } |
1385 | 1383 |
1386 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { | 1384 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { |
1387 return m_pOriDevice; | 1385 return m_pOriDevice; |
1388 } | 1386 } |
1389 | 1387 |
1390 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 1388 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
1391 uint32_t argb, | 1389 uint32_t argb, |
1392 const FX_RECT* pSrcRect, | 1390 const FX_RECT* pSrcRect, |
1393 int left, | 1391 int left, |
1394 int top, | 1392 int top, |
1395 int blend_type) { | 1393 int blend_type) { |
1396 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1394 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1397 return TRUE; | 1395 return true; |
1398 | 1396 |
1399 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, | 1397 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
1400 top + pBitmap->GetHeight()); | 1398 top + pBitmap->GetHeight()); |
1401 void* dummy; | 1399 void* dummy; |
1402 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); | 1400 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
1403 } | 1401 } |
1404 | 1402 |
1405 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 1403 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
1406 uint32_t argb, | 1404 uint32_t argb, |
1407 int dest_left, | 1405 int dest_left, |
1408 int dest_top, | 1406 int dest_top, |
1409 int dest_width, | 1407 int dest_width, |
1410 int dest_height, | 1408 int dest_height, |
1411 const FX_RECT* pClipRect, | 1409 const FX_RECT* pClipRect, |
1412 uint32_t flags, | 1410 uint32_t flags, |
1413 int blend_type) { | 1411 int blend_type) { |
1414 if (!m_pBitmap->GetBuffer()) | 1412 if (!m_pBitmap->GetBuffer()) |
1415 return TRUE; | 1413 return true; |
1416 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, | 1414 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
1417 dest_top + dest_height); | 1415 dest_top + dest_height); |
1418 | 1416 |
1419 m_pCanvas->save(); | 1417 m_pCanvas->save(); |
1420 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, | 1418 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, |
1421 pClipRect->right, pClipRect->top); | 1419 pClipRect->right, pClipRect->top); |
1422 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); | 1420 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); |
1423 void* dummy; | 1421 void* dummy; |
1424 FX_BOOL result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); | 1422 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); |
1425 m_pCanvas->restore(); | 1423 m_pCanvas->restore(); |
1426 | 1424 |
1427 return result; | 1425 return result; |
1428 } | 1426 } |
1429 | 1427 |
1430 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 1428 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1431 int bitmap_alpha, | 1429 int bitmap_alpha, |
1432 uint32_t argb, | 1430 uint32_t argb, |
1433 const CFX_Matrix* pMatrix, | 1431 const CFX_Matrix* pMatrix, |
1434 uint32_t render_flags, | 1432 uint32_t render_flags, |
1435 void*& handle, | 1433 void*& handle, |
1436 int blend_type) { | 1434 int blend_type) { |
1437 DebugValidate(m_pBitmap, m_pOriDevice); | 1435 DebugValidate(m_pBitmap, m_pOriDevice); |
1438 SkColorTable* ct = nullptr; | 1436 SkColorTable* ct = nullptr; |
1439 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1437 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
1440 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; | 1438 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; |
1441 SkBitmap skBitmap; | 1439 SkBitmap skBitmap; |
1442 int width, height; | 1440 int width, height; |
1443 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, | 1441 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, |
1444 &height, false)) { | 1442 &height, false)) { |
1445 return FALSE; | 1443 return false; |
1446 } | 1444 } |
1447 m_pCanvas->save(); | 1445 m_pCanvas->save(); |
1448 SkMatrix skMatrix; | 1446 SkMatrix skMatrix; |
1449 SetBitmapMatrix(pMatrix, width, height, &skMatrix); | 1447 SetBitmapMatrix(pMatrix, width, height, &skMatrix); |
1450 m_pCanvas->concat(skMatrix); | 1448 m_pCanvas->concat(skMatrix); |
1451 SkPaint paint; | 1449 SkPaint paint; |
1452 SetBitmapPaint(pSource->IsAlphaMask(), argb, bitmap_alpha, blend_type, | 1450 SetBitmapPaint(pSource->IsAlphaMask(), argb, bitmap_alpha, blend_type, |
1453 &paint); | 1451 &paint); |
1454 // TODO(caryclark) Once Skia supports 8 bit src to 8 bit dst remove this | 1452 // TODO(caryclark) Once Skia supports 8 bit src to 8 bit dst remove this |
1455 if (m_pBitmap && m_pBitmap->GetBPP() == 8 && pSource->GetBPP() == 8) { | 1453 if (m_pBitmap && m_pBitmap->GetBPP() == 8 && pSource->GetBPP() == 8) { |
1456 SkMatrix inv; | 1454 SkMatrix inv; |
1457 SkAssertResult(skMatrix.invert(&inv)); | 1455 SkAssertResult(skMatrix.invert(&inv)); |
1458 for (int y = 0; y < m_pBitmap->GetHeight(); ++y) { | 1456 for (int y = 0; y < m_pBitmap->GetHeight(); ++y) { |
1459 for (int x = 0; x < m_pBitmap->GetWidth(); ++x) { | 1457 for (int x = 0; x < m_pBitmap->GetWidth(); ++x) { |
1460 SkPoint src = {x + 0.5f, y + 0.5f}; | 1458 SkPoint src = {x + 0.5f, y + 0.5f}; |
1461 inv.mapPoints(&src, 1); | 1459 inv.mapPoints(&src, 1); |
1462 // TODO(caryclark) Why does the matrix map require clamping? | 1460 // TODO(caryclark) Why does the matrix map require clamping? |
1463 src.fX = SkTMax(0.5f, SkTMin(src.fX, width - 0.5f)); | 1461 src.fX = SkTMax(0.5f, SkTMin(src.fX, width - 0.5f)); |
1464 src.fY = SkTMax(0.5f, SkTMin(src.fY, height - 0.5f)); | 1462 src.fY = SkTMax(0.5f, SkTMin(src.fY, height - 0.5f)); |
1465 m_pBitmap->SetPixel(x, y, skBitmap.getColor(src.fX, src.fY)); | 1463 m_pBitmap->SetPixel(x, y, skBitmap.getColor(src.fX, src.fY)); |
1466 } | 1464 } |
1467 } | 1465 } |
1468 } else { | 1466 } else { |
1469 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); | 1467 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); |
1470 } | 1468 } |
1471 m_pCanvas->restore(); | 1469 m_pCanvas->restore(); |
1472 if (ct) | 1470 if (ct) |
1473 ct->unref(); | 1471 ct->unref(); |
1474 DebugValidate(m_pBitmap, m_pOriDevice); | 1472 DebugValidate(m_pBitmap, m_pOriDevice); |
1475 return TRUE; | 1473 return true; |
1476 } | 1474 } |
1477 | 1475 |
1478 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { | 1476 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
1479 return FALSE; | 1477 return false; |
1480 } | 1478 } |
1481 | 1479 |
1482 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { | 1480 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { |
1483 void* buffer = pDIBitmap->GetBuffer(); | 1481 void* buffer = pDIBitmap->GetBuffer(); |
1484 if (!buffer) | 1482 if (!buffer) |
1485 return; | 1483 return; |
1486 if (pDIBitmap->GetBPP() != 32) { | 1484 if (pDIBitmap->GetBPP() != 32) { |
1487 return; | 1485 return; |
1488 } | 1486 } |
1489 int height = pDIBitmap->GetHeight(); | 1487 int height = pDIBitmap->GetHeight(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 m_pCache->Dump(this); | 1564 m_pCache->Dump(this); |
1567 #endif | 1565 #endif |
1568 } | 1566 } |
1569 | 1567 |
1570 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { | 1568 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { |
1571 if (m_pOriDevice) | 1569 if (m_pOriDevice) |
1572 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); | 1570 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); |
1573 } | 1571 } |
1574 | 1572 |
1575 CFX_FxgeDevice::CFX_FxgeDevice() { | 1573 CFX_FxgeDevice::CFX_FxgeDevice() { |
1576 m_bOwnedBitmap = FALSE; | 1574 m_bOwnedBitmap = false; |
1577 } | 1575 } |
1578 | 1576 |
1579 void CFX_FxgeDevice::Clear(uint32_t color) { | 1577 void CFX_FxgeDevice::Clear(uint32_t color) { |
1580 CFX_SkiaDeviceDriver* skDriver = | 1578 CFX_SkiaDeviceDriver* skDriver = |
1581 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1579 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1582 skDriver->Clear(color); | 1580 skDriver->Clear(color); |
1583 } | 1581 } |
1584 | 1582 |
1585 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { | 1583 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { |
1586 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); | 1584 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); |
(...skipping 17 matching lines...) Expand all Loading... |
1604 if (!recorder) | 1602 if (!recorder) |
1605 return false; | 1603 return false; |
1606 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); | 1604 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); |
1607 return true; | 1605 return true; |
1608 } | 1606 } |
1609 | 1607 |
1610 bool CFX_FxgeDevice::Create(int width, | 1608 bool CFX_FxgeDevice::Create(int width, |
1611 int height, | 1609 int height, |
1612 FXDIB_Format format, | 1610 FXDIB_Format format, |
1613 CFX_DIBitmap* pOriDevice) { | 1611 CFX_DIBitmap* pOriDevice) { |
1614 m_bOwnedBitmap = TRUE; | 1612 m_bOwnedBitmap = true; |
1615 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 1613 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
1616 if (!pBitmap->Create(width, height, format)) { | 1614 if (!pBitmap->Create(width, height, format)) { |
1617 delete pBitmap; | 1615 delete pBitmap; |
1618 return false; | 1616 return false; |
1619 } | 1617 } |
1620 SetBitmap(pBitmap); | 1618 SetBitmap(pBitmap); |
1621 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, false, | 1619 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, false, |
1622 pOriDevice, false)); | 1620 pOriDevice, false)); |
1623 return true; | 1621 return true; |
1624 } | 1622 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 uint8_t g = SkGetPackedG32(srcRow[x]); | 1666 uint8_t g = SkGetPackedG32(srcRow[x]); |
1669 uint8_t b = SkGetPackedB32(srcRow[x]); | 1667 uint8_t b = SkGetPackedB32(srcRow[x]); |
1670 SkA32Assert(a); | 1668 SkA32Assert(a); |
1671 SkASSERT(r <= a); | 1669 SkASSERT(r <= a); |
1672 SkASSERT(g <= a); | 1670 SkASSERT(g <= a); |
1673 SkASSERT(b <= a); | 1671 SkASSERT(b <= a); |
1674 } | 1672 } |
1675 } | 1673 } |
1676 #endif | 1674 #endif |
1677 } | 1675 } |
OLD | NEW |