1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_TREES_LAYER_TREE_HOST_COMMON_H_
#define CC_TREES_LAYER_TREE_HOST_COMMON_H_
#include <vector>
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "cc/base/cc_export.h"
#include "cc/base/scoped_ptr_vector.h"
#include "cc/layers/layer_lists.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/vector2d.h"
namespace cc {
class LayerImpl;
class Layer;
class CC_EXPORT LayerTreeHostCommon {
public:
static gfx::Rect CalculateVisibleRect(gfx::Rect target_surface_rect,
gfx::Rect layer_bound_rect,
const gfx::Transform& transform);
static void CalculateDrawProperties(
Layer* root_layer,
gfx::Size device_viewport_size,
const gfx::Transform& device_transform,
float device_scale_factor,
float page_scale_factor,
Layer* page_scale_application_layer,
int max_texture_size,
bool can_use_lcd_text,
bool can_adjust_raster_scales,
LayerList* render_surface_layer_list);
static void CalculateDrawProperties(
LayerImpl* root_layer,
gfx::Size device_viewport_size,
const gfx::Transform& device_transform,
float device_scale_factor,
float page_scale_factor,
LayerImpl* page_scale_application_layer,
int max_texture_size,
bool can_use_lcd_text,
bool can_adjust_raster_scales,
LayerImplList* render_surface_layer_list);
// Performs hit testing for a given render_surface_layer_list.
static LayerImpl* FindLayerThatIsHitByPoint(
gfx::PointF screen_space_point,
const LayerImplList& render_surface_layer_list);
static LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
gfx::PointF screen_space_point,
const LayerImplList& render_surface_layer_list);
static bool LayerHasTouchEventHandlersAt(gfx::PointF screen_space_point,
LayerImpl* layer_impl);
template <typename LayerType>
static bool RenderSurfaceContributesToTarget(LayerType*,
int target_surface_layer_id);
template <typename LayerType>
static void CallFunctionForSubtree(
LayerType* root_layer,
const base::Callback<void(LayerType* layer)>& function);
// Returns a layer with the given id if one exists in the subtree starting
// from the given root layer (including mask and replica layers).
template <typename LayerType>
static LayerType* FindLayerInSubtree(LayerType* root_layer, int layer_id);
static Layer* get_child_as_raw_ptr(
const LayerList& children,
size_t index) {
return children[index].get();
}
static LayerImpl* get_child_as_raw_ptr(
const OwnedLayerImplList& children,
size_t index) {
return children[index];
}
struct ScrollUpdateInfo {
int layer_id;
gfx::Vector2d scroll_delta;
};
};
struct CC_EXPORT ScrollAndScaleSet {
ScrollAndScaleSet();
~ScrollAndScaleSet();
std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls;
float page_scale_delta;
};
template <typename LayerType>
bool LayerTreeHostCommon::RenderSurfaceContributesToTarget(
LayerType* layer,
int target_surface_layer_id) {
// A layer will either contribute its own content, or its render surface's
// content, to the target surface. The layer contributes its surface's content
// when both the following are true:
// (1) The layer actually has a render surface, and
// (2) The layer's render surface is not the same as the target surface.
//
// Otherwise, the layer just contributes itself to the target surface.
return layer->render_surface() && layer->id() != target_surface_layer_id;
}
template <typename LayerType>
LayerType* LayerTreeHostCommon::FindLayerInSubtree(LayerType* root_layer,
int layer_id) {
if (!root_layer)
return NULL;
if (root_layer->id() == layer_id)
return root_layer;
if (root_layer->mask_layer() && root_layer->mask_layer()->id() == layer_id)
return root_layer->mask_layer();
if (root_layer->replica_layer() &&
root_layer->replica_layer()->id() == layer_id)
return root_layer->replica_layer();
for (size_t i = 0; i < root_layer->children().size(); ++i) {
if (LayerType* found = FindLayerInSubtree(
get_child_as_raw_ptr(root_layer->children(), i), layer_id))
return found;
}
return NULL;
}
template <typename LayerType>
void LayerTreeHostCommon::CallFunctionForSubtree(
LayerType* root_layer,
const base::Callback<void(LayerType* layer)>& function) {
function.Run(root_layer);
if (LayerType* mask_layer = root_layer->mask_layer())
function.Run(mask_layer);
if (LayerType* replica_layer = root_layer->replica_layer()) {
function.Run(replica_layer);
if (LayerType* mask_layer = replica_layer->mask_layer())
function.Run(mask_layer);
}
for (size_t i = 0; i < root_layer->children().size(); ++i) {
CallFunctionForSubtree(get_child_as_raw_ptr(root_layer->children(), i),
function);
}
}
} // namespace cc
#endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_
|