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 "gpu/command_buffer/client/gles2_interface.h" | 11 #include "gpu/command_buffer/client/gles2_interface.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "media/filters/skcanvas_video_renderer.h" | 13 #include "media/filters/skcanvas_video_renderer.h" |
14 #include "third_party/khronos/GLES2/gl2.h" | 14 #include "third_party/khronos/GLES2/gl2.h" |
15 #include "third_party/khronos/GLES2/gl2ext.h" | 15 #include "third_party/khronos/GLES2/gl2ext.h" |
16 #include "ui/gfx/size_conversions.h" | 16 #include "ui/gfx/size_conversions.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 namespace { | |
21 | |
20 const ResourceFormat kYUVResourceFormat = LUMINANCE_8; | 22 const ResourceFormat kYUVResourceFormat = LUMINANCE_8; |
21 const ResourceFormat kRGBResourceFormat = RGBA_8888; | 23 const ResourceFormat kRGBResourceFormat = RGBA_8888; |
22 | 24 |
25 class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { | |
26 public: | |
27 explicit SyncPointClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} | |
28 virtual ~SyncPointClientImpl() {} | |
29 virtual uint32 InsertSyncPoint() OVERRIDE { | |
30 return GLC(gl_, gl_->InsertSyncPointCHROMIUM()); | |
31 } | |
32 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { | |
33 GLC(gl_, gl_->WaitSyncPointCHROMIUM(sync_point)); | |
34 } | |
35 | |
36 private: | |
37 gpu::gles2::GLES2Interface* gl_; | |
38 }; | |
39 | |
40 } // namespace | |
41 | |
23 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} | 42 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} |
24 | 43 |
25 VideoFrameExternalResources::~VideoFrameExternalResources() {} | 44 VideoFrameExternalResources::~VideoFrameExternalResources() {} |
26 | 45 |
27 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, | 46 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, |
28 ResourceProvider* resource_provider) | 47 ResourceProvider* resource_provider) |
29 : context_provider_(context_provider), | 48 : context_provider_(context_provider), |
30 resource_provider_(resource_provider) { | 49 resource_provider_(resource_provider) { |
31 } | 50 } |
32 | 51 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 external_resources.mailboxes.push_back( | 295 external_resources.mailboxes.push_back( |
277 TextureMailbox(plane_resources[i].mailbox, GL_TEXTURE_2D, 0)); | 296 TextureMailbox(plane_resources[i].mailbox, GL_TEXTURE_2D, 0)); |
278 external_resources.release_callbacks.push_back( | 297 external_resources.release_callbacks.push_back( |
279 base::Bind(&RecycleResource, AsWeakPtr(), recycle_data)); | 298 base::Bind(&RecycleResource, AsWeakPtr(), recycle_data)); |
280 } | 299 } |
281 | 300 |
282 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 301 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
283 return external_resources; | 302 return external_resources; |
284 } | 303 } |
285 | 304 |
286 static void ReturnTexture(const scoped_refptr<media::VideoFrame>& frame, | 305 static void ReturnTexture(const scoped_refptr<media::VideoFrame>& video_frame, |
287 uint32 sync_point, | 306 base::WeakPtr<ContextProvider> context_provider, |
danakj
2014/07/10 17:09:15
Why not WeakPtr to the VideoResourceUpdater, and p
dshwang
2014/07/10 19:23:11
I was worried the last frame glitch before video_l
danakj
2014/07/10 20:00:48
We could pass on lost_resource=true to the videofr
| |
307 uint32 /* sync_point */, | |
danakj
2014/07/10 17:09:15
we don't comment out parameter names like this in
| |
288 bool lost_resource) { | 308 bool lost_resource) { |
289 frame->AppendReleaseSyncPoint(sync_point); | 309 DCHECK(context_provider.get() || lost_resource); |
310 if (lost_resource) | |
311 return; | |
danakj
2014/07/10 17:09:15
can you TODO that this lost_resource should be for
dshwang
2014/07/10 19:23:11
Yes, I'll update
| |
312 // VideoFrame::UpdateReleaseSyncPoint() creates new sync point using the same | |
313 // GL context which created the given |sync_point|, so discard the | |
314 // |sync_point|. | |
315 SyncPointClientImpl client(context_provider->ContextGL()); | |
316 video_frame->UpdateReleaseSyncPoint(&client); | |
290 } | 317 } |
291 | 318 |
292 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 319 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
293 const scoped_refptr<media::VideoFrame>& video_frame) { | 320 const scoped_refptr<media::VideoFrame>& video_frame) { |
294 media::VideoFrame::Format frame_format = video_frame->format(); | 321 media::VideoFrame::Format frame_format = video_frame->format(); |
295 | 322 |
296 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); | 323 DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); |
297 if (frame_format != media::VideoFrame::NATIVE_TEXTURE) | 324 if (frame_format != media::VideoFrame::NATIVE_TEXTURE) |
298 return VideoFrameExternalResources(); | 325 return VideoFrameExternalResources(); |
299 | 326 |
(...skipping 16 matching lines...) Expand all Loading... | |
316 default: | 343 default: |
317 NOTREACHED(); | 344 NOTREACHED(); |
318 return VideoFrameExternalResources(); | 345 return VideoFrameExternalResources(); |
319 } | 346 } |
320 | 347 |
321 external_resources.mailboxes.push_back( | 348 external_resources.mailboxes.push_back( |
322 TextureMailbox(mailbox_holder->mailbox, | 349 TextureMailbox(mailbox_holder->mailbox, |
323 mailbox_holder->texture_target, | 350 mailbox_holder->texture_target, |
324 mailbox_holder->sync_point)); | 351 mailbox_holder->sync_point)); |
325 external_resources.release_callbacks.push_back( | 352 external_resources.release_callbacks.push_back( |
326 base::Bind(&ReturnTexture, video_frame)); | 353 base::Bind(&ReturnTexture, video_frame, context_provider_->AsWeakPtr())); |
327 return external_resources; | 354 return external_resources; |
328 } | 355 } |
329 | 356 |
330 // static | 357 // static |
331 void VideoResourceUpdater::RecycleResource( | 358 void VideoResourceUpdater::RecycleResource( |
332 base::WeakPtr<VideoResourceUpdater> updater, | 359 base::WeakPtr<VideoResourceUpdater> updater, |
333 RecycleResourceData data, | 360 RecycleResourceData data, |
334 uint32 sync_point, | 361 uint32 sync_point, |
335 bool lost_resource) { | 362 bool lost_resource) { |
336 if (!updater.get()) { | 363 if (!updater.get()) { |
(...skipping 21 matching lines...) Expand all Loading... | |
358 } | 385 } |
359 | 386 |
360 PlaneResource recycled_resource(data.resource_id, | 387 PlaneResource recycled_resource(data.resource_id, |
361 data.resource_size, | 388 data.resource_size, |
362 data.resource_format, | 389 data.resource_format, |
363 data.mailbox); | 390 data.mailbox); |
364 updater->recycled_resources_.push_back(recycled_resource); | 391 updater->recycled_resources_.push_back(recycled_resource); |
365 } | 392 } |
366 | 393 |
367 } // namespace cc | 394 } // namespace cc |
OLD | NEW |