OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "SkImageFilter.h" | 28 #include "SkImageFilter.h" |
29 #include "SkMatrix44.h" | 29 #include "SkMatrix44.h" |
30 #include "base/trace_event/trace_event_argument.h" | 30 #include "base/trace_event/trace_event_argument.h" |
31 #include "cc/layers/layer.h" | 31 #include "cc/layers/layer.h" |
32 #include "platform/DragImage.h" | 32 #include "platform/DragImage.h" |
33 #include "platform/JSONValues.h" | 33 #include "platform/JSONValues.h" |
34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
35 #include "platform/geometry/FloatRect.h" | 35 #include "platform/geometry/FloatRect.h" |
36 #include "platform/geometry/LayoutRect.h" | 36 #include "platform/geometry/LayoutRect.h" |
37 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
| 38 #include "platform/graphics/ColorSpaceFilter.h" |
| 39 #include "platform/graphics/ColorSpaceProfile.h" |
38 #include "platform/graphics/FirstPaintInvalidationTracking.h" | 40 #include "platform/graphics/FirstPaintInvalidationTracking.h" |
39 #include "platform/graphics/GraphicsContext.h" | 41 #include "platform/graphics/GraphicsContext.h" |
40 #include "platform/graphics/GraphicsLayerFactory.h" | 42 #include "platform/graphics/GraphicsLayerFactory.h" |
| 43 #include "platform/graphics/GraphicsScreen.h" |
41 #include "platform/graphics/Image.h" | 44 #include "platform/graphics/Image.h" |
42 #include "platform/graphics/LinkHighlight.h" | 45 #include "platform/graphics/LinkHighlight.h" |
43 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 46 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
44 #include "platform/graphics/paint/DrawingRecorder.h" | 47 #include "platform/graphics/paint/DrawingRecorder.h" |
45 #include "platform/graphics/paint/PaintController.h" | 48 #include "platform/graphics/paint/PaintController.h" |
46 #include "platform/scroll/ScrollableArea.h" | 49 #include "platform/scroll/ScrollableArea.h" |
47 #include "platform/text/TextStream.h" | 50 #include "platform/text/TextStream.h" |
48 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
49 #include "public/platform/WebCompositorAnimation.h" | 52 #include "public/platform/WebCompositorAnimation.h" |
50 #include "public/platform/WebCompositorSupport.h" | 53 #include "public/platform/WebCompositorSupport.h" |
51 #include "public/platform/WebFilterOperations.h" | 54 #include "public/platform/WebFilterOperations.h" |
52 #include "public/platform/WebFloatPoint.h" | 55 #include "public/platform/WebFloatPoint.h" |
53 #include "public/platform/WebFloatRect.h" | 56 #include "public/platform/WebFloatRect.h" |
54 #include "public/platform/WebLayer.h" | 57 #include "public/platform/WebLayer.h" |
55 #include "public/platform/WebPoint.h" | 58 #include "public/platform/WebPoint.h" |
56 #include "public/platform/WebSize.h" | 59 #include "public/platform/WebSize.h" |
| 60 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
57 #include "wtf/CurrentTime.h" | 61 #include "wtf/CurrentTime.h" |
58 #include "wtf/HashMap.h" | 62 #include "wtf/HashMap.h" |
59 #include "wtf/HashSet.h" | 63 #include "wtf/HashSet.h" |
60 #include "wtf/MathExtras.h" | 64 #include "wtf/MathExtras.h" |
61 #include "wtf/text/StringUTF8Adaptor.h" | 65 #include "wtf/text/StringUTF8Adaptor.h" |
62 #include "wtf/text/WTFString.h" | 66 #include "wtf/text/WTFString.h" |
63 #include <algorithm> | 67 #include <algorithm> |
64 #include <cmath> | 68 #include <cmath> |
65 #include <utility> | 69 #include <utility> |
66 | 70 |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 return; | 1079 return; |
1076 | 1080 |
1077 m_contentsRect = rect; | 1081 m_contentsRect = rect; |
1078 updateContentsRect(); | 1082 updateContentsRect(); |
1079 } | 1083 } |
1080 | 1084 |
1081 void GraphicsLayer::setContentsToImage(Image* image, RespectImageOrientationEnum
respectImageOrientation) | 1085 void GraphicsLayer::setContentsToImage(Image* image, RespectImageOrientationEnum
respectImageOrientation) |
1082 { | 1086 { |
1083 RefPtr<SkImage> skImage = image ? image->imageForCurrentFrame() : nullptr; | 1087 RefPtr<SkImage> skImage = image ? image->imageForCurrentFrame() : nullptr; |
1084 | 1088 |
1085 if (image && skImage && image->isBitmapImage()) { | 1089 RefPtr<SkColorFilter> colorTransform; |
1086 if (respectImageOrientation == RespectImageOrientation) { | 1090 |
| 1091 if (skImage && image->isBitmapImage()) { |
| 1092 RELEASE_ASSERT(currentScreenId()); // There should be an active graphics
screen. |
| 1093 |
| 1094 if (imageColorProfilesEnabled() && toBitmapImage(image)->hasColorProfile
()) { |
| 1095 // FIXME: In an experiment, I passed a SkColorCubeFilter to the GPU
and that works. But note |
| 1096 // that a SkColorCurveFilter does not - it gets dropped on floor som
ewhere after CC sends it |
| 1097 // to the GPU process (maybe because SkColorCurveFilter has float-16
(HALF_FLOAT) textures, |
| 1098 // whereas SkColorCubeFilter does not?). |
| 1099 if (RefPtr<ColorSpaceProfile> source = toBitmapImage(image)->colorPr
ofile()) { |
| 1100 RefPtr<ColorSpaceProfile> target = screenColorProfile(currentScr
eenId()); |
| 1101 colorTransform = createColorSpaceFilter(source.get(), target.get
()); |
| 1102 } |
| 1103 } |
| 1104 |
| 1105 if (skImage && respectImageOrientation == RespectImageOrientation) { |
1087 ImageOrientation imageOrientation = toBitmapImage(image)->currentFra
meOrientation(); | 1106 ImageOrientation imageOrientation = toBitmapImage(image)->currentFra
meOrientation(); |
1088 skImage = DragImage::resizeAndOrientImage(skImage.release(), imageOr
ientation); | 1107 skImage = DragImage::resizeAndOrientImage(skImage.release(), imageOr
ientation); |
1089 } | 1108 } |
1090 } | 1109 } |
1091 | 1110 |
1092 if (image && skImage) { | 1111 if (image && skImage) { |
1093 if (!m_imageLayer) { | 1112 if (!m_imageLayer) { |
1094 m_imageLayer = adoptPtr(Platform::current()->compositorSupport()->cr
eateImageLayer()); | 1113 m_imageLayer = adoptPtr(Platform::current()->compositorSupport()->cr
eateImageLayer()); |
1095 registerContentsLayer(m_imageLayer->layer()); | 1114 registerContentsLayer(m_imageLayer->layer()); |
1096 } | 1115 } |
1097 m_imageLayer->setImage(skImage.get()); | 1116 m_imageLayer->setImage(skImage.get()); |
1098 m_imageLayer->layer()->setOpaque(image->currentFrameKnownToBeOpaque()); | 1117 m_imageLayer->layer()->setOpaque(image->currentFrameKnownToBeOpaque()); |
1099 updateContentsRect(); | 1118 updateContentsRect(); |
1100 } else { | 1119 } else { |
1101 if (m_imageLayer) { | 1120 if (m_imageLayer) { |
1102 unregisterContentsLayer(m_imageLayer->layer()); | 1121 unregisterContentsLayer(m_imageLayer->layer()); |
1103 m_imageLayer.clear(); | 1122 m_imageLayer.clear(); |
1104 } | 1123 } |
1105 } | 1124 } |
1106 | 1125 |
1107 setContentsTo(m_imageLayer ? m_imageLayer->layer() : 0); | 1126 setContentsTo(m_imageLayer ? m_imageLayer->layer() : 0); |
| 1127 |
| 1128 if (!imageColorProfilesEnabled()) |
| 1129 return; |
| 1130 |
| 1131 if (colorTransform) |
| 1132 setContentsLayerColorTransform(colorSpaceFlattenableFilter(colorTransfor
m.get())); |
| 1133 else |
| 1134 setContentsLayerColorTransform(nullptr); |
1108 } | 1135 } |
1109 | 1136 |
1110 bool GraphicsLayer::addAnimation(PassOwnPtr<WebCompositorAnimation> popAnimation
) | 1137 bool GraphicsLayer::addAnimation(PassOwnPtr<WebCompositorAnimation> popAnimation
) |
1111 { | 1138 { |
1112 OwnPtr<WebCompositorAnimation> animation(std::move(popAnimation)); | 1139 OwnPtr<WebCompositorAnimation> animation(std::move(popAnimation)); |
1113 ASSERT(animation); | 1140 ASSERT(animation); |
1114 platformLayer()->setAnimationDelegate(this); | 1141 platformLayer()->setAnimationDelegate(this); |
1115 | 1142 |
1116 // Remove any existing animations with the same animation id and target prop
erty. | 1143 // Remove any existing animations with the same animation id and target prop
erty. |
1117 platformLayer()->removeAnimation(animation->id(), animation->targetProperty(
)); | 1144 platformLayer()->removeAnimation(animation->id(), animation->targetProperty(
)); |
(...skipping 13 matching lines...) Expand all Loading... |
1131 void GraphicsLayer::abortAnimation(int animationId) | 1158 void GraphicsLayer::abortAnimation(int animationId) |
1132 { | 1159 { |
1133 platformLayer()->abortAnimation(animationId); | 1160 platformLayer()->abortAnimation(animationId); |
1134 } | 1161 } |
1135 | 1162 |
1136 WebLayer* GraphicsLayer::platformLayer() const | 1163 WebLayer* GraphicsLayer::platformLayer() const |
1137 { | 1164 { |
1138 return m_layer->layer(); | 1165 return m_layer->layer(); |
1139 } | 1166 } |
1140 | 1167 |
| 1168 void GraphicsLayer::setContentsLayerColorTransform(PassRefPtr<SkColorFilter> fil
ter) |
| 1169 { |
| 1170 if (!m_contentsLayer) |
| 1171 return; |
| 1172 |
| 1173 RefPtr<SkImageFilter> colorTransform; |
| 1174 if (RefPtr<SkColorFilter> colorFilter = filter) |
| 1175 colorTransform = adoptRef(SkColorFilterImageFilter::Create(colorFilter.g
et())); |
| 1176 |
| 1177 OwnPtr<WebFilterOperations> webFilters = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); |
| 1178 if (colorTransform) |
| 1179 webFilters->appendReferenceFilter(colorTransform.get()); |
| 1180 m_contentsLayer->setFilters(*webFilters); |
| 1181 } |
| 1182 |
1141 void GraphicsLayer::setFilters(const FilterOperations& filters) | 1183 void GraphicsLayer::setFilters(const FilterOperations& filters) |
1142 { | 1184 { |
1143 SkiaImageFilterBuilder builder; | 1185 SkiaImageFilterBuilder builder; |
1144 OwnPtr<WebFilterOperations> webFilters = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); | 1186 OwnPtr<WebFilterOperations> webFilters = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); |
1145 builder.buildFilterOperations(filters, webFilters.get()); | 1187 builder.buildFilterOperations(filters, webFilters.get()); |
1146 m_layer->layer()->setFilters(*webFilters); | 1188 m_layer->layer()->setFilters(*webFilters); |
1147 } | 1189 } |
1148 | 1190 |
1149 void GraphicsLayer::setBackdropFilters(const FilterOperations& filters) | 1191 void GraphicsLayer::setBackdropFilters(const FilterOperations& filters) |
1150 { | 1192 { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 { | 1302 { |
1261 if (!layer) { | 1303 if (!layer) { |
1262 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); | 1304 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); |
1263 return; | 1305 return; |
1264 } | 1306 } |
1265 | 1307 |
1266 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1308 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
1267 fprintf(stderr, "%s\n", output.utf8().data()); | 1309 fprintf(stderr, "%s\n", output.utf8().data()); |
1268 } | 1310 } |
1269 #endif | 1311 #endif |
OLD | NEW |