OLD | NEW |
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 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 5 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
6 | 6 |
| 7 #include <OpenGL/CGLIOSurface.h> |
7 #include <OpenGL/CGLRenderers.h> | 8 #include <OpenGL/CGLRenderers.h> |
8 #include <OpenGL/OpenGL.h> | 9 #include <OpenGL/OpenGL.h> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
17 #include "content/browser/gpu/gpu_data_manager_impl.h" | 18 #include "content/browser/gpu/gpu_data_manager_impl.h" |
18 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 19 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
19 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma
c.h" | 20 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma
c.h" |
20 #include "content/browser/renderer_host/compositing_iosurface_transformer_mac.h" | 21 #include "content/browser/renderer_host/compositing_iosurface_transformer_mac.h" |
21 #include "content/browser/renderer_host/render_widget_host_impl.h" | 22 #include "content/browser/renderer_host/render_widget_host_impl.h" |
22 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 23 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
23 #include "content/common/content_constants_internal.h" | 24 #include "content/common/content_constants_internal.h" |
24 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 25 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
25 #include "media/base/video_util.h" | 26 #include "media/base/video_util.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
27 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
28 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
29 #include "ui/gfx/size_conversions.h" | 30 #include "ui/gfx/size_conversions.h" |
30 #include "ui/gl/gl_context.h" | 31 #include "ui/gl/gl_context.h" |
31 #include "ui/gl/io_surface_support_mac.h" | |
32 | 32 |
33 #ifdef NDEBUG | 33 #ifdef NDEBUG |
34 #define CHECK_GL_ERROR() | 34 #define CHECK_GL_ERROR() |
35 #define CHECK_AND_SAVE_GL_ERROR() | 35 #define CHECK_AND_SAVE_GL_ERROR() |
36 #else | 36 #else |
37 #define CHECK_GL_ERROR() do { \ | 37 #define CHECK_GL_ERROR() do { \ |
38 GLenum gl_error = glGetError(); \ | 38 GLenum gl_error = glGetError(); \ |
39 LOG_IF(ERROR, gl_error != GL_NO_ERROR) << "GL Error: " << gl_error; \ | 39 LOG_IF(ERROR, gl_error != GL_NO_ERROR) << "GL Error: " << gl_error; \ |
40 } while (0) | 40 } while (0) |
41 #define CHECK_AND_SAVE_GL_ERROR() do { \ | 41 #define CHECK_AND_SAVE_GL_ERROR() do { \ |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 for (int i = 0; i < num_outputs; ++i) { | 211 for (int i = 0; i < num_outputs; ++i) { |
212 if (!pixel_buffers[i]) { | 212 if (!pixel_buffers[i]) { |
213 glGenBuffersARB(1, &pixel_buffers[i]); CHECK_GL_ERROR(); | 213 glGenBuffersARB(1, &pixel_buffers[i]); CHECK_GL_ERROR(); |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 | 218 |
219 // static | 219 // static |
220 scoped_refptr<CompositingIOSurfaceMac> CompositingIOSurfaceMac::Create() { | 220 scoped_refptr<CompositingIOSurfaceMac> CompositingIOSurfaceMac::Create() { |
221 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); | |
222 if (!io_surface_support) { | |
223 LOG(ERROR) << "No IOSurface support"; | |
224 return NULL; | |
225 } | |
226 | |
227 scoped_refptr<CompositingIOSurfaceContext> offscreen_context = | 221 scoped_refptr<CompositingIOSurfaceContext> offscreen_context = |
228 CompositingIOSurfaceContext::Get( | 222 CompositingIOSurfaceContext::Get( |
229 CompositingIOSurfaceContext::kOffscreenContextWindowNumber); | 223 CompositingIOSurfaceContext::kOffscreenContextWindowNumber); |
230 if (!offscreen_context) { | 224 if (!offscreen_context) { |
231 LOG(ERROR) << "Failed to create context for offscreen operations"; | 225 LOG(ERROR) << "Failed to create context for offscreen operations"; |
232 return NULL; | 226 return NULL; |
233 } | 227 } |
234 | 228 |
235 return new CompositingIOSurfaceMac(io_surface_support, | 229 return new CompositingIOSurfaceMac(offscreen_context); |
236 offscreen_context); | |
237 } | 230 } |
238 | 231 |
239 CompositingIOSurfaceMac::CompositingIOSurfaceMac( | 232 CompositingIOSurfaceMac::CompositingIOSurfaceMac( |
240 IOSurfaceSupport* io_surface_support, | |
241 const scoped_refptr<CompositingIOSurfaceContext>& offscreen_context) | 233 const scoped_refptr<CompositingIOSurfaceContext>& offscreen_context) |
242 : io_surface_support_(io_surface_support), | 234 : offscreen_context_(offscreen_context), |
243 offscreen_context_(offscreen_context), | |
244 io_surface_handle_(0), | 235 io_surface_handle_(0), |
245 scale_factor_(1.f), | 236 scale_factor_(1.f), |
246 texture_(0), | 237 texture_(0), |
247 finish_copy_timer_( | 238 finish_copy_timer_( |
248 FROM_HERE, | 239 FROM_HERE, |
249 base::TimeDelta::FromMilliseconds(kFinishCopyPollingPeriodMs), | 240 base::TimeDelta::FromMilliseconds(kFinishCopyPollingPeriodMs), |
250 base::Bind(&CompositingIOSurfaceMac::CheckIfAllCopiesAreFinished, | 241 base::Bind(&CompositingIOSurfaceMac::CheckIfAllCopiesAreFinished, |
251 base::Unretained(this), | 242 base::Unretained(this), |
252 false), | 243 false), |
253 true), | 244 true), |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 scale_factor_ = scale_factor; | 477 scale_factor_ = scale_factor; |
487 dip_io_surface_size_ = gfx::ToFlooredSize( | 478 dip_io_surface_size_ = gfx::ToFlooredSize( |
488 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor_)); | 479 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor_)); |
489 | 480 |
490 // Early-out if the IOSurface has not changed. Note that because IOSurface | 481 // Early-out if the IOSurface has not changed. Note that because IOSurface |
491 // sizes are rounded, the same IOSurface may have two different sizes | 482 // sizes are rounded, the same IOSurface may have two different sizes |
492 // associated with it. | 483 // associated with it. |
493 if (io_surface_ && io_surface_handle == io_surface_handle_) | 484 if (io_surface_ && io_surface_handle == io_surface_handle_) |
494 return true; | 485 return true; |
495 | 486 |
496 io_surface_.reset(io_surface_support_->IOSurfaceLookup( | 487 io_surface_.reset(IOSurfaceLookup(static_cast<uint32>(io_surface_handle))); |
497 static_cast<uint32>(io_surface_handle))); | |
498 // Can fail if IOSurface with that ID was already released by the gpu | 488 // Can fail if IOSurface with that ID was already released by the gpu |
499 // process. | 489 // process. |
500 if (!io_surface_) { | 490 if (!io_surface_) { |
501 UnrefIOSurfaceWithContextCurrent(); | 491 UnrefIOSurfaceWithContextCurrent(); |
502 return false; | 492 return false; |
503 } | 493 } |
504 | 494 |
505 io_surface_handle_ = io_surface_handle; | 495 io_surface_handle_ = io_surface_handle; |
506 | 496 |
507 // Actual IOSurface size is rounded up to reduce reallocations during window | 497 // Actual IOSurface size is rounded up to reduce reallocations during window |
508 // resize. Get the actual size to properly map the texture. | 498 // resize. Get the actual size to properly map the texture. |
509 gfx::Size rounded_size( | 499 gfx::Size rounded_size(IOSurfaceGetWidth(io_surface_), |
510 io_surface_support_->IOSurfaceGetWidth(io_surface_), | 500 IOSurfaceGetHeight(io_surface_)); |
511 io_surface_support_->IOSurfaceGetHeight(io_surface_)); | |
512 | 501 |
513 glGenTextures(1, &texture_); | 502 glGenTextures(1, &texture_); |
514 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); | 503 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); |
515 glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 504 glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
516 glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 505 glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
517 CHECK_AND_SAVE_GL_ERROR(); | 506 CHECK_AND_SAVE_GL_ERROR(); |
518 GLuint plane = 0; | 507 GLuint plane = 0; |
519 CGLError cgl_error = io_surface_support_->CGLTexImageIOSurface2D( | 508 CGLError cgl_error = CGLTexImageIOSurface2D( |
520 current_context->cgl_context(), | 509 current_context->cgl_context(), |
521 GL_TEXTURE_RECTANGLE_ARB, | 510 GL_TEXTURE_RECTANGLE_ARB, |
522 GL_RGBA, | 511 GL_RGBA, |
523 rounded_size.width(), | 512 rounded_size.width(), |
524 rounded_size.height(), | 513 rounded_size.height(), |
525 GL_BGRA, | 514 GL_BGRA, |
526 GL_UNSIGNED_INT_8_8_8_8_REV, | 515 GL_UNSIGNED_INT_8_8_8_8_REV, |
527 io_surface_.get(), | 516 io_surface_.get(), |
528 plane); | 517 plane); |
529 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); | 518 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 } | 977 } |
989 | 978 |
990 // static | 979 // static |
991 base::LazyInstance<CompositingIOSurfaceMac::EvictionQueue> | 980 base::LazyInstance<CompositingIOSurfaceMac::EvictionQueue> |
992 CompositingIOSurfaceMac::eviction_queue_; | 981 CompositingIOSurfaceMac::eviction_queue_; |
993 | 982 |
994 // static | 983 // static |
995 bool CompositingIOSurfaceMac::eviction_scheduled_ = false; | 984 bool CompositingIOSurfaceMac::eviction_scheduled_ = false; |
996 | 985 |
997 } // namespace content | 986 } // namespace content |
OLD | NEW |