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

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: fixed 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
« no previous file with comments | « no previous file | content/browser/renderer_host/compositing_iosurface_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
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.
52 bool CopyTo(const gfx::Rect& src_pixel_subrect, 54 // |callback| is invoked when the operation is completed or failed.
55 // Do no call this method again before |callback| is invoked.
56 void CopyTo(const gfx::Rect& src_pixel_subrect,
53 const gfx::Size& dst_pixel_size, 57 const gfx::Size& dst_pixel_size,
54 void* out); 58 void* out,
59 const base::Callback<void(bool)>& callback);
55 60
56 // Unref the IOSurface and delete the associated GL texture. If the GPU 61 // Unref the IOSurface and delete the associated GL texture. If the GPU
57 // process is no longer referencing it, this will delete the IOSurface. 62 // process is no longer referencing it, this will delete the IOSurface.
58 void UnrefIOSurface(); 63 void UnrefIOSurface();
59 64
60 // Call when globalFrameDidChange is received on the NSView. 65 // Call when globalFrameDidChange is received on the NSView.
61 void GlobalFrameDidChange(); 66 void GlobalFrameDidChange();
62 67
63 // Disassociate the GL context with the NSView and unref the IOSurface. Do 68 // Disassociate the GL context with the NSView and unref the IOSurface. Do
64 // this to switch to software drawing mode. 69 // 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 141 // Texture coordinates are flipped vertically so they can be drawn on
137 // a projection with a flipped y-axis (origin is top left). 142 // a projection with a flipped y-axis (origin is top left).
138 verts_[0].set_texcoord(tx1, ty2); 143 verts_[0].set_texcoord(tx1, ty2);
139 verts_[1].set_texcoord(tx1, ty1); 144 verts_[1].set_texcoord(tx1, ty1);
140 verts_[2].set_texcoord(tx2, ty1); 145 verts_[2].set_texcoord(tx2, ty1);
141 verts_[3].set_texcoord(tx2, ty2); 146 verts_[3].set_texcoord(tx2, ty2);
142 } 147 }
143 SurfaceVertex verts_[4]; 148 SurfaceVertex verts_[4];
144 }; 149 };
145 150
151 // Keeps track of states and buffers for asynchronous readback of IOSurface.
152 struct CopyContext {
153 CopyContext();
154 ~CopyContext();
155
156 void Reset() {
157 started = false;
158 cycles_elapsed = 0;
159 frame_buffer = 0;
160 frame_buffer_texture = 0;
161 pixel_buffer = 0;
162 use_fence = false;
163 fence = 0;
164 out_buf = NULL;
165 callback.Reset();
166 }
167
168 bool started;
169 int cycles_elapsed;
170 GLuint frame_buffer;
171 GLuint frame_buffer_texture;
172 GLuint pixel_buffer;
173 bool use_fence;
174 GLuint fence;
175 gfx::Rect src_rect;
176 gfx::Size dest_size;
177 void* out_buf;
178 base::Callback<void(bool)> callback;
179 };
180
146 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support, 181 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support,
147 NSOpenGLContext* glContext, 182 NSOpenGLContext* glContext,
148 CGLContextObj cglContext, 183 CGLContextObj cglContext,
149 GLuint shader_program_blit_rgb, 184 GLuint shader_program_blit_rgb,
150 GLint blit_rgb_sampler_location, 185 GLint blit_rgb_sampler_location,
151 GLuint shader_program_white, 186 GLuint shader_program_white,
152 bool is_vsync_disabled, 187 bool is_vsync_disabled,
153 CVDisplayLinkRef display_link); 188 CVDisplayLinkRef display_link);
154 189
155 // Returns true if IOSurface is ready to render. False otherwise. 190 // Returns true if IOSurface is ready to render. False otherwise.
156 bool MapIOSurfaceToTexture(uint64 io_surface_handle); 191 bool MapIOSurfaceToTexture(uint64 io_surface_handle);
157 192
158 void UnrefIOSurfaceWithContextCurrent(); 193 void UnrefIOSurfaceWithContextCurrent();
159 194
160 void DrawQuad(const SurfaceQuad& quad); 195 void DrawQuad(const SurfaceQuad& quad);
161 196
162 // Called on display-link thread. 197 // Called on display-link thread.
163 void DisplayLinkTick(CVDisplayLinkRef display_link, 198 void DisplayLinkTick(CVDisplayLinkRef display_link,
164 const CVTimeStamp* time); 199 const CVTimeStamp* time);
165 200
166 void CalculateVsyncParametersLockHeld(const CVTimeStamp* time); 201 void CalculateVsyncParametersLockHeld(const CVTimeStamp* time);
167 202
168 // Prevent from spinning on CGLFlushDrawable when it fails to throttle to 203 // Prevent from spinning on CGLFlushDrawable when it fails to throttle to
169 // VSync frequency. 204 // VSync frequency.
170 void RateLimitDraws(); 205 void RateLimitDraws();
171 206
172 void StartOrContinueDisplayLink(); 207 void StartOrContinueDisplayLink();
173 void StopDisplayLink(); 208 void StopDisplayLink();
174 209
210 void FinishCopy();
211 void CleanupResourcesForCopy();
212
175 // Cached pointer to IOSurfaceSupport Singleton. 213 // Cached pointer to IOSurfaceSupport Singleton.
176 IOSurfaceSupport* io_surface_support_; 214 IOSurfaceSupport* io_surface_support_;
177 215
178 // GL context 216 // GL context
179 scoped_nsobject<NSOpenGLContext> glContext_; 217 scoped_nsobject<NSOpenGLContext> glContext_;
180 CGLContextObj cglContext_; // weak, backed by |glContext_|. 218 CGLContextObj cglContext_; // weak, backed by |glContext_|.
181 219
182 // IOSurface data. 220 // IOSurface data.
183 uint64 io_surface_handle_; 221 uint64 io_surface_handle_;
184 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; 222 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_;
185 223
186 // The width and height of the io surface. 224 // The width and height of the io surface.
187 gfx::Size pixel_io_surface_size_; // In pixels. 225 gfx::Size pixel_io_surface_size_; // In pixels.
188 gfx::Size io_surface_size_; // In view units. 226 gfx::Size io_surface_size_; // In view units.
189 227
190 // The "live" OpenGL texture referring to this IOSurfaceRef. Note 228 // The "live" OpenGL texture referring to this IOSurfaceRef. Note
191 // that per the CGLTexImageIOSurface2D API we do not need to 229 // that per the CGLTexImageIOSurface2D API we do not need to
192 // explicitly update this texture's contents once created. All we 230 // explicitly update this texture's contents once created. All we
193 // need to do is ensure it is re-bound before attempting to draw 231 // need to do is ensure it is re-bound before attempting to draw
194 // with it. 232 // with it.
195 GLuint texture_; 233 GLuint texture_;
196 234
235 CopyContext copy_context_;
236
237 // Timer for finishing a copy operation.
238 base::RepeatingTimer<CompositingIOSurfaceMac> copy_timer_;
239
197 // Shader parameters. 240 // Shader parameters.
198 GLuint shader_program_blit_rgb_; 241 GLuint shader_program_blit_rgb_;
199 GLint blit_rgb_sampler_location_; 242 GLint blit_rgb_sampler_location_;
200 GLuint shader_program_white_; 243 GLuint shader_program_white_;
201 244
202 SurfaceQuad quad_; 245 SurfaceQuad quad_;
203 246
204 bool is_vsync_disabled_; 247 bool is_vsync_disabled_;
205 248
206 // CVDisplayLink for querying Vsync timing info and throttling swaps. 249 // CVDisplayLink for querying Vsync timing info and throttling swaps.
(...skipping 11 matching lines...) Expand all
218 261
219 // Vsync timing data. 262 // Vsync timing data.
220 base::TimeTicks vsync_timebase_; 263 base::TimeTicks vsync_timebase_;
221 uint32 vsync_interval_numerator_; 264 uint32 vsync_interval_numerator_;
222 uint32 vsync_interval_denominator_; 265 uint32 vsync_interval_denominator_;
223 }; 266 };
224 267
225 } // namespace content 268 } // namespace content
226 269
227 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 270 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/compositing_iosurface_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698