OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/surface/accelerated_surface_mac.h" | 5 #include "ui/gfx/surface/accelerated_surface_mac.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
9 #include "ui/gfx/gl/gl_bindings.h" | 9 #include "ui/gfx/gl/gl_bindings.h" |
10 #include "ui/gfx/gl/gl_context.h" | 10 #include "ui/gfx/gl/gl_context.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 void AcceleratedSurface::Destroy() { | 67 void AcceleratedSurface::Destroy() { |
68 // The FBO and texture objects will be destroyed when the OpenGL context, | 68 // The FBO and texture objects will be destroyed when the OpenGL context, |
69 // and any other contexts sharing resources with it, is. We don't want to | 69 // and any other contexts sharing resources with it, is. We don't want to |
70 // make the context current one last time here just in order to delete | 70 // make the context current one last time here just in order to delete |
71 // these objects. | 71 // these objects. |
72 | 72 |
73 // Release the old TransportDIB in the browser. | 73 // Release the old TransportDIB in the browser. |
74 if (dib_free_callback_.get() && transport_dib_.get()) { | 74 if (!dib_free_callback_.is_null() && transport_dib_.get()) { |
75 dib_free_callback_->Run(transport_dib_->id()); | 75 dib_free_callback_.Run(transport_dib_->id()); |
76 } | 76 } |
77 transport_dib_.reset(); | 77 transport_dib_.reset(); |
78 | 78 |
79 gl_context_ = NULL; | 79 gl_context_ = NULL; |
80 gl_surface_ = NULL; | 80 gl_surface_ = NULL; |
81 } | 81 } |
82 | 82 |
83 // Call after making changes to the surface which require a visual update. | 83 // Call after making changes to the surface which require a visual update. |
84 // Makes the rendering show up in other processes. | 84 // Makes the rendering show up in other processes. |
85 void AcceleratedSurface::SwapBuffers() { | 85 void AcceleratedSurface::SwapBuffers() { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 if (surface_size_ == size) { | 324 if (surface_size_ == size) { |
325 // Return an invalid handle to indicate to the caller that no new backing | 325 // Return an invalid handle to indicate to the caller that no new backing |
326 // store allocation occurred. | 326 // store allocation occurred. |
327 return TransportDIB::DefaultHandleValue(); | 327 return TransportDIB::DefaultHandleValue(); |
328 } | 328 } |
329 surface_size_ = size; | 329 surface_size_ = size; |
330 gfx::Size clamped_size = ClampToValidDimensions(size); | 330 gfx::Size clamped_size = ClampToValidDimensions(size); |
331 real_surface_size_ = clamped_size; | 331 real_surface_size_ = clamped_size; |
332 | 332 |
333 // Release the old TransportDIB in the browser. | 333 // Release the old TransportDIB in the browser. |
334 if (dib_free_callback_.get() && transport_dib_.get()) { | 334 if (!dib_free_callback_.is_null() && transport_dib_.get()) { |
335 dib_free_callback_->Run(transport_dib_->id()); | 335 dib_free_callback_.Run(transport_dib_->id()); |
336 } | 336 } |
337 transport_dib_.reset(); | 337 transport_dib_.reset(); |
338 | 338 |
339 // Ask the renderer to create a TransportDIB. | 339 // Ask the renderer to create a TransportDIB. |
340 size_t dib_size = | 340 size_t dib_size = |
341 clamped_size.width() * 4 * clamped_size.height(); // 4 bytes per pixel. | 341 clamped_size.width() * 4 * clamped_size.height(); // 4 bytes per pixel. |
342 TransportDIB::Handle dib_handle; | 342 TransportDIB::Handle dib_handle; |
343 if (dib_alloc_callback_.get()) { | 343 if (!dib_alloc_callback_.is_null()) { |
344 dib_alloc_callback_->Run(dib_size, &dib_handle); | 344 dib_alloc_callback_.Run(dib_size, &dib_handle); |
345 } | 345 } |
346 if (!TransportDIB::is_valid_handle(dib_handle)) { | 346 if (!TransportDIB::is_valid_handle(dib_handle)) { |
347 // If the allocator fails, it means the DIB was not created in the browser, | 347 // If the allocator fails, it means the DIB was not created in the browser, |
348 // so there is no need to run the deallocator here. | 348 // so there is no need to run the deallocator here. |
349 return TransportDIB::DefaultHandleValue(); | 349 return TransportDIB::DefaultHandleValue(); |
350 } | 350 } |
351 transport_dib_.reset(TransportDIB::Map(dib_handle)); | 351 transport_dib_.reset(TransportDIB::Map(dib_handle)); |
352 if (transport_dib_.get() == NULL) { | 352 if (transport_dib_.get() == NULL) { |
353 // TODO(dspringer): if the Map() fails, should the deallocator be run so | 353 // TODO(dspringer): if the Map() fails, should the deallocator be run so |
354 // that the DIB is deallocated in the browser? | 354 // that the DIB is deallocated in the browser? |
(...skipping 14 matching lines...) Expand all Loading... |
369 0, // 0 border | 369 0, // 0 border |
370 GL_BGRA, // Used for consistency | 370 GL_BGRA, // Used for consistency |
371 GL_UNSIGNED_INT_8_8_8_8_REV, | 371 GL_UNSIGNED_INT_8_8_8_8_REV, |
372 NULL); // No data, just reserve room on the card. | 372 NULL); // No data, just reserve room on the card. |
373 SetupFrameBufferObject(target); | 373 SetupFrameBufferObject(target); |
374 } | 374 } |
375 return transport_dib_->handle(); | 375 return transport_dib_->handle(); |
376 } | 376 } |
377 | 377 |
378 void AcceleratedSurface::SetTransportDIBAllocAndFree( | 378 void AcceleratedSurface::SetTransportDIBAllocAndFree( |
379 Callback2<size_t, TransportDIB::Handle*>::Type* allocator, | 379 const base::Callback<void(size_t, TransportDIB::Handle*)>& allocator, |
380 Callback1<TransportDIB::Id>::Type* deallocator) { | 380 const base::Callback<void(TransportDIB::Id)>& deallocator) { |
381 dib_alloc_callback_.reset(allocator); | 381 dib_alloc_callback_ = allocator; |
382 dib_free_callback_.reset(deallocator); | 382 dib_free_callback_ = deallocator; |
383 } | 383 } |
OLD | NEW |