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

Side by Side Diff: ui/gfx/compositor/layer.h

Issue 9288053: Remove old (pre-webkit) compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/debug_utils.cc ('k') | ui/gfx/compositor/layer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_GFX_COMPOSITOR_LAYER_H_ 5 #ifndef UI_GFX_COMPOSITOR_LAYER_H_
6 #define UI_GFX_COMPOSITOR_LAYER_H_ 6 #define UI_GFX_COMPOSITOR_LAYER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // |target|. Necessarily, |source| and |target| must inhabit the same Layer 145 // |target|. Necessarily, |source| and |target| must inhabit the same Layer
146 // tree. 146 // tree.
147 static void ConvertPointToLayer(const Layer* source, 147 static void ConvertPointToLayer(const Layer* source,
148 const Layer* target, 148 const Layer* target,
149 gfx::Point* point); 149 gfx::Point* point);
150 150
151 // See description in View for details 151 // See description in View for details
152 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); 152 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely);
153 bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; } 153 bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; }
154 154
155 // Returns the invalid rectangle. That is, the region of the layer that needs
156 // to be repainted. This is exposed for testing and isn't generally useful.
157 const gfx::Rect& invalid_rect() const { return invalid_rect_; }
158
159 const gfx::Rect& hole_rect() const { return hole_rect_; }
160
161 const std::string& name() const { return name_; } 155 const std::string& name() const { return name_; }
162 void set_name(const std::string& name) { name_ = name; } 156 void set_name(const std::string& name) { name_ = name; }
163 157
164 const ui::Texture* texture() const { return texture_.get(); } 158 const ui::Texture* texture() const { return texture_.get(); }
165 159
166 // Assigns a new external texture. |texture| can be NULL to disable external 160 // Assigns a new external texture. |texture| can be NULL to disable external
167 // updates. 161 // updates.
168 // TODO(beng): This can be removed from the API when we are in a 162 // TODO(beng): This can be removed from the API when we are in a
169 // single-compositor world. 163 // single-compositor world.
170 void SetExternalTexture(ui::Texture* texture); 164 void SetExternalTexture(ui::Texture* texture);
171 165
172 // Resets the canvas of the texture. 166 // Resets the canvas of the texture.
173 void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin); 167 void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin);
174 168
175 // Adds |invalid_rect| to the Layer's pending invalid rect and calls 169 // Adds |invalid_rect| to the Layer's pending invalid rect and calls
176 // ScheduleDraw(). 170 // ScheduleDraw().
177 void SchedulePaint(const gfx::Rect& invalid_rect); 171 void SchedulePaint(const gfx::Rect& invalid_rect);
178 172
179 // Schedules a redraw of the layer tree at the compositor. 173 // Schedules a redraw of the layer tree at the compositor.
180 void ScheduleDraw(); 174 void ScheduleDraw();
181 175
182 // Does drawing for the layer.
183 void Draw();
184
185 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting
186 // with the receiver.
187 void DrawTree();
188
189 // Sometimes the Layer is being updated by something other than SetCanvas 176 // Sometimes the Layer is being updated by something other than SetCanvas
190 // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT). 177 // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT).
191 bool layer_updated_externally() const { return layer_updated_externally_; } 178 bool layer_updated_externally() const { return layer_updated_externally_; }
192 179
193 // WebContentLayerClient 180 // WebContentLayerClient
194 virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip); 181 virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip);
195 182
196 #if defined(USE_WEBKIT_COMPOSITOR)
197 WebKit::WebLayer web_layer() { return web_layer_; } 183 WebKit::WebLayer web_layer() { return web_layer_; }
198 #endif
199 184
200 private: 185 private:
201 struct LayerProperties { 186 struct LayerProperties {
202 public: 187 public:
203 ui::Layer* layer; 188 ui::Layer* layer;
204 ui::Transform transform_relative_to_root; 189 ui::Transform transform_relative_to_root;
205 }; 190 };
206 191
207 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than 192 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than
208 // 1.0, we'll render to a separate texture, and then apply the alpha. 193 // 1.0, we'll render to a separate texture, and then apply the alpha.
209 // Currently, we multiply our opacity by all our ancestor's opacities and 194 // Currently, we multiply our opacity by all our ancestor's opacities and
210 // use the combined result, but this is only temporary. 195 // use the combined result, but this is only temporary.
211 float GetCombinedOpacity() const; 196 float GetCombinedOpacity() const;
212 197
213 // Called during the Draw() pass to freshen the Layer's contents from the
214 // delegate.
215 void UpdateLayerCanvas();
216
217 // Stacks |child| above or below |other|. Helper method for StackAbove() and 198 // Stacks |child| above or below |other|. Helper method for StackAbove() and
218 // StackBelow(). 199 // StackBelow().
219 void StackRelativeTo(Layer* child, Layer* other, bool above); 200 void StackRelativeTo(Layer* child, Layer* other, bool above);
220 201
221 // Called to indicate that a layer's properties have changed and that the
222 // holes for the layers must be recomputed.
223 void SetNeedsToRecomputeHole();
224
225 // Resets |hole_rect_| to the empty rect for all layers below and
226 // including this one.
227 void ClearHoleRects();
228
229 // Does a preorder traversal of layers starting with this layer. Omits layers 202 // Does a preorder traversal of layers starting with this layer. Omits layers
230 // which cannot punch a hole in another layer such as non visible layers 203 // which cannot punch a hole in another layer such as non visible layers
231 // and layers which don't fill their bounds opaquely. 204 // and layers which don't fill their bounds opaquely.
232 void GetLayerProperties(const ui::Transform& current_transform, 205 void GetLayerProperties(const ui::Transform& current_transform,
233 std::vector<LayerProperties>* traverasal); 206 std::vector<LayerProperties>* traverasal);
234 207
235 // A hole in a layer is an area in the layer that does not get drawn
236 // because this area is covered up with another layer which is known to be
237 // opaque.
238 // This method computes the dimension of the hole (if there is one)
239 // based on whether one of its child nodes is always opaque.
240 // Note: This method should only be called from the root.
241 void RecomputeHole();
242
243 void set_hole_rect(const gfx::Rect& hole_rect) {
244 hole_rect_ = hole_rect;
245 }
246
247 // Determines the regions that don't intersect |rect| and places the
248 // result in |sides|.
249 //
250 // rect_____________________________
251 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
252 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx|
253 // |________________________________|
254 // |xxxxx| |xxxxx|
255 // |xxxxx|region_to_punch_out |xxxxx|
256 // |left | |right|
257 // |_____|____________________|_____|
258 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
259 // |xxxxxxxxxx bottom xxxxxxxxxxxxxx|
260 // |________________________________|
261 static void PunchHole(const gfx::Rect& rect,
262 const gfx::Rect& region_to_punch_out,
263 std::vector<gfx::Rect>* sides);
264
265 // Drops texture just for this layer.
266 void DropTexture();
267
268 // Drop all textures for layers below and including this one. Called when
269 // the layer is removed from a hierarchy. Textures will be re-generated if
270 // the layer is subsequently re-attached and needs to be drawn.
271 void DropTextures();
272
273 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; 208 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const;
274 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; 209 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const;
275 210
276 bool GetTransformRelativeTo(const Layer* ancestor, 211 bool GetTransformRelativeTo(const Layer* ancestor,
277 Transform* transform) const; 212 Transform* transform) const;
278 213
279 // The only externally updated layers are ones that get their pixels from 214 // The only externally updated layers are ones that get their pixels from
280 // WebKit and WebKit does not produce valid alpha values. All other layers 215 // WebKit and WebKit does not produce valid alpha values. All other layers
281 // should have valid alpha. 216 // should have valid alpha.
282 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } 217 bool has_valid_alpha_channel() const { return !layer_updated_externally_; }
283 218
284 // Following are invoked from the animation or if no animation exists to 219 // Following are invoked from the animation or if no animation exists to
285 // update the values immediately. 220 // update the values immediately.
286 void SetBoundsImmediately(const gfx::Rect& bounds); 221 void SetBoundsImmediately(const gfx::Rect& bounds);
287 void SetTransformImmediately(const ui::Transform& transform); 222 void SetTransformImmediately(const ui::Transform& transform);
288 void SetOpacityImmediately(float opacity); 223 void SetOpacityImmediately(float opacity);
289 224
290 // Implementation of LayerAnimatorDelegate 225 // Implementation of LayerAnimatorDelegate
291 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; 226 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
292 virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE; 227 virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE;
293 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; 228 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE;
294 virtual void ScheduleDrawForAnimation() OVERRIDE; 229 virtual void ScheduleDrawForAnimation() OVERRIDE;
295 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; 230 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE;
296 virtual const Transform& GetTransformForAnimation() const OVERRIDE; 231 virtual const Transform& GetTransformForAnimation() const OVERRIDE;
297 virtual float GetOpacityForAnimation() const OVERRIDE; 232 virtual float GetOpacityForAnimation() const OVERRIDE;
298 233
299 #if defined(USE_WEBKIT_COMPOSITOR)
300 void CreateWebLayer(); 234 void CreateWebLayer();
301 void RecomputeTransform(); 235 void RecomputeTransform();
302 void RecomputeDrawsContentAndUVRect(); 236 void RecomputeDrawsContentAndUVRect();
303 void RecomputeDebugBorderColor(); 237 void RecomputeDebugBorderColor();
304 #endif
305 238
306 const LayerType type_; 239 const LayerType type_;
307 240
308 Compositor* compositor_; 241 Compositor* compositor_;
309 242
310 scoped_refptr<ui::Texture> texture_; 243 scoped_refptr<ui::Texture> texture_;
311 244
312 Layer* parent_; 245 Layer* parent_;
313 246
314 // This layer's children, in bottom-to-top stacking order. 247 // This layer's children, in bottom-to-top stacking order.
315 std::vector<Layer*> children_; 248 std::vector<Layer*> children_;
316 249
317 ui::Transform transform_; 250 ui::Transform transform_;
318 251
319 gfx::Rect bounds_; 252 gfx::Rect bounds_;
320 253
321 // Visibility of this layer. See SetVisible/IsDrawn for more details. 254 // Visibility of this layer. See SetVisible/IsDrawn for more details.
322 bool visible_; 255 bool visible_;
323 256
324 bool fills_bounds_opaquely_; 257 bool fills_bounds_opaquely_;
325 258
326 gfx::Rect hole_rect_;
327
328 bool recompute_hole_;
329
330 gfx::Rect invalid_rect_;
331
332 // If true the layer is always up to date. 259 // If true the layer is always up to date.
333 bool layer_updated_externally_; 260 bool layer_updated_externally_;
334 261
335 float opacity_; 262 float opacity_;
336 263
337 std::string name_; 264 std::string name_;
338 265
339 LayerDelegate* delegate_; 266 LayerDelegate* delegate_;
340 267
341 scoped_ptr<LayerAnimator> animator_; 268 scoped_ptr<LayerAnimator> animator_;
342 269
343 #if defined(USE_WEBKIT_COMPOSITOR)
344 WebKit::WebLayer web_layer_; 270 WebKit::WebLayer web_layer_;
345 bool web_layer_is_accelerated_; 271 bool web_layer_is_accelerated_;
346 bool show_debug_borders_; 272 bool show_debug_borders_;
347 #endif
348 273
349 DISALLOW_COPY_AND_ASSIGN(Layer); 274 DISALLOW_COPY_AND_ASSIGN(Layer);
350 }; 275 };
351 276
352 } // namespace ui 277 } // namespace ui
353 278
354 #endif // UI_GFX_COMPOSITOR_LAYER_H_ 279 #endif // UI_GFX_COMPOSITOR_LAYER_H_
OLDNEW
« no previous file with comments | « ui/gfx/compositor/debug_utils.cc ('k') | ui/gfx/compositor/layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698