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
3 // found in the LICENSE file.
5 #ifndef CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
6 #define CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "cc/base/cc_export.h"
15 #include "cc/resources/release_callback.h"
16 #include "cc/resources/resource_format.h"
17 #include "cc/resources/texture_mailbox.h"
18 #include "ui/gfx/size.h"
21 class SkCanvasVideoRenderer
;
26 class ContextProvider
;
27 class ResourceProvider
;
29 class CC_EXPORT VideoFrameExternalResources
{
31 // Specifies what type of data is contained in the mailboxes, as well as how
32 // many mailboxes will be present.
37 STREAM_TEXTURE_RESOURCE
,
40 #if defined(VIDEO_HOLE)
41 // TODO(danakj): Implement this with a solid color layer instead of a video
42 // frame and video layer.
44 #endif // defined(VIDEO_HOLE)
46 // TODO(danakj): Remove this and abstract TextureMailbox into
47 // "ExternalResource" that can hold a hardware or software backing.
52 std::vector
<TextureMailbox
> mailboxes
;
53 std::vector
<ReleaseCallback
> release_callbacks
;
55 // TODO(danakj): Remove these too.
56 std::vector
<unsigned> software_resources
;
57 ReleaseCallback software_release_callback
;
59 VideoFrameExternalResources();
60 ~VideoFrameExternalResources();
63 // VideoResourceUpdater is by the video system to produce frame content as
64 // resources consumable by the compositor.
65 class CC_EXPORT VideoResourceUpdater
66 : public base::SupportsWeakPtr
<VideoResourceUpdater
> {
68 explicit VideoResourceUpdater(ContextProvider
* context_provider
,
69 ResourceProvider
* resource_provider
);
70 ~VideoResourceUpdater();
72 VideoFrameExternalResources
CreateExternalResourcesFromVideoFrame(
73 const scoped_refptr
<media::VideoFrame
>& video_frame
);
76 struct PlaneResource
{
78 gfx::Size resource_size
;
79 ResourceFormat resource_format
;
82 PlaneResource(unsigned resource_id
,
83 const gfx::Size
& resource_size
,
84 ResourceFormat resource_format
,
86 : resource_id(resource_id
),
87 resource_size(resource_size
),
88 resource_format(resource_format
),
92 void DeleteResource(unsigned resource_id
);
93 bool VerifyFrame(const scoped_refptr
<media::VideoFrame
>& video_frame
);
94 VideoFrameExternalResources
CreateForHardwarePlanes(
95 const scoped_refptr
<media::VideoFrame
>& video_frame
);
96 VideoFrameExternalResources
CreateForSoftwarePlanes(
97 const scoped_refptr
<media::VideoFrame
>& video_frame
);
99 struct RecycleResourceData
{
100 unsigned resource_id
;
101 gfx::Size resource_size
;
102 ResourceFormat resource_format
;
103 gpu::Mailbox mailbox
;
105 static void RecycleResource(base::WeakPtr
<VideoResourceUpdater
> updater
,
106 RecycleResourceData data
,
110 ContextProvider
* context_provider_
;
111 ResourceProvider
* resource_provider_
;
112 scoped_ptr
<media::SkCanvasVideoRenderer
> video_renderer_
;
114 std::vector
<unsigned> all_resources_
;
115 std::vector
<PlaneResource
> recycled_resources_
;
117 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater
);
122 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_