OLD | NEW |
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 "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/gl_renderer.h" | 8 #include "cc/output/gl_renderer.h" |
9 #include "cc/resources/resource_provider.h" | 9 #include "cc/resources/resource_provider.h" |
10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 #include "media/filters/skcanvas_video_renderer.h" | 12 #include "media/filters/skcanvas_video_renderer.h" |
| 13 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
13 #include "third_party/khronos/GLES2/gl2.h" | 14 #include "third_party/khronos/GLES2/gl2.h" |
14 #include "third_party/khronos/GLES2/gl2ext.h" | 15 #include "third_party/khronos/GLES2/gl2ext.h" |
15 #include "ui/gfx/size_conversions.h" | 16 #include "ui/gfx/size_conversions.h" |
16 | 17 |
17 const unsigned kYUVResourceFormat = GL_LUMINANCE; | 18 const unsigned kYUVResourceFormat = GL_LUMINANCE; |
18 const unsigned kRGBResourceFormat = GL_RGBA; | 19 const unsigned kRGBResourceFormat = GL_RGBA; |
19 | 20 |
20 namespace cc { | 21 namespace cc { |
21 | 22 |
22 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} | 23 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} |
23 | 24 |
24 VideoFrameExternalResources::~VideoFrameExternalResources() {} | 25 VideoFrameExternalResources::~VideoFrameExternalResources() {} |
25 | 26 |
26 VideoResourceUpdater::VideoResourceUpdater(ResourceProvider* resource_provider) | 27 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, |
27 : resource_provider_(resource_provider) { | 28 ResourceProvider* resource_provider) |
| 29 : context_provider_(context_provider), |
| 30 resource_provider_(resource_provider) { |
28 } | 31 } |
29 | 32 |
30 VideoResourceUpdater::~VideoResourceUpdater() { | 33 VideoResourceUpdater::~VideoResourceUpdater() { |
31 while (!all_resources_.empty()) { | 34 while (!all_resources_.empty()) { |
32 resource_provider_->DeleteResource(all_resources_.back()); | 35 resource_provider_->DeleteResource(all_resources_.back()); |
33 all_resources_.pop_back(); | 36 all_resources_.pop_back(); |
34 } | 37 } |
35 } | 38 } |
36 | 39 |
37 void VideoResourceUpdater::DeleteResource(unsigned resource_id) { | 40 void VideoResourceUpdater::DeleteResource(unsigned resource_id) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 134 |
132 // Only YUV software video frames are supported. | 135 // Only YUV software video frames are supported. |
133 DCHECK(input_frame_format == media::VideoFrame::YV12 || | 136 DCHECK(input_frame_format == media::VideoFrame::YV12 || |
134 input_frame_format == media::VideoFrame::YV12A || | 137 input_frame_format == media::VideoFrame::YV12A || |
135 input_frame_format == media::VideoFrame::YV16); | 138 input_frame_format == media::VideoFrame::YV16); |
136 if (input_frame_format != media::VideoFrame::YV12 && | 139 if (input_frame_format != media::VideoFrame::YV12 && |
137 input_frame_format != media::VideoFrame::YV12A && | 140 input_frame_format != media::VideoFrame::YV12A && |
138 input_frame_format != media::VideoFrame::YV16) | 141 input_frame_format != media::VideoFrame::YV16) |
139 return VideoFrameExternalResources(); | 142 return VideoFrameExternalResources(); |
140 | 143 |
141 bool software_compositor = !resource_provider_->GraphicsContext3D(); | 144 bool software_compositor = context_provider_ == NULL; |
142 | 145 |
143 GLenum output_resource_format = kYUVResourceFormat; | 146 GLenum output_resource_format = kYUVResourceFormat; |
144 size_t output_plane_count = | 147 size_t output_plane_count = |
145 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3; | 148 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3; |
146 | 149 |
147 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB | 150 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB |
148 // conversion here. That involves an extra copy of each frame to a bitmap. | 151 // conversion here. That involves an extra copy of each frame to a bitmap. |
149 // Obviously, this is suboptimal and should be addressed once ubercompositor | 152 // Obviously, this is suboptimal and should be addressed once ubercompositor |
150 // starts shaping up. | 153 // starts shaping up. |
151 if (software_compositor) { | 154 if (software_compositor) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // TODO(danakj): Abstract out hw/sw resource create/delete from | 193 // TODO(danakj): Abstract out hw/sw resource create/delete from |
191 // ResourceProvider and stop using ResourceProvider in this class. | 194 // ResourceProvider and stop using ResourceProvider in this class. |
192 resource_id = | 195 resource_id = |
193 resource_provider_->CreateResource(output_plane_resource_size, | 196 resource_provider_->CreateResource(output_plane_resource_size, |
194 output_resource_format, | 197 output_resource_format, |
195 ResourceProvider::TextureUsageAny); | 198 ResourceProvider::TextureUsageAny); |
196 | 199 |
197 DCHECK(mailbox.IsZero()); | 200 DCHECK(mailbox.IsZero()); |
198 | 201 |
199 if (!software_compositor) { | 202 if (!software_compositor) { |
| 203 DCHECK(context_provider_); |
| 204 |
200 WebKit::WebGraphicsContext3D* context = | 205 WebKit::WebGraphicsContext3D* context = |
201 resource_provider_->GraphicsContext3D(); | 206 context_provider_->Context3d(); |
202 DCHECK(context); | |
203 | 207 |
204 GLC(context, context->genMailboxCHROMIUM(mailbox.name)); | 208 GLC(context, context->genMailboxCHROMIUM(mailbox.name)); |
205 if (mailbox.IsZero()) { | 209 if (mailbox.IsZero()) { |
206 resource_provider_->DeleteResource(resource_id); | 210 resource_provider_->DeleteResource(resource_id); |
207 resource_id = 0; | 211 resource_id = 0; |
208 } else { | 212 } else { |
209 ResourceProvider::ScopedWriteLockGL lock( | 213 ResourceProvider::ScopedWriteLockGL lock( |
210 resource_provider_, resource_id); | 214 resource_provider_, resource_id); |
211 GLC(context, context->bindTexture(GL_TEXTURE_2D, lock.texture_id())); | 215 GLC(context, context->bindTexture(GL_TEXTURE_2D, lock.texture_id())); |
212 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, | 216 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 327 } |
324 | 328 |
325 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 329 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
326 const scoped_refptr<media::VideoFrame>& video_frame) { | 330 const scoped_refptr<media::VideoFrame>& video_frame) { |
327 media::VideoFrame::Format frame_format = video_frame->format(); | 331 media::VideoFrame::Format frame_format = video_frame->format(); |
328 | 332 |
329 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); | 333 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); |
330 if (frame_format != media::VideoFrame::NATIVE_TEXTURE) | 334 if (frame_format != media::VideoFrame::NATIVE_TEXTURE) |
331 return VideoFrameExternalResources(); | 335 return VideoFrameExternalResources(); |
332 | 336 |
333 WebKit::WebGraphicsContext3D* context = | 337 if (!context_provider_) |
334 resource_provider_->GraphicsContext3D(); | |
335 if (!context) | |
336 return VideoFrameExternalResources(); | 338 return VideoFrameExternalResources(); |
337 | 339 |
338 VideoFrameExternalResources external_resources; | 340 VideoFrameExternalResources external_resources; |
339 switch (video_frame->texture_target()) { | 341 switch (video_frame->texture_target()) { |
340 case GL_TEXTURE_2D: | 342 case GL_TEXTURE_2D: |
341 external_resources.type = VideoFrameExternalResources::RGB_RESOURCE; | 343 external_resources.type = VideoFrameExternalResources::RGB_RESOURCE; |
342 break; | 344 break; |
343 case GL_TEXTURE_EXTERNAL_OES: | 345 case GL_TEXTURE_EXTERNAL_OES: |
344 external_resources.type = | 346 external_resources.type = |
345 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; | 347 VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE; |
(...skipping 24 matching lines...) Expand all Loading... |
370 void VideoResourceUpdater::RecycleResource( | 372 void VideoResourceUpdater::RecycleResource( |
371 base::WeakPtr<VideoResourceUpdater> updater, | 373 base::WeakPtr<VideoResourceUpdater> updater, |
372 RecycleResourceData data, | 374 RecycleResourceData data, |
373 unsigned sync_point, | 375 unsigned sync_point, |
374 bool lost_resource) { | 376 bool lost_resource) { |
375 if (!updater.get()) { | 377 if (!updater.get()) { |
376 // Resource was already deleted. | 378 // Resource was already deleted. |
377 return; | 379 return; |
378 } | 380 } |
379 | 381 |
380 WebKit::WebGraphicsContext3D* context = | 382 ContextProvider* context_provider = updater->context_provider_; |
381 updater->resource_provider_->GraphicsContext3D(); | 383 if (context_provider && sync_point) { |
382 if (context && sync_point) | 384 GLC(context_provider->Context3d(), |
383 GLC(context, context->waitSyncPoint(sync_point)); | 385 context_provider->Context3d()->waitSyncPoint(sync_point)); |
| 386 } |
384 | 387 |
385 if (lost_resource) { | 388 if (lost_resource) { |
386 updater->DeleteResource(data.resource_id); | 389 updater->DeleteResource(data.resource_id); |
387 return; | 390 return; |
388 } | 391 } |
389 | 392 |
390 // Drop recycled resources that are the wrong format. | 393 // Drop recycled resources that are the wrong format. |
391 while (!updater->recycled_resources_.empty() && | 394 while (!updater->recycled_resources_.empty() && |
392 updater->recycled_resources_.back().resource_format != | 395 updater->recycled_resources_.back().resource_format != |
393 data.resource_format) { | 396 data.resource_format) { |
394 updater->DeleteResource(updater->recycled_resources_.back().resource_id); | 397 updater->DeleteResource(updater->recycled_resources_.back().resource_id); |
395 updater->recycled_resources_.pop_back(); | 398 updater->recycled_resources_.pop_back(); |
396 } | 399 } |
397 | 400 |
398 PlaneResource recycled_resource(data.resource_id, | 401 PlaneResource recycled_resource(data.resource_id, |
399 data.resource_size, | 402 data.resource_size, |
400 data.resource_format, | 403 data.resource_format, |
401 data.mailbox); | 404 data.mailbox); |
402 updater->recycled_resources_.push_back(recycled_resource); | 405 updater->recycled_resources_.push_back(recycled_resource); |
403 } | 406 } |
404 | 407 |
405 } // namespace cc | 408 } // namespace cc |
OLD | NEW |