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/CGLRenderers.h> | 7 #include <OpenGL/CGLRenderers.h> |
8 #include <OpenGL/OpenGL.h> | 8 #include <OpenGL/OpenGL.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 COMPILE_ASSERT(media::VideoFrame::kYPlane == 0, VideoFrame_kYPlane_mismatch); | 117 COMPILE_ASSERT(media::VideoFrame::kYPlane == 0, VideoFrame_kYPlane_mismatch); |
118 COMPILE_ASSERT(media::VideoFrame::kUPlane == 1, VideoFrame_kUPlane_mismatch); | 118 COMPILE_ASSERT(media::VideoFrame::kUPlane == 1, VideoFrame_kUPlane_mismatch); |
119 COMPILE_ASSERT(media::VideoFrame::kVPlane == 2, VideoFrame_kVPlane_mismatch); | 119 COMPILE_ASSERT(media::VideoFrame::kVPlane == 2, VideoFrame_kVPlane_mismatch); |
120 | 120 |
121 TRACE_EVENT1("browser", "MapBufferToVideoFrame", "plane", plane); | 121 TRACE_EVENT1("browser", "MapBufferToVideoFrame", "plane", plane); |
122 | 122 |
123 // Apply black-out in the regions surrounding the view area (for | 123 // Apply black-out in the regions surrounding the view area (for |
124 // letterboxing/pillarboxing). Only do this once, since this is performed on | 124 // letterboxing/pillarboxing). Only do this once, since this is performed on |
125 // all planes in the VideoFrame here. | 125 // all planes in the VideoFrame here. |
126 if (plane == 0) | 126 if (plane == 0) |
127 media::LetterboxYUV(target, region_in_frame); | 127 media::LetterboxYUV(target.get(), region_in_frame); |
128 | 128 |
129 if (buf) { | 129 if (buf) { |
130 int packed_width = region_in_frame.width(); | 130 int packed_width = region_in_frame.width(); |
131 int packed_height = region_in_frame.height(); | 131 int packed_height = region_in_frame.height(); |
132 // For planes 1 and 2, the width and height are 1/2 size (rounded up). | 132 // For planes 1 and 2, the width and height are 1/2 size (rounded up). |
133 if (plane > 0) { | 133 if (plane > 0) { |
134 packed_width = (packed_width + 1) / 2; | 134 packed_width = (packed_width + 1) / 2; |
135 packed_height = (packed_height + 1) / 2; | 135 packed_height = (packed_height + 1) / 2; |
136 } | 136 } |
137 const uint8* src = reinterpret_cast<const uint8*>(buf); | 137 const uint8* src = reinterpret_cast<const uint8*>(buf); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 | 244 |
245 // static | 245 // static |
246 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create(int window_number) { | 246 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create(int window_number) { |
247 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::Create"); | 247 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::Create"); |
248 | 248 |
249 scoped_refptr<CompositingIOSurfaceContext> context = | 249 scoped_refptr<CompositingIOSurfaceContext> context = |
250 CompositingIOSurfaceContext::Get(window_number); | 250 CompositingIOSurfaceContext::Get(window_number); |
251 if (!context) { | 251 if (!context.get()) { |
252 LOG(ERROR) << "Failed to create context for IOSurface"; | 252 LOG(ERROR) << "Failed to create context for IOSurface"; |
253 return NULL; | 253 return NULL; |
254 } | 254 } |
255 | 255 |
256 return Create(context); | 256 return Create(context); |
257 } | 257 } |
258 | 258 |
259 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create( | 259 CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create( |
260 const scoped_refptr<CompositingIOSurfaceContext>& context) { | 260 const scoped_refptr<CompositingIOSurfaceContext>& context) { |
261 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); | 261 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 if (!copy_requests_.empty()) | 340 if (!copy_requests_.empty()) |
341 return; | 341 return; |
342 if (!copy_context_pool_.empty()) { | 342 if (!copy_context_pool_.empty()) { |
343 CGLSetCurrentContext(context_->cgl_context()); | 343 CGLSetCurrentContext(context_->cgl_context()); |
344 DestroyAllCopyContextsWithinContext(); | 344 DestroyAllCopyContextsWithinContext(); |
345 CGLSetCurrentContext(0); | 345 CGLSetCurrentContext(0); |
346 } | 346 } |
347 | 347 |
348 scoped_refptr<CompositingIOSurfaceContext> new_context = | 348 scoped_refptr<CompositingIOSurfaceContext> new_context = |
349 CompositingIOSurfaceContext::Get(window_number); | 349 CompositingIOSurfaceContext::Get(window_number); |
350 if (!new_context) | 350 if (!new_context.get()) |
351 return; | 351 return; |
352 | 352 |
353 // Having two NSOpenGLContexts bound to an NSView concurrently will cause | 353 // Having two NSOpenGLContexts bound to an NSView concurrently will cause |
354 // artifacts and crashes. If |context_| is bound to |view|, then unbind | 354 // artifacts and crashes. If |context_| is bound to |view|, then unbind |
355 // |context_| before |new_context| gets bound to |view|. | 355 // |context_| before |new_context| gets bound to |view|. |
356 // http://crbug.com/230883 | 356 // http://crbug.com/230883 |
357 if ([context_->nsgl_context() view] == view) | 357 if ([context_->nsgl_context() view] == view) |
358 [context_->nsgl_context() clearDrawable]; | 358 [context_->nsgl_context() clearDrawable]; |
359 | 359 |
360 context_ = new_context; | 360 context_ = new_context; |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 (base::mac::IsOSMountainLionOrLater() || !IsVendorIntel())); | 814 (base::mac::IsOSMountainLionOrLater() || !IsVendorIntel())); |
815 } | 815 } |
816 | 816 |
817 base::Closure CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext( | 817 base::Closure CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext( |
818 const gfx::Rect& src_pixel_subrect, | 818 const gfx::Rect& src_pixel_subrect, |
819 const gfx::Rect& dst_pixel_rect, | 819 const gfx::Rect& dst_pixel_rect, |
820 bool called_within_draw, | 820 bool called_within_draw, |
821 const SkBitmap* bitmap_output, | 821 const SkBitmap* bitmap_output, |
822 const scoped_refptr<media::VideoFrame>& video_frame_output, | 822 const scoped_refptr<media::VideoFrame>& video_frame_output, |
823 const base::Callback<void(bool)>& done_callback) { | 823 const base::Callback<void(bool)>& done_callback) { |
824 DCHECK_NE(bitmap_output != NULL, video_frame_output != NULL); | 824 DCHECK_NE(bitmap_output != NULL, video_frame_output.get() != NULL); |
825 DCHECK(!done_callback.is_null()); | 825 DCHECK(!done_callback.is_null()); |
826 | 826 |
827 const bool async_copy = IsAsynchronousReadbackSupported(); | 827 const bool async_copy = IsAsynchronousReadbackSupported(); |
828 TRACE_EVENT2( | 828 TRACE_EVENT2( |
829 "browser", "CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext", | 829 "browser", "CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext", |
830 "output", bitmap_output ? "SkBitmap (ARGB)" : "VideoFrame (YV12)", | 830 "output", bitmap_output ? "SkBitmap (ARGB)" : "VideoFrame (YV12)", |
831 "async_readback", async_copy); | 831 "async_readback", async_copy); |
832 | 832 |
833 CopyContext* copy_context; | 833 CopyContext* copy_context; |
834 if (copy_context_pool_.empty()) { | 834 if (copy_context_pool_.empty()) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 temp_readback_buffer.reset( | 1056 temp_readback_buffer.reset( |
1057 new uint32[copy_context->output_texture_sizes[i].GetArea()]); | 1057 new uint32[copy_context->output_texture_sizes[i].GetArea()]); |
1058 buf = temp_readback_buffer.get(); | 1058 buf = temp_readback_buffer.get(); |
1059 } | 1059 } |
1060 } | 1060 } |
1061 glReadPixels(0, 0, | 1061 glReadPixels(0, 0, |
1062 copy_context->output_texture_sizes[i].width(), | 1062 copy_context->output_texture_sizes[i].width(), |
1063 copy_context->output_texture_sizes[i].height(), | 1063 copy_context->output_texture_sizes[i].height(), |
1064 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, | 1064 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, |
1065 buf); CHECK_AND_SAVE_GL_ERROR(); | 1065 buf); CHECK_AND_SAVE_GL_ERROR(); |
1066 if (video_frame_output) { | 1066 if (video_frame_output.get()) { |
1067 if (!temp_readback_buffer) { | 1067 if (!temp_readback_buffer) { |
1068 // Apply letterbox black-out around view region. | 1068 // Apply letterbox black-out around view region. |
1069 media::LetterboxYUV(video_frame_output, dst_pixel_rect); | 1069 media::LetterboxYUV(video_frame_output.get(), dst_pixel_rect); |
1070 } else { | 1070 } else { |
1071 // Copy from temporary buffer and fully render the VideoFrame. | 1071 // Copy from temporary buffer and fully render the VideoFrame. |
1072 success &= MapBufferToVideoFrame(video_frame_output, dst_pixel_rect, | 1072 success &= MapBufferToVideoFrame(video_frame_output, dst_pixel_rect, |
1073 temp_readback_buffer.get(), i); | 1073 temp_readback_buffer.get(), i); |
1074 } | 1074 } |
1075 } | 1075 } |
1076 } | 1076 } |
1077 | 1077 |
1078 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); CHECK_AND_SAVE_GL_ERROR(); | 1078 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); CHECK_AND_SAVE_GL_ERROR(); |
1079 copy_context_pool_.push_back(copy_context); | 1079 copy_context_pool_.push_back(copy_context); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 } | 1113 } |
1114 | 1114 |
1115 GLenum CompositingIOSurfaceMac::GetAndSaveGLError() { | 1115 GLenum CompositingIOSurfaceMac::GetAndSaveGLError() { |
1116 GLenum gl_error = glGetError(); | 1116 GLenum gl_error = glGetError(); |
1117 if (gl_error_ == GL_NO_ERROR) | 1117 if (gl_error_ == GL_NO_ERROR) |
1118 gl_error_ = gl_error; | 1118 gl_error_ = gl_error; |
1119 return gl_error; | 1119 return gl_error; |
1120 } | 1120 } |
1121 | 1121 |
1122 } // namespace content | 1122 } // namespace content |
OLD | NEW |