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

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_mac.h

Issue 10917307: Implement asynchronous operation for RWHVP::CopyFromCompositingSurface on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mazda comments Created 8 years, 3 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 CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
6 #define CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 6 #define CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #import <QuartzCore/CVDisplayLink.h> 9 #import <QuartzCore/CVDisplayLink.h>
10 #include <QuartzCore/QuartzCore.h> 10 #include <QuartzCore/QuartzCore.h>
11 11
12 #include "base/callback.h"
12 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
13 #include "base/memory/scoped_nsobject.h" 14 #include "base/memory/scoped_nsobject.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "base/time.h" 16 #include "base/time.h"
16 #include "base/timer.h" 17 #include "base/timer.h"
17 #include "ui/gfx/native_widget_types.h" 18 #include "ui/gfx/native_widget_types.h"
19 #include "ui/gfx/rect.h"
18 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
19 21
20 class IOSurfaceSupport; 22 class IOSurfaceSupport;
21 23
22 namespace gfx { 24 namespace gfx {
23 class Rect; 25 class Rect;
24 } 26 }
25 27
26 namespace content { 28 namespace content {
27 29
(...skipping 13 matching lines...) Expand all
41 // Blit the IOSurface at the upper-left corner of the |view|. If |view| window 43 // Blit the IOSurface at the upper-left corner of the |view|. If |view| window
42 // size is larger than the IOSurface, the remaining right and bottom edges 44 // size is larger than the IOSurface, the remaining right and bottom edges
43 // will be white. |scaleFactor| is 1 in normal views, 2 in HiDPI views. 45 // will be white. |scaleFactor| is 1 in normal views, 2 in HiDPI views.
44 void DrawIOSurface(NSView* view, float scale_factor); 46 void DrawIOSurface(NSView* view, float scale_factor);
45 47
46 // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef 48 // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef
47 // into |out|. The copied region is specified with |src_pixel_subrect| and 49 // into |out|. The copied region is specified with |src_pixel_subrect| and
48 // the data is transformed so that it fits in |dst_pixel_size|. 50 // the data is transformed so that it fits in |dst_pixel_size|.
49 // |src_pixel_subrect| and |dst_pixel_size| are not in DIP but in pixel. 51 // |src_pixel_subrect| and |dst_pixel_size| are not in DIP but in pixel.
50 // Caller must ensure that |out| is allocated with the size no less than 52 // Caller must ensure that |out| is allocated with the size no less than
51 // |4 * dst_pixel_size.width() * dst_pixel_size.height()| bytes. 53 // |4 * dst_pixel_size.width() * dst_pixel_size.height()| bytes.
Nico 2012/09/22 11:12:21 Describe |callback|, mention that only one callbac
52 bool CopyTo(const gfx::Rect& src_pixel_subrect, 54 void CopyTo(const gfx::Rect& src_pixel_subrect,
53 const gfx::Size& dst_pixel_size, 55 const gfx::Size& dst_pixel_size,
54 void* out); 56 void* out,
57 const base::Callback<void(bool)>& callback);
55 58
56 // Unref the IOSurface and delete the associated GL texture. If the GPU 59 // Unref the IOSurface and delete the associated GL texture. If the GPU
57 // process is no longer referencing it, this will delete the IOSurface. 60 // process is no longer referencing it, this will delete the IOSurface.
58 void UnrefIOSurface(); 61 void UnrefIOSurface();
59 62
60 // Call when globalFrameDidChange is received on the NSView. 63 // Call when globalFrameDidChange is received on the NSView.
61 void GlobalFrameDidChange(); 64 void GlobalFrameDidChange();
62 65
63 // Disassociate the GL context with the NSView and unref the IOSurface. Do 66 // Disassociate the GL context with the NSView and unref the IOSurface. Do
64 // this to switch to software drawing mode. 67 // this to switch to software drawing mode.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Texture coordinates are flipped vertically so they can be drawn on 139 // Texture coordinates are flipped vertically so they can be drawn on
137 // a projection with a flipped y-axis (origin is top left). 140 // a projection with a flipped y-axis (origin is top left).
138 verts_[0].set_texcoord(tx1, ty2); 141 verts_[0].set_texcoord(tx1, ty2);
139 verts_[1].set_texcoord(tx1, ty1); 142 verts_[1].set_texcoord(tx1, ty1);
140 verts_[2].set_texcoord(tx2, ty1); 143 verts_[2].set_texcoord(tx2, ty1);
141 verts_[3].set_texcoord(tx2, ty2); 144 verts_[3].set_texcoord(tx2, ty2);
142 } 145 }
143 SurfaceVertex verts_[4]; 146 SurfaceVertex verts_[4];
144 }; 147 };
145 148
149 // Keeps track of states and buffers for asynchronous readback of IOSurface.
150 struct CopyContext {
151 CopyContext();
152 ~CopyContext();
153
154 void Reset() {
155 started = false;
156 cycles_elapsed = 0;
157 frame_buffer = 0;
158 frame_buffer_texture = 0;
159 pixel_buffer = 0;
160 use_fence = false;
161 fence = 0;
Nico 2012/09/22 11:12:21 you're not setting src_rect and dest_size to their
162 out_buf = NULL;
163 callback.Reset();
164 }
165
166 bool started;
167 int cycles_elapsed;
168 GLuint frame_buffer;
169 GLuint frame_buffer_texture;
170 GLuint pixel_buffer;
171 bool use_fence;
172 GLuint fence;
173 gfx::Rect src_rect;
174 gfx::Size dest_size;
175 void* out_buf;
176 base::Callback<void(bool)> callback;
177 };
178
146 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support, 179 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support,
147 NSOpenGLContext* glContext, 180 NSOpenGLContext* glContext,
148 CGLContextObj cglContext, 181 CGLContextObj cglContext,
149 GLuint shader_program_blit_rgb, 182 GLuint shader_program_blit_rgb,
150 GLint blit_rgb_sampler_location, 183 GLint blit_rgb_sampler_location,
151 GLuint shader_program_white, 184 GLuint shader_program_white,
152 bool is_vsync_disabled, 185 bool is_vsync_disabled,
153 CVDisplayLinkRef display_link); 186 CVDisplayLinkRef display_link);
154 187
155 // Returns true if IOSurface is ready to render. False otherwise. 188 // Returns true if IOSurface is ready to render. False otherwise.
156 bool MapIOSurfaceToTexture(uint64 io_surface_handle); 189 bool MapIOSurfaceToTexture(uint64 io_surface_handle);
157 190
158 void UnrefIOSurfaceWithContextCurrent(); 191 void UnrefIOSurfaceWithContextCurrent();
159 192
160 void DrawQuad(const SurfaceQuad& quad); 193 void DrawQuad(const SurfaceQuad& quad);
161 194
162 // Called on display-link thread. 195 // Called on display-link thread.
163 void DisplayLinkTick(CVDisplayLinkRef display_link, 196 void DisplayLinkTick(CVDisplayLinkRef display_link,
164 const CVTimeStamp* time); 197 const CVTimeStamp* time);
165 198
166 void CalculateVsyncParametersLockHeld(const CVTimeStamp* time); 199 void CalculateVsyncParametersLockHeld(const CVTimeStamp* time);
167 200
168 // Prevent from spinning on CGLFlushDrawable when it fails to throttle to 201 // Prevent from spinning on CGLFlushDrawable when it fails to throttle to
169 // VSync frequency. 202 // VSync frequency.
170 void RateLimitDraws(); 203 void RateLimitDraws();
171 204
172 void StartOrContinueDisplayLink(); 205 void StartOrContinueDisplayLink();
173 void StopDisplayLink(); 206 void StopDisplayLink();
174 207
208 void FinishCopy();
209 void CleanupResourcesForCopy();
210
175 // Cached pointer to IOSurfaceSupport Singleton. 211 // Cached pointer to IOSurfaceSupport Singleton.
176 IOSurfaceSupport* io_surface_support_; 212 IOSurfaceSupport* io_surface_support_;
177 213
178 // GL context 214 // GL context
179 scoped_nsobject<NSOpenGLContext> glContext_; 215 scoped_nsobject<NSOpenGLContext> glContext_;
180 CGLContextObj cglContext_; // weak, backed by |glContext_|. 216 CGLContextObj cglContext_; // weak, backed by |glContext_|.
181 217
182 // IOSurface data. 218 // IOSurface data.
183 uint64 io_surface_handle_; 219 uint64 io_surface_handle_;
184 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; 220 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_;
185 221
186 // The width and height of the io surface. 222 // The width and height of the io surface.
187 gfx::Size pixel_io_surface_size_; // In pixels. 223 gfx::Size pixel_io_surface_size_; // In pixels.
188 gfx::Size io_surface_size_; // In view units. 224 gfx::Size io_surface_size_; // In view units.
189 225
190 // The "live" OpenGL texture referring to this IOSurfaceRef. Note 226 // The "live" OpenGL texture referring to this IOSurfaceRef. Note
191 // that per the CGLTexImageIOSurface2D API we do not need to 227 // that per the CGLTexImageIOSurface2D API we do not need to
192 // explicitly update this texture's contents once created. All we 228 // explicitly update this texture's contents once created. All we
193 // need to do is ensure it is re-bound before attempting to draw 229 // need to do is ensure it is re-bound before attempting to draw
194 // with it. 230 // with it.
195 GLuint texture_; 231 GLuint texture_;
196 232
233 CopyContext copy_context_;
234
235 // Timer for finishing a copy operation.
236 base::RepeatingTimer<CompositingIOSurfaceMac> copy_timer_;
237
197 // Shader parameters. 238 // Shader parameters.
198 GLuint shader_program_blit_rgb_; 239 GLuint shader_program_blit_rgb_;
199 GLint blit_rgb_sampler_location_; 240 GLint blit_rgb_sampler_location_;
200 GLuint shader_program_white_; 241 GLuint shader_program_white_;
201 242
202 SurfaceQuad quad_; 243 SurfaceQuad quad_;
203 244
204 bool is_vsync_disabled_; 245 bool is_vsync_disabled_;
205 246
206 // CVDisplayLink for querying Vsync timing info and throttling swaps. 247 // CVDisplayLink for querying Vsync timing info and throttling swaps.
(...skipping 11 matching lines...) Expand all
218 259
219 // Vsync timing data. 260 // Vsync timing data.
220 base::TimeTicks vsync_timebase_; 261 base::TimeTicks vsync_timebase_;
221 uint32 vsync_interval_numerator_; 262 uint32 vsync_interval_numerator_;
222 uint32 vsync_interval_denominator_; 263 uint32 vsync_interval_denominator_;
223 }; 264 };
224 265
225 } // namespace content 266 } // namespace content
226 267
227 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 268 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698