OLD | NEW |
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_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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const Layer* root_layer() const { return root_layer_; } | 122 const Layer* root_layer() const { return root_layer_; } |
123 Layer* root_layer() { return root_layer_; } | 123 Layer* root_layer() { return root_layer_; } |
124 void SetRootLayer(Layer* root_layer); | 124 void SetRootLayer(Layer* root_layer); |
125 | 125 |
126 // Draws the scene created by the layer tree and any visual effects. If | 126 // Draws the scene created by the layer tree and any visual effects. If |
127 // |force_clear| is true, this will cause the compositor to clear before | 127 // |force_clear| is true, this will cause the compositor to clear before |
128 // compositing. | 128 // compositing. |
129 void Draw(bool force_clear); | 129 void Draw(bool force_clear); |
130 | 130 |
131 // Reads the contents of the last rendered frame into the given bitmap. | 131 // Reads the contents of the last rendered frame into the given bitmap. |
132 virtual void ReadPixels(SkBitmap* bitmap) = 0; | 132 // Returns false if the pixels could not be read. |
| 133 virtual bool ReadPixels(SkBitmap* bitmap) = 0; |
133 | 134 |
134 // Notifies the compositor that the size of the widget that it is | 135 // Notifies the compositor that the size of the widget that it is |
135 // drawing to has changed. | 136 // drawing to has changed. |
136 void WidgetSizeChanged(const gfx::Size& size) { | 137 void WidgetSizeChanged(const gfx::Size& size) { |
137 if (size.IsEmpty()) | 138 if (size.IsEmpty()) |
138 return; | 139 return; |
139 size_ = size; | 140 size_ = size; |
140 OnWidgetSizeChanged(); | 141 OnWidgetSizeChanged(); |
141 } | 142 } |
142 | 143 |
(...skipping 25 matching lines...) Expand all Loading... |
168 | 169 |
169 // Notifies the compositor that compositing is complete. | 170 // Notifies the compositor that compositing is complete. |
170 virtual void OnNotifyEnd() = 0; | 171 virtual void OnNotifyEnd() = 0; |
171 | 172 |
172 virtual void OnWidgetSizeChanged() = 0; | 173 virtual void OnWidgetSizeChanged() = 0; |
173 virtual void OnRootLayerChanged(); | 174 virtual void OnRootLayerChanged(); |
174 virtual void DrawTree(); | 175 virtual void DrawTree(); |
175 | 176 |
176 CompositorDelegate* delegate() { return delegate_; } | 177 CompositorDelegate* delegate() { return delegate_; } |
177 | 178 |
| 179 // When reading back pixel data we often get RGBA rather than BGRA pixels and |
| 180 // and the image often needs to be flipped vertically. |
| 181 static void SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, |
| 182 const gfx::Size& image_size); |
| 183 |
178 private: | 184 private: |
179 // Notifies the compositor that compositing is about to start. See Draw() for | 185 // Notifies the compositor that compositing is about to start. See Draw() for |
180 // notes about |force_clear|. | 186 // notes about |force_clear|. |
181 void NotifyStart(bool force_clear); | 187 void NotifyStart(bool force_clear); |
182 | 188 |
183 // Notifies the compositor that compositing is complete. | 189 // Notifies the compositor that compositing is complete. |
184 void NotifyEnd(); | 190 void NotifyEnd(); |
185 | 191 |
186 CompositorDelegate* delegate_; | 192 CompositorDelegate* delegate_; |
187 gfx::Size size_; | 193 gfx::Size size_; |
188 | 194 |
189 // The root of the Layer tree drawn by this compositor. | 195 // The root of the Layer tree drawn by this compositor. |
190 Layer* root_layer_; | 196 Layer* root_layer_; |
191 | 197 |
192 ObserverList<CompositorObserver> observer_list_; | 198 ObserverList<CompositorObserver> observer_list_; |
193 | 199 |
194 // Factory used to create Compositors. Settable by tests. | 200 // Factory used to create Compositors. Settable by tests. |
195 // The delegate can be NULL if you don't wish to catch the ScheduleDraw() | 201 // The delegate can be NULL if you don't wish to catch the ScheduleDraw() |
196 // calls to it. | 202 // calls to it. |
197 static ui::Compositor*(*compositor_factory_)( | 203 static ui::Compositor*(*compositor_factory_)( |
198 ui::CompositorDelegate* delegate); | 204 ui::CompositorDelegate* delegate); |
199 | 205 |
200 friend class base::RefCounted<Compositor>; | 206 friend class base::RefCounted<Compositor>; |
201 }; | 207 }; |
202 | 208 |
203 } // namespace ui | 209 } // namespace ui |
204 | 210 |
205 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_ | 211 #endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |