Home | History | Annotate | Download | only in debug
      1 // Copyright 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CC_DEBUG_DEBUG_RECT_HISTORY_H_
      6 #define CC_DEBUG_DEBUG_RECT_HISTORY_H_
      7 
      8 #include <vector>
      9 #include "base/basictypes.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "cc/layers/layer_lists.h"
     12 #include "ui/gfx/rect.h"
     13 #include "ui/gfx/rect_f.h"
     14 
     15 namespace cc {
     16 
     17 class LayerImpl;
     18 class LayerTreeDebugState;
     19 
     20 // There are currently six types of debug rects:
     21 //
     22 // - Paint rects (update rects): regions of a layer that needed to be
     23 // re-uploaded to the texture resource; in most cases implying that they had to
     24 // be repainted, too.
     25 //
     26 // - Property-changed rects: enclosing bounds of layers that cause changes to
     27 // the screen even if the layer did not change internally. (For example, if the
     28 // layer's opacity or position changes.)
     29 //
     30 // - Surface damage rects: the aggregate damage on a target surface that is
     31 // caused by all layers and surfaces that contribute to it. This includes (1)
     32 // paint rects, (2) property- changed rects, and (3) newly exposed areas.
     33 //
     34 // - Screen space rects: this is the region the contents occupy in screen space.
     35 //
     36 // - Replica screen space rects: this is the region the replica's contents
     37 // occupy in screen space.
     38 //
     39 // - Occluding rects: these are the regions that contribute to the occluded
     40 // region.
     41 //
     42 // - Non-Occluding rects: these are the regions of composited layers that do not
     43 //   contribute to the occluded region.
     44 //
     45 enum DebugRectType {
     46   PAINT_RECT_TYPE,
     47   PROPERTY_CHANGED_RECT_TYPE,
     48   SURFACE_DAMAGE_RECT_TYPE,
     49   SCREEN_SPACE_RECT_TYPE,
     50   REPLICA_SCREEN_SPACE_RECT_TYPE,
     51   OCCLUDING_RECT_TYPE,
     52   NONOCCLUDING_RECT_TYPE,
     53   TOUCH_EVENT_HANDLER_RECT_TYPE,
     54   WHEEL_EVENT_HANDLER_RECT_TYPE,
     55   NON_FAST_SCROLLABLE_RECT_TYPE,
     56 };
     57 
     58 struct DebugRect {
     59   DebugRect(DebugRectType new_type, gfx::RectF new_rect)
     60       : type(new_type), rect(new_rect) {}
     61 
     62   DebugRectType type;
     63   gfx::RectF rect;
     64 };
     65 
     66 // This class maintains a history of rects of various types that can be used
     67 // for debugging purposes. The overhead of collecting rects is performed only if
     68 // the appropriate LayerTreeSettings are enabled.
     69 class DebugRectHistory {
     70  public:
     71   static scoped_ptr<DebugRectHistory> Create();
     72 
     73   ~DebugRectHistory();
     74 
     75   // Note: Saving debug rects must happen before layers' change tracking is
     76   // reset.
     77   void SaveDebugRectsForCurrentFrame(
     78       LayerImpl* root_layer,
     79       const LayerImplList& render_surface_layer_list,
     80       const std::vector<gfx::Rect>& occluding_screen_space_rects,
     81       const std::vector<gfx::Rect>& non_occluding_screen_space_rects,
     82       const LayerTreeDebugState& debug_state);
     83 
     84   const std::vector<DebugRect>& debug_rects() { return debug_rects_; }
     85 
     86  private:
     87   DebugRectHistory();
     88 
     89   void SavePaintRects(LayerImpl* layer);
     90   void SavePropertyChangedRects(
     91       const LayerImplList& render_surface_layer_list);
     92   void SaveSurfaceDamageRects(
     93       const LayerImplList& render_surface_layer_list);
     94   void SaveScreenSpaceRects(
     95       const LayerImplList& render_surface_layer_list);
     96   void SaveOccludingRects(
     97       const std::vector<gfx::Rect>& occluding_screen_space_rects);
     98   void SaveNonOccludingRects(
     99       const std::vector<gfx::Rect>& non_occluding_screen_space_rects);
    100   void SaveTouchEventHandlerRects(LayerImpl* layer);
    101   void SaveTouchEventHandlerRectsCallback(LayerImpl* layer);
    102   void SaveWheelEventHandlerRects(LayerImpl* layer);
    103   void SaveWheelEventHandlerRectsCallback(LayerImpl* layer);
    104   void SaveNonFastScrollableRects(LayerImpl* layer);
    105   void SaveNonFastScrollableRectsCallback(LayerImpl* layer);
    106 
    107   std::vector<DebugRect> debug_rects_;
    108 
    109   DISALLOW_COPY_AND_ASSIGN(DebugRectHistory);
    110 };
    111 
    112 }  // namespace cc
    113 
    114 #endif  // CC_DEBUG_DEBUG_RECT_HISTORY_H_
    115