| OLD | NEW |
| 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 CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #import <Cocoa/Cocoa.h> | 11 #import <Cocoa/Cocoa.h> |
| 11 #import <QuartzCore/CVDisplayLink.h> | 12 #import <QuartzCore/CVDisplayLink.h> |
| 12 #include <QuartzCore/QuartzCore.h> | 13 #include <QuartzCore/QuartzCore.h> |
| 13 | 14 |
| 14 #include "base/callback.h" | 15 #include "base/callback.h" |
| 15 #include "base/mac/scoped_cftyperef.h" | 16 #include "base/mac/scoped_cftyperef.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 18 #include "base/time.h" | 19 #include "base/time.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // a projection with a flipped y-axis (origin is top left). | 182 // a projection with a flipped y-axis (origin is top left). |
| 182 verts_[0].set_texcoord(tx1, ty2); | 183 verts_[0].set_texcoord(tx1, ty2); |
| 183 verts_[1].set_texcoord(tx1, ty1); | 184 verts_[1].set_texcoord(tx1, ty1); |
| 184 verts_[2].set_texcoord(tx2, ty1); | 185 verts_[2].set_texcoord(tx2, ty1); |
| 185 verts_[3].set_texcoord(tx2, ty2); | 186 verts_[3].set_texcoord(tx2, ty2); |
| 186 } | 187 } |
| 187 SurfaceVertex verts_[4]; | 188 SurfaceVertex verts_[4]; |
| 188 }; | 189 }; |
| 189 | 190 |
| 190 // Keeps track of states and buffers for readback of IOSurface. | 191 // Keeps track of states and buffers for readback of IOSurface. |
| 192 // |
| 193 // TODO(miu): Major code refactoring is badly needed! To be done in a |
| 194 // soon-upcoming change. For now, we blatantly violate the style guide with |
| 195 // respect to struct vs. class usage: |
| 191 struct CopyContext { | 196 struct CopyContext { |
| 192 CopyContext(); | 197 explicit CopyContext(const scoped_refptr<CompositingIOSurfaceContext>& ctx); |
| 193 ~CopyContext(); | 198 ~CopyContext(); |
| 194 void CleanUp(); | |
| 195 | 199 |
| 200 // Delete any references to owned OpenGL objects. This must be called |
| 201 // within the OpenGL context just before destruction. |
| 202 void ReleaseCachedGLObjects(); |
| 203 |
| 204 // The following two methods assume |num_outputs| has been set, and are |
| 205 // being called within the OpenGL context. |
| 206 void PrepareReadbackFramebuffers(); |
| 207 void PrepareForAsynchronousReadback(); |
| 208 |
| 209 const scoped_ptr<CompositingIOSurfaceTransformer> transformer; |
| 196 int num_outputs; | 210 int num_outputs; |
| 197 GLuint output_textures[3]; | 211 GLuint output_textures[3]; // Not owned. |
| 198 // Note: For YUV, the |output_texture_sizes| widths are in terms of 4-byte | 212 // Note: For YUV, the |output_texture_sizes| widths are in terms of 4-byte |
| 199 // quads, not pixels. | 213 // quads, not pixels. |
| 200 gfx::Size output_texture_sizes[3]; | 214 gfx::Size output_texture_sizes[3]; |
| 201 GLuint frame_buffers[3]; | 215 GLuint frame_buffers[3]; |
| 202 GLuint pixel_buffers[3]; | 216 GLuint pixel_buffers[3]; |
| 203 GLuint fence; // When non-zero, doing an asynchronous copy. | 217 GLuint fence; // When non-zero, doing an asynchronous copy. |
| 204 int cycles_elapsed; | 218 int cycles_elapsed; |
| 205 base::Callback<bool(const void*, int)> map_buffer_callback; | 219 base::Callback<bool(const void*, int)> map_buffer_callback; |
| 206 base::Callback<void(bool)> done_callback; | 220 base::Callback<void(bool)> done_callback; |
| 207 }; | 221 }; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 CopyContext* copy_context, | 288 CopyContext* copy_context, |
| 275 const SkBitmap* bitmap_output, | 289 const SkBitmap* bitmap_output, |
| 276 const scoped_refptr<media::VideoFrame>& video_frame_output); | 290 const scoped_refptr<media::VideoFrame>& video_frame_output); |
| 277 | 291 |
| 278 // Scan the list of started asynchronous copies and test if each one has | 292 // Scan the list of started asynchronous copies and test if each one has |
| 279 // completed. | 293 // completed. |
| 280 void FinishAllCopies(); | 294 void FinishAllCopies(); |
| 281 void FinishAllCopiesWithinContext( | 295 void FinishAllCopiesWithinContext( |
| 282 std::vector<base::Closure>* done_callbacks); | 296 std::vector<base::Closure>* done_callbacks); |
| 283 | 297 |
| 284 void CleanupAllCopiesWithinContext(); | |
| 285 void FailAllCopies(); | 298 void FailAllCopies(); |
| 299 void DestroyAllCopyContextsWithinContext(); |
| 286 | 300 |
| 287 gfx::Rect IntersectWithIOSurface(const gfx::Rect& rect, | 301 gfx::Rect IntersectWithIOSurface(const gfx::Rect& rect, |
| 288 float scale_factor) const; | 302 float scale_factor) const; |
| 289 | 303 |
| 290 // Cached pointer to IOSurfaceSupport Singleton. | 304 // Cached pointer to IOSurfaceSupport Singleton. |
| 291 IOSurfaceSupport* io_surface_support_; | 305 IOSurfaceSupport* io_surface_support_; |
| 292 | 306 |
| 293 // GL context, and parameters for context sharing. This may change when | 307 // GL context, and parameters for context sharing. This may change when |
| 294 // moving between windows, but will never be NULL. | 308 // moving between windows, but will never be NULL. |
| 295 scoped_refptr<CompositingIOSurfaceContext> context_; | 309 scoped_refptr<CompositingIOSurfaceContext> context_; |
| 296 | 310 |
| 297 // IOSurface data. | 311 // IOSurface data. |
| 298 uint64 io_surface_handle_; | 312 uint64 io_surface_handle_; |
| 299 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; | 313 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; |
| 300 | 314 |
| 301 // The width and height of the io surface. | 315 // The width and height of the io surface. |
| 302 gfx::Size pixel_io_surface_size_; // In pixels. | 316 gfx::Size pixel_io_surface_size_; // In pixels. |
| 303 gfx::Size io_surface_size_; // In view units. | 317 gfx::Size io_surface_size_; // In view units. |
| 304 | 318 |
| 305 // The "live" OpenGL texture referring to this IOSurfaceRef. Note | 319 // The "live" OpenGL texture referring to this IOSurfaceRef. Note |
| 306 // that per the CGLTexImageIOSurface2D API we do not need to | 320 // that per the CGLTexImageIOSurface2D API we do not need to |
| 307 // explicitly update this texture's contents once created. All we | 321 // explicitly update this texture's contents once created. All we |
| 308 // need to do is ensure it is re-bound before attempting to draw | 322 // need to do is ensure it is re-bound before attempting to draw |
| 309 // with it. | 323 // with it. |
| 310 GLuint texture_; | 324 GLuint texture_; |
| 311 | 325 |
| 312 std::deque<CopyContext> copy_requests_; | 326 // A pool of CopyContexts with OpenGL objects ready for re-use. Prefer to |
| 327 // pull one from the pool before creating a new CopyContext. |
| 328 std::vector<CopyContext*> copy_context_pool_; |
| 329 |
| 330 // CopyContexts being used for in-flight copy operations. |
| 331 std::deque<CopyContext*> copy_requests_; |
| 313 | 332 |
| 314 // Timer for finishing a copy operation. | 333 // Timer for finishing a copy operation. |
| 315 base::Timer finish_copy_timer_; | 334 base::Timer finish_copy_timer_; |
| 316 | 335 |
| 317 scoped_ptr<CompositingIOSurfaceTransformer> transformer_; | |
| 318 | |
| 319 SurfaceQuad quad_; | 336 SurfaceQuad quad_; |
| 320 | 337 |
| 321 // CVDisplayLink for querying Vsync timing info and throttling swaps. | 338 // CVDisplayLink for querying Vsync timing info and throttling swaps. |
| 322 CVDisplayLinkRef display_link_; | 339 CVDisplayLinkRef display_link_; |
| 323 | 340 |
| 324 // Timer for stopping display link after a timeout with no swaps. | 341 // Timer for stopping display link after a timeout with no swaps. |
| 325 base::DelayTimer<CompositingIOSurfaceMac> display_link_stop_timer_; | 342 base::DelayTimer<CompositingIOSurfaceMac> display_link_stop_timer_; |
| 326 | 343 |
| 327 // Lock for sharing data between UI thread and display-link thread. | 344 // Lock for sharing data between UI thread and display-link thread. |
| 328 base::Lock lock_; | 345 base::Lock lock_; |
| 329 | 346 |
| 330 // Counts for throttling swaps. | 347 // Counts for throttling swaps. |
| 331 int64 vsync_count_; | 348 int64 vsync_count_; |
| 332 int64 swap_count_; | 349 int64 swap_count_; |
| 333 | 350 |
| 334 // Vsync timing data. | 351 // Vsync timing data. |
| 335 base::TimeTicks vsync_timebase_; | 352 base::TimeTicks vsync_timebase_; |
| 336 uint32 vsync_interval_numerator_; | 353 uint32 vsync_interval_numerator_; |
| 337 uint32 vsync_interval_denominator_; | 354 uint32 vsync_interval_denominator_; |
| 338 | 355 |
| 339 bool initialized_is_intel_; | 356 bool initialized_is_intel_; |
| 340 bool is_intel_; | 357 bool is_intel_; |
| 341 GLint screen_; | 358 GLint screen_; |
| 342 }; | 359 }; |
| 343 | 360 |
| 344 } // namespace content | 361 } // namespace content |
| 345 | 362 |
| 346 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ | 363 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_MAC_H_ |
| OLD | NEW |