| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include <utility> | 64 #include <utility> |
| 65 | 65 |
| 66 #ifndef NDEBUG | 66 #ifndef NDEBUG |
| 67 #include <stdio.h> | 67 #include <stdio.h> |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 namespace blink { | 70 namespace blink { |
| 71 | 71 |
| 72 static bool s_drawDebugRedFill = true; | 72 static bool s_drawDebugRedFill = true; |
| 73 | 73 |
| 74 // TODO(wangxianzhu): Remove this when we no longer invalidate rects. | 74 struct PaintInvalidationInfo { |
| 75 struct PaintInvalidationTrackingInfo { | |
| 76 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 75 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 77 Vector<FloatRect> invalidationRects; | 76 // This is for comparison only. Don't dereference because the client may hav
e died. |
| 78 Vector<String> invalidationObjects; | 77 const DisplayItemClient* client; |
| 78 String clientDebugName; |
| 79 FloatRect rect; |
| 80 PaintInvalidationReason reason; |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 typedef HashMap<const GraphicsLayer*, PaintInvalidationTrackingInfo> PaintInvali
dationTrackingMap; | 83 typedef HashMap<const GraphicsLayer*, Vector<PaintInvalidationInfo>> PaintInvali
dationTrackingMap; |
| 82 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() | 84 static PaintInvalidationTrackingMap& paintInvalidationTrackingMap() |
| 83 { | 85 { |
| 84 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); | 86 DEFINE_STATIC_LOCAL(PaintInvalidationTrackingMap, map, ()); |
| 85 return map; | 87 return map; |
| 86 } | 88 } |
| 87 | 89 |
| 88 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) | 90 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) |
| 89 { | 91 { |
| 90 OwnPtr<GraphicsLayer> layer = adoptPtr(new GraphicsLayer(client)); | 92 OwnPtr<GraphicsLayer> layer = adoptPtr(new GraphicsLayer(client)); |
| 91 return layer.release(); | 93 return layer.release(); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 532 |
| 531 void GraphicsLayer::resetTrackedPaintInvalidations() | 533 void GraphicsLayer::resetTrackedPaintInvalidations() |
| 532 { | 534 { |
| 533 paintInvalidationTrackingMap().remove(this); | 535 paintInvalidationTrackingMap().remove(this); |
| 534 } | 536 } |
| 535 | 537 |
| 536 bool GraphicsLayer::hasTrackedPaintInvalidations() const | 538 bool GraphicsLayer::hasTrackedPaintInvalidations() const |
| 537 { | 539 { |
| 538 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f
ind(this); | 540 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f
ind(this); |
| 539 if (it != paintInvalidationTrackingMap().end()) | 541 if (it != paintInvalidationTrackingMap().end()) |
| 540 return !it->value.invalidationRects.isEmpty(); | 542 return !it->value.isEmpty(); |
| 541 return false; | 543 return false; |
| 542 } | 544 } |
| 543 | 545 |
| 544 void GraphicsLayer::trackPaintInvalidationRect(const FloatRect& rect) | 546 void GraphicsLayer::trackPaintInvalidation(const DisplayItemClient& client, cons
t FloatRect& rect, PaintInvalidationReason reason) |
| 545 { | 547 { |
| 546 if (rect.isEmpty()) | |
| 547 return; | |
| 548 | |
| 549 // The caller must check isTrackingPaintInvalidations() before calling this
method | 548 // The caller must check isTrackingPaintInvalidations() before calling this
method |
| 550 // to avoid constructing the rect unnecessarily. | 549 // to avoid constructing the rect unnecessarily. |
| 551 ASSERT(isTrackingPaintInvalidations()); | 550 ASSERT(isTrackingPaintInvalidations()); |
| 552 | 551 |
| 553 paintInvalidationTrackingMap().add(this, PaintInvalidationTrackingInfo()).st
oredValue->value.invalidationRects.append(rect); | 552 PaintInvalidationInfo info = { &client, client.debugName(), rect, reason }; |
| 553 paintInvalidationTrackingMap().add(this, Vector<PaintInvalidationInfo>()).st
oredValue->value.append(info); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void GraphicsLayer::trackPaintInvalidationObject(const String& objectDebugString
) | 556 static bool comparePaintInvalidationInfo(const PaintInvalidationInfo& a, const P
aintInvalidationInfo& b) |
| 557 { | 557 { |
| 558 if (objectDebugString.isEmpty()) | 558 return codePointCompareLessThan(a.clientDebugName, b.clientDebugName); |
| 559 return; | |
| 560 | |
| 561 // The caller must check isTrackingPaintInvalidations() before calling this
method | |
| 562 // because constructing the debug string will be costly. | |
| 563 ASSERT(isTrackingPaintInvalidations()); | |
| 564 | |
| 565 paintInvalidationTrackingMap().add(this, PaintInvalidationTrackingInfo()).st
oredValue->value.invalidationObjects.append(objectDebugString); | |
| 566 } | |
| 567 | |
| 568 static bool compareFloatRects(const FloatRect& a, const FloatRect& b) | |
| 569 { | |
| 570 if (a.x() != b.x()) | |
| 571 return a.x() > b.x(); | |
| 572 if (a.y() != b.y()) | |
| 573 return a.y() > b.y(); | |
| 574 if (a.width() != b.width()) | |
| 575 return a.width() > b.width(); | |
| 576 return a.height() > b.height(); | |
| 577 } | 559 } |
| 578 | 560 |
| 579 template <typename T> | 561 template <typename T> |
| 580 static PassRefPtr<JSONArray> pointAsJSONArray(const T& point) | 562 static PassRefPtr<JSONArray> pointAsJSONArray(const T& point) |
| 581 { | 563 { |
| 582 RefPtr<JSONArray> array = JSONArray::create(); | 564 RefPtr<JSONArray> array = JSONArray::create(); |
| 583 array->pushNumber(point.x()); | 565 array->pushNumber(point.x()); |
| 584 array->pushNumber(point.y()); | 566 array->pushNumber(point.y()); |
| 585 return array; | 567 return array; |
| 586 } | 568 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 json->setArray("transform", transformAsJSONArray(m_transform)); | 700 json->setArray("transform", transformAsJSONArray(m_transform)); |
| 719 | 701 |
| 720 if (m_replicaLayer) | 702 if (m_replicaLayer) |
| 721 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r
enderingContextMap)); | 703 json->setObject("replicaLayer", m_replicaLayer->layerTreeAsJSON(flags, r
enderingContextMap)); |
| 722 | 704 |
| 723 if (m_replicatedLayer) | 705 if (m_replicatedLayer) |
| 724 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ?
pointerAsString(m_replicatedLayer) : ""); | 706 json->setString("replicatedLayer", flags & LayerTreeIncludesDebugInfo ?
pointerAsString(m_replicatedLayer) : ""); |
| 725 | 707 |
| 726 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f
ind(this); | 708 PaintInvalidationTrackingMap::iterator it = paintInvalidationTrackingMap().f
ind(this); |
| 727 if (it != paintInvalidationTrackingMap().end()) { | 709 if (it != paintInvalidationTrackingMap().end()) { |
| 728 if (flags & LayerTreeIncludesPaintInvalidationRects) { | 710 if (flags & LayerTreeIncludesPaintInvalidations) { |
| 729 Vector<FloatRect>& rects = it->value.invalidationRects; | 711 Vector<PaintInvalidationInfo>& infos = it->value; |
| 730 if (!rects.isEmpty()) { | 712 if (!infos.isEmpty()) { |
| 731 std::sort(rects.begin(), rects.end(), &compareFloatRects); | 713 std::stable_sort(infos.begin(), infos.end(), &comparePaintInvali
dationInfo); |
| 732 RefPtr<JSONArray> rectsJSON = JSONArray::create(); | 714 RefPtr<JSONArray> paintInvalidationsJSON = JSONArray::create(); |
| 733 for (auto& rect : rects) { | 715 const DisplayItemClient* lastDisplayItemClientWithRect = nullptr
; |
| 734 if (rect.isEmpty()) | 716 for (auto& info : infos) { |
| 735 continue; | 717 RefPtr<JSONObject> infoJSON = JSONObject::create(); |
| 736 rectsJSON->pushArray(rectAsJSONArray(rect)); | 718 if (info.rect.isEmpty()) { |
| 719 // Entry with empty rect is from invalidateDisplayItemCl
ient(). |
| 720 // Skip the entry if the client is the same as the previ
ous setNeedsDisplayInRect(). |
| 721 if (info.client == lastDisplayItemClientWithRect) |
| 722 continue; |
| 723 } else { |
| 724 lastDisplayItemClientWithRect = info.client; |
| 725 } |
| 726 infoJSON->setString("object", info.clientDebugName); |
| 727 infoJSON->setArray("rect", rectAsJSONArray(info.rect)); |
| 728 infoJSON->setString("reason", paintInvalidationReasonToStrin
g(info.reason)); |
| 729 paintInvalidationsJSON->pushObject(infoJSON); |
| 737 } | 730 } |
| 738 json->setArray("repaintRects", rectsJSON); | 731 json->setArray("paintInvalidations", paintInvalidationsJSON); |
| 739 } | |
| 740 } | |
| 741 | |
| 742 if (flags & LayerTreeIncludesPaintInvalidationObjects) { | |
| 743 Vector<String>& clients = it->value.invalidationObjects; | |
| 744 if (!clients.isEmpty()) { | |
| 745 RefPtr<JSONArray> clientsJSON = JSONArray::create(); | |
| 746 for (auto& clientString : clients) | |
| 747 clientsJSON->pushString(clientString); | |
| 748 json->setArray("paintInvalidationClients", clientsJSON); | |
| 749 } | 732 } |
| 750 } | 733 } |
| 751 } | 734 } |
| 752 | 735 |
| 753 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) { | 736 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) { |
| 754 RefPtr<JSONArray> paintingPhasesJSON = JSONArray::create(); | 737 RefPtr<JSONArray> paintingPhasesJSON = JSONArray::create(); |
| 755 if (m_paintingPhase & GraphicsLayerPaintBackground) | 738 if (m_paintingPhase & GraphicsLayerPaintBackground) |
| 756 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground"); | 739 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground"); |
| 757 if (m_paintingPhase & GraphicsLayerPaintForeground) | 740 if (m_paintingPhase & GraphicsLayerPaintForeground) |
| 758 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground"); | 741 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground"); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 return; | 1014 return; |
| 1032 m_isRootForIsolatedGroup = isolated; | 1015 m_isRootForIsolatedGroup = isolated; |
| 1033 platformLayer()->setIsRootForIsolatedGroup(isolated); | 1016 platformLayer()->setIsRootForIsolatedGroup(isolated); |
| 1034 } | 1017 } |
| 1035 | 1018 |
| 1036 void GraphicsLayer::setContentsNeedsDisplay() | 1019 void GraphicsLayer::setContentsNeedsDisplay() |
| 1037 { | 1020 { |
| 1038 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { | 1021 if (WebLayer* contentsLayer = contentsLayerIfRegistered()) { |
| 1039 contentsLayer->invalidate(); | 1022 contentsLayer->invalidate(); |
| 1040 if (isTrackingPaintInvalidations()) | 1023 if (isTrackingPaintInvalidations()) |
| 1041 trackPaintInvalidationRect(m_contentsRect); | 1024 trackPaintInvalidation(*this, m_contentsRect, PaintInvalidationFull)
; |
| 1042 } | 1025 } |
| 1043 } | 1026 } |
| 1044 | 1027 |
| 1045 void GraphicsLayer::setNeedsDisplay() | 1028 void GraphicsLayer::setNeedsDisplay() |
| 1046 { | 1029 { |
| 1047 if (!drawsContent()) | 1030 if (!drawsContent()) |
| 1048 return; | 1031 return; |
| 1049 | 1032 |
| 1050 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv
ely does so. | 1033 // TODO(chrishtr): stop invalidating the rects once FrameView::paintRecursiv
ely does so. |
| 1051 m_layer->layer()->invalidate(); | 1034 m_layer->layer()->invalidate(); |
| 1052 if (isTrackingPaintInvalidations()) | |
| 1053 trackPaintInvalidationRect(FloatRect(FloatPoint(), m_size)); | |
| 1054 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 1035 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
| 1055 m_linkHighlights[i]->invalidate(); | 1036 m_linkHighlights[i]->invalidate(); |
| 1037 getPaintController().invalidateAll(); |
| 1056 | 1038 |
| 1057 getPaintController().invalidateAll(); | |
| 1058 if (isTrackingPaintInvalidations()) | 1039 if (isTrackingPaintInvalidations()) |
| 1059 trackPaintInvalidationObject("##ALL##"); | 1040 trackPaintInvalidation(*this, FloatRect(FloatPoint(), m_size), PaintInva
lidationFull); |
| 1060 } | 1041 } |
| 1061 | 1042 |
| 1062 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation
Reason invalidationReason) | 1043 void GraphicsLayer::setNeedsDisplayInRect(const IntRect& rect, PaintInvalidation
Reason invalidationReason, const DisplayItemClient& client) |
| 1063 { | 1044 { |
| 1064 if (!drawsContent()) | 1045 if (!drawsContent()) |
| 1065 return; | 1046 return; |
| 1066 | 1047 |
| 1067 m_layer->layer()->invalidateRect(rect); | 1048 m_layer->layer()->invalidateRect(rect); |
| 1068 if (firstPaintInvalidationTrackingEnabled()) | 1049 if (firstPaintInvalidationTrackingEnabled()) |
| 1069 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); | 1050 m_debugInfo.appendAnnotatedInvalidateRect(rect, invalidationReason); |
| 1070 if (isTrackingPaintInvalidations()) | |
| 1071 trackPaintInvalidationRect(rect); | |
| 1072 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 1051 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
| 1073 m_linkHighlights[i]->invalidate(); | 1052 m_linkHighlights[i]->invalidate(); |
| 1053 |
| 1054 if (isTrackingPaintInvalidations()) |
| 1055 trackPaintInvalidation(client, rect, invalidationReason); |
| 1074 } | 1056 } |
| 1075 | 1057 |
| 1076 void GraphicsLayer::invalidateDisplayItemClient(const DisplayItemClient& display
ItemClient, PaintInvalidationReason) | 1058 void GraphicsLayer::invalidateDisplayItemClient(const DisplayItemClient& display
ItemClient, PaintInvalidationReason invalidationReason) |
| 1077 { | 1059 { |
| 1078 if (!drawsContent()) | 1060 if (!drawsContent()) |
| 1079 return; | 1061 return; |
| 1080 | 1062 |
| 1081 getPaintController().invalidate(displayItemClient); | 1063 getPaintController().invalidate(displayItemClient); |
| 1064 |
| 1082 if (isTrackingPaintInvalidations()) | 1065 if (isTrackingPaintInvalidations()) |
| 1083 trackPaintInvalidationObject(displayItemClient.debugName()); | 1066 trackPaintInvalidation(displayItemClient, FloatRect(), invalidationReaso
n); |
| 1084 } | 1067 } |
| 1085 | 1068 |
| 1086 void GraphicsLayer::setContentsRect(const IntRect& rect) | 1069 void GraphicsLayer::setContentsRect(const IntRect& rect) |
| 1087 { | 1070 { |
| 1088 if (rect == m_contentsRect) | 1071 if (rect == m_contentsRect) |
| 1089 return; | 1072 return; |
| 1090 | 1073 |
| 1091 m_contentsRect = rect; | 1074 m_contentsRect = rect; |
| 1092 updateContentsRect(); | 1075 updateContentsRect(); |
| 1093 } | 1076 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 { | 1213 { |
| 1231 if (!layer) { | 1214 if (!layer) { |
| 1232 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); | 1215 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); |
| 1233 return; | 1216 return; |
| 1234 } | 1217 } |
| 1235 | 1218 |
| 1236 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1219 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
| 1237 fprintf(stderr, "%s\n", output.utf8().data()); | 1220 fprintf(stderr, "%s\n", output.utf8().data()); |
| 1238 } | 1221 } |
| 1239 #endif | 1222 #endif |
| OLD | NEW |