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

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

Powered by Google App Engine
This is Rietveld 408576698