| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium 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 "platform/graphics/compositing/PaintChunksToCcLayer.h" | 5 #include "platform/graphics/compositing/PaintChunksToCcLayer.h" |
| 6 | 6 |
| 7 #include "cc/paint/compositing_display_item.h" | 7 #include "cc/paint/compositing_display_item.h" |
| 8 #include "cc/paint/display_item_list.h" | 8 #include "cc/paint/display_item_list.h" |
| 9 #include "cc/paint/drawing_display_item.h" | 9 #include "cc/paint/drawing_display_item.h" |
| 10 #include "cc/paint/filter_display_item.h" | 10 #include "cc/paint/filter_display_item.h" |
| 11 #include "cc/paint/float_clip_display_item.h" | 11 #include "cc/paint/float_clip_display_item.h" |
| 12 #include "cc/paint/transform_display_item.h" | 12 #include "cc/paint/transform_display_item.h" |
| 13 #include "platform/graphics/GraphicsContext.h" | 13 #include "platform/graphics/GraphicsContext.h" |
| 14 #include "platform/graphics/paint/DisplayItemList.h" | 14 #include "platform/graphics/paint/DisplayItemList.h" |
| 15 #include "platform/graphics/paint/DrawingDisplayItem.h" | 15 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 16 #include "platform/graphics/paint/GeometryMapper.h" | 16 #include "platform/graphics/paint/GeometryMapper.h" |
| 17 #include "platform/graphics/paint/PaintChunk.h" | 17 #include "platform/graphics/paint/PaintChunk.h" |
| 18 #include "platform/graphics/paint/PropertyTreeState.h" | 18 #include "platform/graphics/paint/PropertyTreeState.h" |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 enum EndDisplayItemType { EndTransform, EndClip, EndEffect }; | 24 enum EndDisplayItemType { EndTransform, EndClip, EndEffect }; |
| 25 | 25 |
| 26 // Applies the clips between |localState| and |ancestorState| into a single | 26 // Applies the clips between |localState| and |ancestorState| into a single |
| 27 // combined cc::FloatClipDisplayItem on |ccList|. | 27 // combined cc::FloatClipDisplayItem on |ccList|. |
| 28 static void applyClipsBetweenStates(const PropertyTreeState& localState, | 28 static void applyClipsBetweenStates( |
| 29 const PropertyTreeState& ancestorState, | 29 const PropertyTreeState& localState, |
| 30 cc::DisplayItemList& ccList, | 30 const PropertyTreeState& ancestorState, |
| 31 Vector<EndDisplayItemType>& endDisplayItems, | 31 cc::DisplayItemList& ccList, |
| 32 GeometryMapper& geometryMapper) { | 32 Vector<EndDisplayItemType>& endDisplayItems) { |
| 33 DCHECK(localState.transform() == ancestorState.transform()); | 33 DCHECK(localState.transform() == ancestorState.transform()); |
| 34 #if DCHECK_IS_ON() | 34 #if DCHECK_IS_ON() |
| 35 const TransformPaintPropertyNode* transformNode = | 35 const TransformPaintPropertyNode* transformNode = |
| 36 localState.clip()->localTransformSpace(); | 36 localState.clip()->localTransformSpace(); |
| 37 if (transformNode != ancestorState.transform()) { | 37 if (transformNode != ancestorState.transform()) { |
| 38 const TransformationMatrix& localToAncestorMatrix = | 38 const TransformationMatrix& localToAncestorMatrix = |
| 39 geometryMapper.localToAncestorMatrix(transformNode, | 39 GeometryMapper::localToAncestorMatrix(transformNode, |
| 40 ancestorState.transform()); | 40 ancestorState.transform()); |
| 41 // Clips are only in descendant spaces that are transformed by one | 41 // Clips are only in descendant spaces that are transformed by one |
| 42 // or more scrolls. | 42 // or more scrolls. |
| 43 DCHECK(localToAncestorMatrix.isIdentityOrTranslation()); | 43 DCHECK(localToAncestorMatrix.isIdentityOrTranslation()); |
| 44 } | 44 } |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 const FloatClipRect& combinedClip = | 47 const FloatClipRect& combinedClip = |
| 48 geometryMapper.localToAncestorClipRect(localState, ancestorState); | 48 GeometryMapper::localToAncestorClipRect(localState, ancestorState); |
| 49 | 49 |
| 50 ccList.CreateAndAppendPairedBeginItem<cc::FloatClipDisplayItem>( | 50 ccList.CreateAndAppendPairedBeginItem<cc::FloatClipDisplayItem>( |
| 51 gfx::RectF(combinedClip.rect())); | 51 gfx::RectF(combinedClip.rect())); |
| 52 endDisplayItems.push_back(EndClip); | 52 endDisplayItems.push_back(EndClip); |
| 53 } | 53 } |
| 54 | 54 |
| 55 static void recordPairedBeginDisplayItems( | 55 static void recordPairedBeginDisplayItems( |
| 56 const Vector<PropertyTreeState>& pairedStates, | 56 const Vector<PropertyTreeState>& pairedStates, |
| 57 const PropertyTreeState& pendingLayerState, | 57 const PropertyTreeState& pendingLayerState, |
| 58 cc::DisplayItemList& ccList, | 58 cc::DisplayItemList& ccList, |
| 59 Vector<EndDisplayItemType>& endDisplayItems, | 59 Vector<EndDisplayItemType>& endDisplayItems) { |
| 60 GeometryMapper& geometryMapper) { | |
| 61 PropertyTreeState mappedClipDestinationSpace = pendingLayerState; | 60 PropertyTreeState mappedClipDestinationSpace = pendingLayerState; |
| 62 PropertyTreeState clipSpace = pendingLayerState; | 61 PropertyTreeState clipSpace = pendingLayerState; |
| 63 bool hasClip = false; | 62 bool hasClip = false; |
| 64 | 63 |
| 65 for (Vector<PropertyTreeState>::const_reverse_iterator pairedState = | 64 for (Vector<PropertyTreeState>::const_reverse_iterator pairedState = |
| 66 pairedStates.rbegin(); | 65 pairedStates.rbegin(); |
| 67 pairedState != pairedStates.rend(); ++pairedState) { | 66 pairedState != pairedStates.rend(); ++pairedState) { |
| 68 switch (pairedState->innermostNode()) { | 67 switch (pairedState->innermostNode()) { |
| 69 case PropertyTreeState::Transform: { | 68 case PropertyTreeState::Transform: { |
| 70 if (hasClip) { | 69 if (hasClip) { |
| 71 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, | 70 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, |
| 72 endDisplayItems, geometryMapper); | 71 endDisplayItems); |
| 73 hasClip = false; | 72 hasClip = false; |
| 74 } | 73 } |
| 75 mappedClipDestinationSpace = *pairedState; | 74 mappedClipDestinationSpace = *pairedState; |
| 76 clipSpace = *pairedState; | 75 clipSpace = *pairedState; |
| 77 | 76 |
| 78 TransformationMatrix matrix = pairedState->transform()->matrix(); | 77 TransformationMatrix matrix = pairedState->transform()->matrix(); |
| 79 matrix.applyTransformOrigin(pairedState->transform()->origin()); | 78 matrix.applyTransformOrigin(pairedState->transform()->origin()); |
| 80 | 79 |
| 81 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 80 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 82 transform.matrix() = TransformationMatrix::toSkMatrix44(matrix); | 81 transform.matrix() = TransformationMatrix::toSkMatrix44(matrix); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 111 | 110 |
| 112 FloatRect clipRect = | 111 FloatRect clipRect = |
| 113 pairedState->effect()->outputClip()->clipRect().rect(); | 112 pairedState->effect()->outputClip()->clipRect().rect(); |
| 114 // TODO(chrishtr): specify origin of the filter. | 113 // TODO(chrishtr): specify origin of the filter. |
| 115 FloatPoint filterOrigin; | 114 FloatPoint filterOrigin; |
| 116 if (pairedState->effect()->localTransformSpace() != | 115 if (pairedState->effect()->localTransformSpace() != |
| 117 pairedState->transform()) { | 116 pairedState->transform()) { |
| 118 const TransformPaintPropertyNode* transformNode = | 117 const TransformPaintPropertyNode* transformNode = |
| 119 pairedState->effect()->localTransformSpace(); | 118 pairedState->effect()->localTransformSpace(); |
| 120 const TransformationMatrix& localToAncestorMatrix = | 119 const TransformationMatrix& localToAncestorMatrix = |
| 121 geometryMapper.localToAncestorMatrix(transformNode, | 120 GeometryMapper::localToAncestorMatrix(transformNode, |
| 122 pairedState->transform()); | 121 pairedState->transform()); |
| 123 // Effects are only in descendant spaces that are transformed by one | 122 // Effects are only in descendant spaces that are transformed by one |
| 124 // or more scrolls. | 123 // or more scrolls. |
| 125 DCHECK(localToAncestorMatrix.isIdentityOrTranslation()); | 124 DCHECK(localToAncestorMatrix.isIdentityOrTranslation()); |
| 126 | 125 |
| 127 clipRect = localToAncestorMatrix.mapRect(clipRect); | 126 clipRect = localToAncestorMatrix.mapRect(clipRect); |
| 128 filterOrigin = localToAncestorMatrix.mapPoint(filterOrigin); | 127 filterOrigin = localToAncestorMatrix.mapPoint(filterOrigin); |
| 129 } | 128 } |
| 130 | 129 |
| 131 const bool kLcdTextRequiresOpaqueLayer = true; | 130 const bool kLcdTextRequiresOpaqueLayer = true; |
| 132 ccList.CreateAndAppendPairedBeginItem<cc::CompositingDisplayItem>( | 131 ccList.CreateAndAppendPairedBeginItem<cc::CompositingDisplayItem>( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 146 endDisplayItems.push_back(EndEffect); | 145 endDisplayItems.push_back(EndEffect); |
| 147 break; | 146 break; |
| 148 } | 147 } |
| 149 case PropertyTreeState::None: | 148 case PropertyTreeState::None: |
| 150 break; | 149 break; |
| 151 } | 150 } |
| 152 } | 151 } |
| 153 | 152 |
| 154 if (hasClip) { | 153 if (hasClip) { |
| 155 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, | 154 applyClipsBetweenStates(clipSpace, mappedClipDestinationSpace, ccList, |
| 156 endDisplayItems, geometryMapper); | 155 endDisplayItems); |
| 157 } | 156 } |
| 158 } | 157 } |
| 159 | 158 |
| 160 static void recordPairedEndDisplayItems( | 159 static void recordPairedEndDisplayItems( |
| 161 const Vector<EndDisplayItemType>& endDisplayItemTypes, | 160 const Vector<EndDisplayItemType>& endDisplayItemTypes, |
| 162 cc::DisplayItemList* ccList) { | 161 cc::DisplayItemList* ccList) { |
| 163 for (Vector<EndDisplayItemType>::const_reverse_iterator endType = | 162 for (Vector<EndDisplayItemType>::const_reverse_iterator endType = |
| 164 endDisplayItemTypes.rbegin(); | 163 endDisplayItemTypes.rbegin(); |
| 165 endType != endDisplayItemTypes.rend(); ++endType) { | 164 endType != endDisplayItemTypes.rend(); ++endType) { |
| 166 switch (*endType) { | 165 switch (*endType) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 std::move(record)); | 198 std::move(record)); |
| 200 } | 199 } |
| 201 } | 200 } |
| 202 | 201 |
| 203 } // unnamed namespace | 202 } // unnamed namespace |
| 204 | 203 |
| 205 scoped_refptr<cc::DisplayItemList> PaintChunksToCcLayer::convert( | 204 scoped_refptr<cc::DisplayItemList> PaintChunksToCcLayer::convert( |
| 206 const Vector<const PaintChunk*>& paintChunks, | 205 const Vector<const PaintChunk*>& paintChunks, |
| 207 const PropertyTreeState& layerState, | 206 const PropertyTreeState& layerState, |
| 208 const gfx::Vector2dF& layerOffset, | 207 const gfx::Vector2dF& layerOffset, |
| 209 const DisplayItemList& displayItems, | 208 const DisplayItemList& displayItems) { |
| 210 GeometryMapper& geometryMapper) { | |
| 211 auto ccList = make_scoped_refptr(new cc::DisplayItemList); | 209 auto ccList = make_scoped_refptr(new cc::DisplayItemList); |
| 212 | 210 |
| 213 gfx::Transform counterOffset; | 211 gfx::Transform counterOffset; |
| 214 counterOffset.Translate(-layerOffset.x(), -layerOffset.y()); | 212 counterOffset.Translate(-layerOffset.x(), -layerOffset.y()); |
| 215 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>( | 213 ccList->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>( |
| 216 counterOffset); | 214 counterOffset); |
| 217 | 215 |
| 218 for (const auto* paintChunk : paintChunks) { | 216 for (const auto* paintChunk : paintChunks) { |
| 219 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState; | 217 const PropertyTreeState* state = &paintChunk->properties.propertyTreeState; |
| 220 PropertyTreeStateIterator iterator(*state); | 218 PropertyTreeStateIterator iterator(*state); |
| 221 Vector<PropertyTreeState> pairedStates; | 219 Vector<PropertyTreeState> pairedStates; |
| 222 for (; state && *state != layerState; state = iterator.next()) { | 220 for (; state && *state != layerState; state = iterator.next()) { |
| 223 if (state->innermostNode() != PropertyTreeState::None) | 221 if (state->innermostNode() != PropertyTreeState::None) |
| 224 pairedStates.push_back(*state); | 222 pairedStates.push_back(*state); |
| 225 } | 223 } |
| 226 | 224 |
| 227 // TODO(chrishtr): we can avoid some extra paired display items if | 225 // TODO(chrishtr): we can avoid some extra paired display items if |
| 228 // multiple PaintChunks share them. We can also collapse clips between | 226 // multiple PaintChunks share them. We can also collapse clips between |
| 229 // transforms into single clips in the same way that PaintLayerClipper does. | 227 // transforms into single clips in the same way that PaintLayerClipper does. |
| 230 Vector<EndDisplayItemType> endDisplayItems; | 228 Vector<EndDisplayItemType> endDisplayItems; |
| 231 | 229 |
| 232 recordPairedBeginDisplayItems(pairedStates, layerState, *ccList.get(), | 230 recordPairedBeginDisplayItems(pairedStates, layerState, *ccList.get(), |
| 233 endDisplayItems, geometryMapper); | 231 endDisplayItems); |
| 234 | 232 |
| 235 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk)) | 233 for (const auto& displayItem : displayItems.itemsInPaintChunk(*paintChunk)) |
| 236 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get()); | 234 appendDisplayItemToCcDisplayItemList(displayItem, ccList.get()); |
| 237 | 235 |
| 238 recordPairedEndDisplayItems(endDisplayItems, ccList.get()); | 236 recordPairedEndDisplayItems(endDisplayItems, ccList.get()); |
| 239 } | 237 } |
| 240 | 238 |
| 241 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | 239 ccList->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); |
| 242 | 240 |
| 243 ccList->Finalize(); | 241 ccList->Finalize(); |
| 244 return ccList; | 242 return ccList; |
| 245 } | 243 } |
| 246 | 244 |
| 247 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |