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

Side by Side Diff: content/browser/compositor/io_surface_layer_mac.mm

Issue 625753002: IOSurface CGL context current lifetime cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 2 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
« no previous file with comments | « no previous file | content/browser/compositor/io_surface_texture_mac.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/browser/compositor/io_surface_layer_mac.h" 5 #include "content/browser/compositor/io_surface_layer_mac.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #include <OpenGL/CGLIOSurface.h> 8 #include <OpenGL/CGLIOSurface.h>
9 #include <OpenGL/CGLRenderers.h> 9 #include <OpenGL/CGLRenderers.h>
10 #include <OpenGL/gl.h> 10 #include <OpenGL/gl.h>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 DisplayIfNeededAndAck(); 161 DisplayIfNeededAndAck();
162 } 162 }
163 163
164 } // namespace content 164 } // namespace content
165 165
166 //////////////////////////////////////////////////////////////////////////////// 166 ////////////////////////////////////////////////////////////////////////////////
167 // IOSurfaceLayer 167 // IOSurfaceLayer
168 168
169 @implementation IOSurfaceLayer 169 @implementation IOSurfaceLayer
170 170
171 - (content::IOSurfaceTexture*)iosurface {
172 return iosurface_.get();
173 }
174
175 - (content::IOSurfaceContext*)context {
176 return context_.get();
177 }
178
179 - (id)initWithClient:(content::IOSurfaceLayerClient*)client 171 - (id)initWithClient:(content::IOSurfaceLayerClient*)client
180 withScaleFactor:(float)scale_factor { 172 withScaleFactor:(float)scale_factor {
181 if (self = [super init]) { 173 if (self = [super init]) {
182 helper_.reset(new content::IOSurfaceLayerHelper(client, self)); 174 helper_.reset(new content::IOSurfaceLayerHelper(client, self));
183 175
184 iosurface_ = content::IOSurfaceTexture::Create(); 176 iosurface_ = content::IOSurfaceTexture::Create();
185 context_ = content::IOSurfaceContext::Get( 177 context_ = content::IOSurfaceContext::Get(
186 content::IOSurfaceContext::kCALayerContext); 178 content::IOSurfaceContext::kCALayerContext);
187 if (!iosurface_.get() || !context_.get()) { 179 if (!iosurface_.get() || !context_.get()) {
188 LOG(ERROR) << "Failed create CompositingIOSurface or context"; 180 LOG(ERROR) << "Failed create CompositingIOSurface or context";
(...skipping 15 matching lines...) Expand all
204 } 196 }
205 197
206 - (void)dealloc { 198 - (void)dealloc {
207 DCHECK(!helper_); 199 DCHECK(!helper_);
208 [super dealloc]; 200 [super dealloc];
209 } 201 }
210 202
211 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id 203 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id
212 withPixelSize:(gfx::Size)pixel_size 204 withPixelSize:(gfx::Size)pixel_size
213 withScaleFactor:(float)scale_factor { 205 withScaleFactor:(float)scale_factor {
214 return iosurface_->SetIOSurface(context_, io_surface_id, pixel_size); 206 return iosurface_->SetIOSurface(io_surface_id, pixel_size);
215 } 207 }
216 208
217 - (void)poisonContextAndSharegroup { 209 - (void)poisonContextAndSharegroup {
218 context_->PoisonContextAndSharegroup(); 210 context_->PoisonContextAndSharegroup();
219 } 211 }
220 212
221 - (bool)hasBeenPoisoned { 213 - (bool)hasBeenPoisoned {
222 return context_->HasBeenPoisoned(); 214 return context_->HasBeenPoisoned();
223 } 215 }
224 216
225 - (float)scaleFactor { 217 - (float)scaleFactor {
226 if ([self respondsToSelector:(@selector(contentsScale))]) 218 if ([self respondsToSelector:(@selector(contentsScale))])
227 return [self contentsScale]; 219 return [self contentsScale];
228 return 1; 220 return 1;
229 } 221 }
230 222
231 - (int)rendererID { 223 - (int)rendererID {
232 return iosurface_->GetRendererID(); 224 GLint current_renderer_id = -1;
225 if (CGLGetParameter(context_->cgl_context(),
226 kCGLCPCurrentRendererID,
227 &current_renderer_id) == kCGLNoError) {
228 return current_renderer_id & kCGLRendererIDMatchingMask;
229 }
230 return -1;
233 } 231 }
234 232
235 - (void)resetClient { 233 - (void)resetClient {
236 helper_.reset(); 234 helper_.reset();
237 } 235 }
238 236
239 - (void)gotNewFrame { 237 - (void)gotNewFrame {
240 helper_->GotNewFrame(); 238 helper_->GotNewFrame();
241 } 239 }
242 240
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 return helper_->CanDraw(); 282 return helper_->CanDraw();
285 return NO; 283 return NO;
286 } 284 }
287 285
288 - (void)drawInCGLContext:(CGLContextObj)glContext 286 - (void)drawInCGLContext:(CGLContextObj)glContext
289 pixelFormat:(CGLPixelFormatObj)pixelFormat 287 pixelFormat:(CGLPixelFormatObj)pixelFormat
290 forLayerTime:(CFTimeInterval)timeInterval 288 forLayerTime:(CFTimeInterval)timeInterval
291 displayTime:(const CVTimeStamp*)timeStamp { 289 displayTime:(const CVTimeStamp*)timeStamp {
292 TRACE_EVENT0("browser", "IOSurfaceLayer::drawInCGLContext"); 290 TRACE_EVENT0("browser", "IOSurfaceLayer::drawInCGLContext");
293 291
294 if (!iosurface_->HasIOSurface() || context_->cgl_context() != glContext) {
295 glClearColor(1, 1, 1, 1);
296 glClear(GL_COLOR_BUFFER_BIT);
297 return;
298 }
299
300 bool draw_succeeded = iosurface_->DrawIOSurface(); 292 bool draw_succeeded = iosurface_->DrawIOSurface();
301 if (helper_) 293 if (helper_)
302 helper_->DidDraw(draw_succeeded); 294 helper_->DidDraw(draw_succeeded);
303 295
304 [super drawInCGLContext:glContext 296 [super drawInCGLContext:glContext
305 pixelFormat:pixelFormat 297 pixelFormat:pixelFormat
306 forLayerTime:timeInterval 298 forLayerTime:timeInterval
307 displayTime:timeStamp]; 299 displayTime:timeStamp];
308 } 300 }
309 301
310 @end 302 @end
OLDNEW
« no previous file with comments | « no previous file | content/browser/compositor/io_surface_texture_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698