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

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

Issue 8222028: Use WebKit compositor in ui::Layer (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase,fixes Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient .h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h"
15 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
16 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
17 #include "ui/gfx/compositor/compositor.h" 20 #include "ui/gfx/compositor/compositor.h"
18 #include "ui/gfx/compositor/layer_animator.h" 21 #include "ui/gfx/compositor/layer_animator.h"
19 #include "ui/gfx/compositor/layer_animator_delegate.h" 22 #include "ui/gfx/compositor/layer_animator_delegate.h"
20 #include "ui/gfx/compositor/layer_delegate.h" 23 #include "ui/gfx/compositor/layer_delegate.h"
21 24
22 class SkCanvas; 25 class SkCanvas;
23 26
24 namespace ui { 27 namespace ui {
25 28
26 class Animation; 29 class Animation;
27 class Compositor; 30 class Compositor;
28 class Texture; 31 class Texture;
29 32
30 // Layer manages a texture, transform and a set of child Layers. Any View that 33 // Layer manages a texture, transform and a set of child Layers. Any View that
31 // has enabled layers ends up creating a Layer to manage the texture. 34 // has enabled layers ends up creating a Layer to manage the texture.
32 // A Layer can also be created without a texture, in which case it renders 35 // A Layer can also be created without a texture, in which case it renders
33 // nothing and is simply used as a node in a hierarchy of layers. 36 // nothing and is simply used as a node in a hierarchy of layers.
34 // 37 //
35 // NOTE: unlike Views, each Layer does *not* own its children views. If you 38 // NOTE: unlike Views, each Layer does *not* own its children views. If you
36 // delete a Layer and it has children, the parent of each child layer is set to 39 // delete a Layer and it has children, the parent of each child layer is set to
37 // NULL, but the children are not deleted. 40 // NULL, but the children are not deleted.
38 class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate { 41 class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate,
42 public WebKit::WebLayerClient,
43 public WebKit::WebContentLayerClient {
39 public: 44 public:
40 enum LayerType { 45 enum LayerType {
41 LAYER_HAS_NO_TEXTURE = 0, 46 LAYER_HAS_NO_TEXTURE = 0,
42 LAYER_HAS_TEXTURE = 1 47 LAYER_HAS_TEXTURE = 1
43 }; 48 };
44 49
45 // |compositor| can be NULL, and will be set later when the Layer is added to 50 // |compositor| can be NULL, and will be set later when the Layer is added to
46 // a Compositor. 51 // a Compositor.
47 explicit Layer(Compositor* compositor); 52 explicit Layer(Compositor* compositor);
48 Layer(Compositor* compositor, LayerType type); 53 Layer(Compositor* compositor, LayerType type);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Sets the visibility of the Layer. A Layer may be visible but not 110 // Sets the visibility of the Layer. A Layer may be visible but not
106 // drawn. This happens if any ancestor of a Layer is not visible. 111 // drawn. This happens if any ancestor of a Layer is not visible.
107 void SetVisible(bool visible); 112 void SetVisible(bool visible);
108 113
109 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors 114 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors
110 // are visible. 115 // are visible.
111 bool IsDrawn() const; 116 bool IsDrawn() const;
112 117
113 // Returns true if this layer can have a texture (has_texture_ is true) 118 // Returns true if this layer can have a texture (has_texture_ is true)
114 // and is not completely obscured by a child. 119 // and is not completely obscured by a child.
115 bool ShouldDraw(); 120 bool ShouldDraw() const;
116 121
117 // Converts a point from the coordinates of |source| to the coordinates of 122 // Converts a point from the coordinates of |source| to the coordinates of
118 // |target|. Necessarily, |source| and |target| must inhabit the same Layer 123 // |target|. Necessarily, |source| and |target| must inhabit the same Layer
119 // tree. 124 // tree.
120 static void ConvertPointToLayer(const Layer* source, 125 static void ConvertPointToLayer(const Layer* source,
121 const Layer* target, 126 const Layer* target,
122 gfx::Point* point); 127 gfx::Point* point);
123 128
124 // See description in View for details 129 // See description in View for details
125 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); 130 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely);
(...skipping 27 matching lines...) Expand all
153 void Draw(); 158 void Draw();
154 159
155 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting 160 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting
156 // with the receiver. 161 // with the receiver.
157 void DrawTree(); 162 void DrawTree();
158 163
159 // Sometimes the Layer is being updated by something other than SetCanvas 164 // Sometimes the Layer is being updated by something other than SetCanvas
160 // (e.g. the GPU process on TOUCH_UI). 165 // (e.g. the GPU process on TOUCH_UI).
161 bool layer_updated_externally() const { return layer_updated_externally_; } 166 bool layer_updated_externally() const { return layer_updated_externally_; }
162 167
168 // WebLayerClient
169 virtual void notifyNeedsComposite();
170
171 // WebContentLayerClient
172 virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip);
173
174 WebKit::WebContentLayer web_layer() { return web_layer_; }
175
163 private: 176 private:
164 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than 177 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than
165 // 1.0, we'll render to a separate texture, and then apply the alpha. 178 // 1.0, we'll render to a separate texture, and then apply the alpha.
166 // Currently, we multiply our opacity by all our ancestor's opacities and 179 // Currently, we multiply our opacity by all our ancestor's opacities and
167 // use the combined result, but this is only temporary. 180 // use the combined result, but this is only temporary.
168 float GetCombinedOpacity() const; 181 float GetCombinedOpacity() const;
169 182
170 // Called during the Draw() pass to freshen the Layer's contents from the 183 // Called during the Draw() pass to freshen the Layer's contents from the
171 // delegate. 184 // delegate.
172 void UpdateLayerCanvas(); 185 void UpdateLayerCanvas();
173 186
174 // A hole in a layer is an area in the layer that does not get drawn 187 // A hole in a layer is an area in the layer that does not get drawn
175 // because this area is covered up with another layer which is known to be 188 // because this area is covered up with another layer which is known to be
176 // opaque. 189 // opaque.
177 // This method computes the dimension of the hole (if there is one) 190 // This method computes the dimension of the hole (if there is one)
178 // based on whether one of its child nodes is always opaque. 191 // based on whether one of its child nodes is always opaque.
179 // Note: For simplicity's sake, currently a hole is only created if the child 192 // Note: For simplicity's sake, currently a hole is only created if the child
180 // view has no transform with respect to its parent. 193 // view has no transform with respect to its parent.
181 void RecomputeHole(); 194 void RecomputeHole();
182 195
196 void RecomputeTransform();
197 void RecomputeDrawsContent();
198
183 // Returns true if the layer paints every pixel (fills_bounds_opaquely) 199 // Returns true if the layer paints every pixel (fills_bounds_opaquely)
184 // and the alpha of the layer is 1.0f. 200 // and the alpha of the layer is 1.0f.
185 bool IsCompletelyOpaque() const; 201 bool IsCompletelyOpaque() const;
186 202
187 // Determines the regions that don't intersect |rect| and places the 203 // Determines the regions that don't intersect |rect| and places the
188 // result in |sides|. 204 // result in |sides|.
189 // 205 //
190 // rect_____________________________ 206 // rect_____________________________
191 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| 207 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
192 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx| 208 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx|
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // update the values immediately. 243 // update the values immediately.
228 void SetBoundsImmediately(const gfx::Rect& bounds); 244 void SetBoundsImmediately(const gfx::Rect& bounds);
229 void SetTransformImmediately(const ui::Transform& transform); 245 void SetTransformImmediately(const ui::Transform& transform);
230 void SetOpacityImmediately(float opacity); 246 void SetOpacityImmediately(float opacity);
231 247
232 // LayerAnimatorDelegate overrides: 248 // LayerAnimatorDelegate overrides:
233 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; 249 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE;
234 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; 250 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE;
235 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; 251 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE;
236 252
253 void CreateWebLayer();
254
237 const LayerType type_; 255 const LayerType type_;
238 256
239 Compositor* compositor_; 257 Compositor* compositor_;
240 258
241 scoped_refptr<ui::Texture> texture_; 259 scoped_refptr<ui::Texture> texture_;
242 260
243 Layer* parent_; 261 Layer* parent_;
244 262
245 std::vector<Layer*> children_; 263 std::vector<Layer*> children_;
246 264
(...skipping 12 matching lines...) Expand all
259 277
260 // If true the layer is always up to date. 278 // If true the layer is always up to date.
261 bool layer_updated_externally_; 279 bool layer_updated_externally_;
262 280
263 float opacity_; 281 float opacity_;
264 282
265 LayerDelegate* delegate_; 283 LayerDelegate* delegate_;
266 284
267 scoped_ptr<LayerAnimator> animator_; 285 scoped_ptr<LayerAnimator> animator_;
268 286
287 WebKit::WebContentLayer web_layer_;
288
269 DISALLOW_COPY_AND_ASSIGN(Layer); 289 DISALLOW_COPY_AND_ASSIGN(Layer);
270 }; 290 };
271 291
272 } // namespace ui 292 } // namespace ui
273 293
274 #endif // UI_GFX_COMPOSITOR_LAYER_H_ 294 #endif // UI_GFX_COMPOSITOR_LAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698