OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 #include "cc/layers/ui_resource_layer_impl.h" | |
6 | |
7 #include "base/strings/stringprintf.h" | |
8 #include "base/values.h" | |
9 #include "cc/base/math_util.h" | |
10 #include "cc/quads/texture_draw_quad.h" | |
11 #include "cc/trees/layer_tree_impl.h" | |
12 #include "cc/trees/occlusion.h" | |
13 #include "ui/gfx/geometry/rect_f.h" | |
14 | |
15 namespace cc { | |
16 | |
17 UIResourceLayerImpl::UIResourceLayerImpl(LayerTreeImpl* tree_impl, int id) | |
18 : LayerImpl(tree_impl, id), | |
19 ui_resource_id_(0), | |
20 uv_top_left_(0.f, 0.f), | |
21 uv_bottom_right_(1.f, 1.f) { | |
22 vertex_opacity_[0] = 1.0f; | |
23 vertex_opacity_[1] = 1.0f; | |
24 vertex_opacity_[2] = 1.0f; | |
25 vertex_opacity_[3] = 1.0f; | |
26 } | |
27 | |
28 UIResourceLayerImpl::~UIResourceLayerImpl() {} | |
29 | |
30 scoped_ptr<LayerImpl> UIResourceLayerImpl::CreateLayerImpl( | |
31 LayerTreeImpl* tree_impl) { | |
32 return UIResourceLayerImpl::Create(tree_impl, id()); | |
33 } | |
34 | |
35 void UIResourceLayerImpl::PushPropertiesTo(LayerImpl* layer) { | |
36 LayerImpl::PushPropertiesTo(layer); | |
37 UIResourceLayerImpl* layer_impl = static_cast<UIResourceLayerImpl*>(layer); | |
38 | |
39 layer_impl->SetUIResourceId(ui_resource_id_); | |
40 layer_impl->SetImageBounds(image_bounds_); | |
41 layer_impl->SetUV(uv_top_left_, uv_bottom_right_); | |
42 layer_impl->SetVertexOpacity(vertex_opacity_); | |
43 } | |
44 | |
45 void UIResourceLayerImpl::SetUIResourceId(UIResourceId uid) { | |
46 if (uid == ui_resource_id_) | |
47 return; | |
48 ui_resource_id_ = uid; | |
49 NoteLayerPropertyChanged(); | |
50 } | |
51 | |
52 void UIResourceLayerImpl::SetImageBounds(const gfx::Size& image_bounds) { | |
53 // This check imposes an ordering on the call sequence. An UIResource must | |
54 // exist before SetImageBounds can be called. | |
55 DCHECK(ui_resource_id_); | |
56 | |
57 if (image_bounds_ == image_bounds) | |
58 return; | |
59 | |
60 image_bounds_ = image_bounds; | |
61 | |
62 NoteLayerPropertyChanged(); | |
63 } | |
64 | |
65 void UIResourceLayerImpl::SetUV(const gfx::PointF& top_left, | |
66 const gfx::PointF& bottom_right) { | |
67 if (uv_top_left_ == top_left && uv_bottom_right_ == bottom_right) | |
68 return; | |
69 uv_top_left_ = top_left; | |
70 uv_bottom_right_ = bottom_right; | |
71 NoteLayerPropertyChanged(); | |
72 } | |
73 | |
74 void UIResourceLayerImpl::SetVertexOpacity(const float vertex_opacity[4]) { | |
75 if (vertex_opacity_[0] == vertex_opacity[0] && | |
76 vertex_opacity_[1] == vertex_opacity[1] && | |
77 vertex_opacity_[2] == vertex_opacity[2] && | |
78 vertex_opacity_[3] == vertex_opacity[3]) | |
79 return; | |
80 vertex_opacity_[0] = vertex_opacity[0]; | |
81 vertex_opacity_[1] = vertex_opacity[1]; | |
82 vertex_opacity_[2] = vertex_opacity[2]; | |
83 vertex_opacity_[3] = vertex_opacity[3]; | |
84 NoteLayerPropertyChanged(); | |
85 } | |
86 | |
87 bool UIResourceLayerImpl::WillDraw(DrawMode draw_mode, | |
88 ResourceProvider* resource_provider) { | |
89 if (!ui_resource_id_ || draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | |
90 return false; | |
91 return LayerImpl::WillDraw(draw_mode, resource_provider); | |
92 } | |
93 | |
94 void UIResourceLayerImpl::AppendQuads( | |
95 RenderPass* render_pass, | |
96 AppendQuadsData* append_quads_data) { | |
97 SharedQuadState* shared_quad_state = | |
98 render_pass->CreateAndAppendSharedQuadState(); | |
99 PopulateSharedQuadState(shared_quad_state); | |
100 | |
101 AppendDebugBorderQuad( | |
102 render_pass, content_bounds(), shared_quad_state, append_quads_data); | |
103 | |
104 if (!ui_resource_id_) | |
105 return; | |
106 | |
107 ResourceProvider::ResourceId resource = | |
108 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); | |
109 | |
110 if (!resource) | |
111 return; | |
112 | |
113 static const bool flipped = false; | |
114 static const bool nearest_neighbor = false; | |
115 static const bool premultiplied_alpha = true; | |
116 | |
117 DCHECK(!bounds().IsEmpty()); | |
118 | |
119 bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) || | |
120 contents_opaque(); | |
121 | |
122 gfx::Rect quad_rect(bounds()); | |
123 gfx::Rect opaque_rect(opaque ? quad_rect : gfx::Rect()); | |
124 gfx::Rect visible_quad_rect = | |
125 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
126 quad_rect); | |
127 if (visible_quad_rect.IsEmpty()) | |
128 return; | |
129 | |
130 TextureDrawQuad* quad = | |
131 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
132 quad->SetNew(shared_quad_state, | |
133 quad_rect, | |
134 opaque_rect, | |
135 visible_quad_rect, | |
136 resource, | |
137 premultiplied_alpha, | |
138 uv_top_left_, | |
139 uv_bottom_right_, | |
140 SK_ColorTRANSPARENT, | |
141 vertex_opacity_, | |
142 flipped, | |
143 nearest_neighbor); | |
144 } | |
145 | |
146 const char* UIResourceLayerImpl::LayerTypeAsString() const { | |
147 return "cc::UIResourceLayerImpl"; | |
148 } | |
149 | |
150 base::DictionaryValue* UIResourceLayerImpl::LayerTreeAsJson() const { | |
151 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); | |
152 | |
153 result->Set("ImageBounds", MathUtil::AsValue(image_bounds_).release()); | |
154 | |
155 base::ListValue* list = new base::ListValue; | |
156 list->AppendDouble(vertex_opacity_[0]); | |
157 list->AppendDouble(vertex_opacity_[1]); | |
158 list->AppendDouble(vertex_opacity_[2]); | |
159 list->AppendDouble(vertex_opacity_[3]); | |
160 result->Set("VertexOpacity", list); | |
161 | |
162 result->Set("UVTopLeft", MathUtil::AsValue(uv_top_left_).release()); | |
163 result->Set("UVBottomRight", MathUtil::AsValue(uv_bottom_right_).release()); | |
164 | |
165 return result; | |
166 } | |
167 | |
168 } // namespace cc | |
OLD | NEW |