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

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

Issue 10221028: Move DIP translation from ui/aura to ui/compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove dip from gyp Created 8 years, 7 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) 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_COMPOSITOR_H_ 5 #ifndef UI_GFX_COMPOSITOR_COMPOSITOR_H_
6 #define UI_GFX_COMPOSITOR_COMPOSITOR_H_ 6 #define UI_GFX_COMPOSITOR_COMPOSITOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 gfx::Size size() const { return size_; } 104 gfx::Size size() const { return size_; }
105 105
106 protected: 106 protected:
107 virtual ~Texture(); 107 virtual ~Texture();
108 108
109 private: 109 private:
110 friend class base::RefCounted<Texture>; 110 friend class base::RefCounted<Texture>;
111 111
112 unsigned int texture_id_; 112 unsigned int texture_id_;
113 bool flipped_; 113 bool flipped_;
114 gfx::Size size_; 114 gfx::Size size_; // in pixel
115 115
116 DISALLOW_COPY_AND_ASSIGN(Texture); 116 DISALLOW_COPY_AND_ASSIGN(Texture);
117 }; 117 };
118 118
119 // An interface to allow the compositor to communicate with its owner. 119 // An interface to allow the compositor to communicate with its owner.
120 class COMPOSITOR_EXPORT CompositorDelegate { 120 class COMPOSITOR_EXPORT CompositorDelegate {
121 public: 121 public:
122 // Requests the owner to schedule a redraw of the layer tree. 122 // Requests the owner to schedule a redraw of the layer tree.
123 virtual void ScheduleDraw() = 0; 123 virtual void ScheduleDraw() = 0;
124 124
125 protected: 125 protected:
126 virtual ~CompositorDelegate() {} 126 virtual ~CompositorDelegate() {}
127 }; 127 };
128 128
129 // Compositor object to take care of GPU painting. 129 // Compositor object to take care of GPU painting.
130 // A Browser compositor object is responsible for generating the final 130 // A Browser compositor object is responsible for generating the final
131 // displayable form of pixels comprising a single widget's contents. It draws an 131 // displayable form of pixels comprising a single widget's contents. It draws an
132 // appropriately transformed texture for each transformed view in the widget's 132 // appropriately transformed texture for each transformed view in the widget's
133 // view hierarchy. 133 // view hierarchy.
134 class COMPOSITOR_EXPORT Compositor 134 class COMPOSITOR_EXPORT Compositor
135 : NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) { 135 : NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) {
136 public: 136 public:
137 Compositor(CompositorDelegate* delegate, 137 Compositor(CompositorDelegate* delegate,
138 gfx::AcceleratedWidget widget, 138 gfx::AcceleratedWidget widget);
139 const gfx::Size& size);
140 virtual ~Compositor(); 139 virtual ~Compositor();
141 140
142 static void Initialize(bool useThread); 141 static void Initialize(bool useThread);
143 static void Terminate(); 142 static void Terminate();
144 143
145 // Schedules a redraw of the layer tree associated with this compositor. 144 // Schedules a redraw of the layer tree associated with this compositor.
146 void ScheduleDraw(); 145 void ScheduleDraw();
147 146
148 // Sets the root of the layer tree drawn by this Compositor. The root layer 147 // Sets the root of the layer tree drawn by this Compositor. The root layer
149 // must have no parent. The compositor's root layer is reset if the root layer 148 // must have no parent. The compositor's root layer is reset if the root layer
150 // is destroyed. NULL can be passed to reset the root layer, in which case the 149 // is destroyed. NULL can be passed to reset the root layer, in which case the
151 // compositor will stop drawing anything. 150 // compositor will stop drawing anything.
152 // The Compositor does not own the root layer. 151 // The Compositor does not own the root layer.
153 const Layer* root_layer() const { return root_layer_; } 152 const Layer* root_layer() const { return root_layer_; }
154 Layer* root_layer() { return root_layer_; } 153 Layer* root_layer() { return root_layer_; }
155 void SetRootLayer(Layer* root_layer); 154 void SetRootLayer(Layer* root_layer);
156 155
156 // The scale factor of the device that this compositor is
157 // compositing layers on.
158 float device_scale_factor() const { return device_scale_factor_; }
159
157 // Draws the scene created by the layer tree and any visual effects. If 160 // Draws the scene created by the layer tree and any visual effects. If
158 // |force_clear| is true, this will cause the compositor to clear before 161 // |force_clear| is true, this will cause the compositor to clear before
159 // compositing. 162 // compositing.
160 void Draw(bool force_clear); 163 void Draw(bool force_clear);
161 164
162 // Where possible, draws are scissored to a damage region calculated from 165 // Where possible, draws are scissored to a damage region calculated from
163 // changes to layer properties. This bypasses that and indicates that 166 // changes to layer properties. This bypasses that and indicates that
164 // the whole frame needs to be drawn. 167 // the whole frame needs to be drawn.
165 void ScheduleFullDraw(); 168 void ScheduleFullDraw();
166 169
167 // Reads the region |bounds| of the contents of the last rendered frame 170 // Reads the region |bounds_in_pixel| of the contents of the last rendered
168 // into the given bitmap. 171 // frame into the given bitmap.
169 // Returns false if the pixels could not be read. 172 // Returns false if the pixels could not be read.
170 bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds); 173 bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds_in_pixel);
171 174
172 // Notifies the compositor that the size of the widget that it is 175 // Notifies the compositor that the device scale factor and size of
173 // drawing to has changed. 176 // the widget that it is drawing to has changed.
174 void WidgetSizeChanged(const gfx::Size& size); 177 void WidgetScaleOrSizeChanged(float scale, const gfx::Size& size_in_pixel);
175 178
176 // Returns the size of the widget that is being drawn to. 179 // Returns the size of the widget that is being drawn to in pixel coordinates.
177 const gfx::Size& size() const { return size_; } 180 const gfx::Size& size() const { return size_; }
178 181
179 // Returns the widget for this compositor. 182 // Returns the widget for this compositor.
180 gfx::AcceleratedWidget widget() const { return widget_; } 183 gfx::AcceleratedWidget widget() const { return widget_; }
181 184
182 // Compositor does not own observers. It is the responsibility of the 185 // Compositor does not own observers. It is the responsibility of the
183 // observer to remove itself when it is done observing. 186 // observer to remove itself when it is done observing.
184 void AddObserver(CompositorObserver* observer); 187 void AddObserver(CompositorObserver* observer);
185 void RemoveObserver(CompositorObserver* observer); 188 void RemoveObserver(CompositorObserver* observer);
186 bool HasObserver(CompositorObserver* observer); 189 bool HasObserver(CompositorObserver* observer);
187 190
188 // Returns whether a draw is pending, that is, if we're between the Draw call 191 // Returns whether a draw is pending, that is, if we're between the Draw call
189 // and the OnCompositingEnded. 192 // and the OnCompositingEnded.
190 bool DrawPending() const { return swap_posted_; } 193 bool DrawPending() const { return swap_posted_; }
191 194
192 // Internal functions, called back by command-buffer contexts on swap buffer 195 // Internal functions, called back by command-buffer contexts on swap buffer
193 // events. 196 // events.
194 197
195 // Signals swap has been posted. 198 // Signals swap has been posted.
196 void OnSwapBuffersPosted(); 199 void OnSwapBuffersPosted();
197 200
198 // Signals swap has completed. 201 // Signals swap has completed.
199 void OnSwapBuffersComplete(); 202 void OnSwapBuffersComplete();
200 203
201 // Signals swap has aborted (e.g. lost context). 204 // Signals swap has aborted (e.g. lost context).
202 void OnSwapBuffersAborted(); 205 void OnSwapBuffersAborted();
203 206
207 // Translates |transform| with translate_offset, then apply the
208 // device scale factor to the all translate operations in the transform.
209 Transform GetTranslateTransform(const Transform& transform,
210 const gfx::Point& translate_offset);
211
204 // WebLayerTreeViewClient implementation. 212 // WebLayerTreeViewClient implementation.
205 virtual void updateAnimations(double frameBeginTime); 213 virtual void updateAnimations(double frameBeginTime);
206 virtual void layout(); 214 virtual void layout();
207 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta, 215 virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta,
208 float scaleFactor); 216 float scaleFactor);
209 virtual WebKit::WebGraphicsContext3D* createContext3D(); 217 virtual WebKit::WebGraphicsContext3D* createContext3D();
210 virtual void didRebindGraphicsContext(bool success); 218 virtual void didRebindGraphicsContext(bool success);
211 virtual void didCommitAndDrawFrame(); 219 virtual void didCommitAndDrawFrame();
212 virtual void didCompleteSwapBuffers(); 220 virtual void didCompleteSwapBuffers();
213 virtual void scheduleComposite(); 221 virtual void scheduleComposite();
(...skipping 16 matching lines...) Expand all
230 ObserverList<CompositorObserver> observer_list_; 238 ObserverList<CompositorObserver> observer_list_;
231 239
232 gfx::AcceleratedWidget widget_; 240 gfx::AcceleratedWidget widget_;
233 WebKit::WebLayer root_web_layer_; 241 WebKit::WebLayer root_web_layer_;
234 WebKit::WebLayerTreeView host_; 242 WebKit::WebLayerTreeView host_;
235 243
236 // This is set to true when the swap buffers has been posted and we're waiting 244 // This is set to true when the swap buffers has been posted and we're waiting
237 // for completion. 245 // for completion.
238 bool swap_posted_; 246 bool swap_posted_;
239 247
248 float device_scale_factor_;
249
250 // Transforms to scale the translation in |transform_|.
251 Transform scale_translate_;
252 Transform invese_scale_translate_;
piman 2012/05/04 18:46:06 nit: invese->inverse
253
240 friend class base::RefCounted<Compositor>; 254 friend class base::RefCounted<Compositor>;
241 }; 255 };
242 256
243 } // namespace ui 257 } // namespace ui
244 258
245 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_ 259 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698