Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/DisplayItem.h

Issue 2894093002: Don't access DisplayItemClient::VisualRect() for cached display items. (Closed)
Patch Set: - Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef DisplayItem_h 5 #ifndef DisplayItem_h
6 #define DisplayItem_h 6 #define DisplayItem_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/graphics/ContiguousContainer.h" 9 #include "platform/graphics/ContiguousContainer.h"
10 #include "platform/graphics/paint/DisplayItemClient.h" 10 #include "platform/graphics/paint/DisplayItemClient.h"
11 #include "platform/wtf/Allocator.h" 11 #include "platform/wtf/Allocator.h"
12 #include "platform/wtf/Assertions.h" 12 #include "platform/wtf/Assertions.h"
13 #include "platform/wtf/Noncopyable.h" 13 #include "platform/wtf/Noncopyable.h"
14 14
15 #ifndef NDEBUG 15 #ifndef NDEBUG
16 #include "platform/wtf/text/StringBuilder.h" 16 #include "platform/wtf/text/StringBuilder.h"
17 #include "platform/wtf/text/WTFString.h" 17 #include "platform/wtf/text/WTFString.h"
18 #endif 18 #endif
19 19
20 namespace blink { 20 namespace blink {
21 21
22 class GraphicsContext; 22 class GraphicsContext;
23 class IntRect; 23 class LayoutSize;
24 class WebDisplayItemList; 24 class WebDisplayItemList;
25 25
26 class PLATFORM_EXPORT DisplayItem { 26 class PLATFORM_EXPORT DisplayItem {
27 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 27 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
28 28
29 public: 29 public:
30 enum { 30 enum {
31 // Must be kept in sync with core/paint/PaintPhase.h. 31 // Must be kept in sync with core/paint/PaintPhase.h.
32 kPaintPhaseMax = 11, 32 kPaintPhaseMax = 11,
33 }; 33 };
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // border type. 192 // border type.
193 enum TableCollapsedBorderSides { 193 enum TableCollapsedBorderSides {
194 kTableCollapsedBorderTop = 1 << 0, 194 kTableCollapsedBorderTop = 1 << 0,
195 kTableCollapsedBorderRight = 1 << 1, 195 kTableCollapsedBorderRight = 1 << 1,
196 kTableCollapsedBorderBottom = 1 << 2, 196 kTableCollapsedBorderBottom = 1 << 2,
197 kTableCollapsedBorderLeft = 1 << 3, 197 kTableCollapsedBorderLeft = 1 << 3,
198 }; 198 };
199 199
200 DisplayItem(const DisplayItemClient& client, Type type, size_t derived_size) 200 DisplayItem(const DisplayItemClient& client, Type type, size_t derived_size)
201 : client_(&client), 201 : client_(&client),
202 visual_rect_(client.VisualRect()),
202 type_(type), 203 type_(type),
203 derived_size_(derived_size), 204 derived_size_(derived_size),
204 skipped_cache_(false) 205 skipped_cache_(false)
205 #ifndef NDEBUG 206 #ifndef NDEBUG
206 , 207 ,
207 client_debug_string_(client.DebugName()) 208 client_debug_string_(client.DebugName())
208 #endif 209 #endif
209 { 210 {
210 // derivedSize must fit in m_derivedSize. 211 // derivedSize must fit in m_derivedSize.
211 // If it doesn't, enlarge m_derivedSize and fix this assert. 212 // If it doesn't, enlarge m_derivedSize and fix this assert.
(...skipping 14 matching lines...) Expand all
226 }; 227 };
227 228
228 Id GetId() const { return Id(*client_, type_); } 229 Id GetId() const { return Id(*client_, type_); }
229 230
230 virtual void Replay(GraphicsContext&) const {} 231 virtual void Replay(GraphicsContext&) const {}
231 232
232 const DisplayItemClient& Client() const { 233 const DisplayItemClient& Client() const {
233 DCHECK(client_); 234 DCHECK(client_);
234 return *client_; 235 return *client_;
235 } 236 }
237
238 // This equals to Client().VisualRect() as long as the client is alive and is
239 // not invalidated. Otherwise it saves the previous visual rect of the client.
240 // See DisplayItemClient::VisualRect() about its coordinate space.
241 const LayoutRect& VisualRect() const { return visual_rect_; }
242
236 Type GetType() const { return type_; } 243 Type GetType() const { return type_; }
237 244
238 // Size of this object in memory, used to move it with memcpy. 245 // Size of this object in memory, used to move it with memcpy.
239 // This is not sizeof(*this), because it needs to account for the size of 246 // This is not sizeof(*this), because it needs to account for the size of
240 // the derived class (i.e. runtime type). Derived classes are expected to 247 // the derived class (i.e. runtime type). Derived classes are expected to
241 // supply this to the DisplayItem constructor. 248 // supply this to the DisplayItem constructor.
242 size_t DerivedSize() const { return derived_size_; } 249 size_t DerivedSize() const { return derived_size_; }
243 250
244 // For PaintController only. Painters should use DisplayItemCacheSkipper 251 // For PaintController only. Painters should use DisplayItemCacheSkipper
245 // instead. 252 // instead.
246 void SetSkippedCache() { skipped_cache_ = true; } 253 void SetSkippedCache() { skipped_cache_ = true; }
247 bool SkippedCache() const { return skipped_cache_; } 254 bool SkippedCache() const { return skipped_cache_; }
248 255
249 // TODO(wkorman): Only DrawingDisplayItem needs the visual rect argument. 256 // Appends this display item to the WebDisplayItemList, if applicable.
250 // Consider refactoring class hierarchy to make this more explicit. 257 // |visual_rect_offset| is the offset between the space of the GraphicsLayer
251 virtual void AppendToWebDisplayItemList(const IntRect&, 258 // which owns the display item and the coordinate space of VisualRect().
259 // TODO(wangxianzhu): Remove the parameter for slimming paint v2.
260 virtual void AppendToWebDisplayItemList(const LayoutSize& visual_rect_offset,
252 WebDisplayItemList*) const {} 261 WebDisplayItemList*) const {}
253 262
254 // See comments of enum Type for usage of the following macros. 263 // See comments of enum Type for usage of the following macros.
255 #define DEFINE_CATEGORY_METHODS(Category) \ 264 #define DEFINE_CATEGORY_METHODS(Category) \
256 static bool Is##Category##Type(Type type) { \ 265 static bool Is##Category##Type(Type type) { \
257 return type >= k##Category##First && type <= k##Category##Last; \ 266 return type >= k##Category##First && type <= k##Category##Last; \
258 } \ 267 } \
259 bool Is##Category() const { return Is##Category##Type(GetType()); } 268 bool Is##Category() const { return Is##Category##Type(GetType()); }
260 269
261 #define DEFINE_CONVERSION_METHODS(Category1, category1, Category2, category2) \ 270 #define DEFINE_CONVERSION_METHODS(Category1, category1, Category2, category2) \
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 WTF::String AsDebugString() const; 353 WTF::String AsDebugString() const;
345 virtual void DumpPropertiesAsDebugString(WTF::StringBuilder&) const; 354 virtual void DumpPropertiesAsDebugString(WTF::StringBuilder&) const;
346 #endif 355 #endif
347 356
348 private: 357 private:
349 // The default DisplayItem constructor is only used by 358 // The default DisplayItem constructor is only used by
350 // ContiguousContainer::appendByMoving where an invalid DisplaItem is 359 // ContiguousContainer::appendByMoving where an invalid DisplaItem is
351 // constructed at the source location. 360 // constructed at the source location.
352 template <typename T, unsigned alignment> 361 template <typename T, unsigned alignment>
353 friend class ContiguousContainer; 362 friend class ContiguousContainer;
363 friend class DisplayItemList;
354 364
355 DisplayItem() 365 DisplayItem()
356 : client_(nullptr), 366 : client_(nullptr),
357 type_(kUninitializedType), 367 type_(kUninitializedType),
358 derived_size_(sizeof(*this)), 368 derived_size_(sizeof(*this)),
359 skipped_cache_(false) {} 369 skipped_cache_(false) {}
360 370
361 const DisplayItemClient* client_; 371 const DisplayItemClient* client_;
372 LayoutRect visual_rect_;
373
362 static_assert(kTypeLast < (1 << 16), 374 static_assert(kTypeLast < (1 << 16),
363 "DisplayItem::Type should fit in 16 bits"); 375 "DisplayItem::Type should fit in 16 bits");
364 const Type type_ : 16; 376 const Type type_ : 16;
365 const unsigned derived_size_ : 8; // size of the actual derived class 377 const unsigned derived_size_ : 8; // size of the actual derived class
366 unsigned skipped_cache_ : 1; 378 unsigned skipped_cache_ : 1;
367 379
368 #ifndef NDEBUG 380 #ifndef NDEBUG
369 WTF::String client_debug_string_; 381 WTF::String client_debug_string_;
370 #endif 382 #endif
371 }; 383 };
(...skipping 28 matching lines...) Expand all
400 bool IsEndAndPairedWith(DisplayItem::Type other_type) const override = 0; 412 bool IsEndAndPairedWith(DisplayItem::Type other_type) const override = 0;
401 #endif 413 #endif
402 414
403 private: 415 private:
404 bool IsEnd() const final { return true; } 416 bool IsEnd() const final { return true; }
405 }; 417 };
406 418
407 } // namespace blink 419 } // namespace blink
408 420
409 #endif // DisplayItem_h 421 #endif // DisplayItem_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698