OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | |
6 #define CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | |
7 | |
8 #include <list> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/time/time.h" | |
15 #include "cc/base/cc_export.h" | |
16 #include "cc/resources/release_callback_impl.h" | |
17 #include "cc/resources/resource_format.h" | |
18 #include "cc/resources/texture_mailbox.h" | |
19 #include "ui/gfx/geometry/size.h" | |
20 | |
21 namespace media { | |
22 class SkCanvasVideoRenderer; | |
23 class VideoFrame; | |
24 } | |
25 | |
26 namespace cc { | |
27 class ContextProvider; | |
28 class ResourceProvider; | |
29 | |
30 class CC_EXPORT VideoFrameExternalResources { | |
31 public: | |
32 // Specifies what type of data is contained in the mailboxes, as well as how | |
33 // many mailboxes will be present. | |
34 enum ResourceType { | |
35 NONE, | |
36 YUV_RESOURCE, | |
37 RGB_RESOURCE, | |
38 STREAM_TEXTURE_RESOURCE, | |
39 IO_SURFACE, | |
40 | |
41 #if defined(VIDEO_HOLE) | |
42 // TODO(danakj): Implement this with a solid color layer instead of a video | |
43 // frame and video layer. | |
44 HOLE, | |
45 #endif // defined(VIDEO_HOLE) | |
46 | |
47 // TODO(danakj): Remove this and abstract TextureMailbox into | |
48 // "ExternalResource" that can hold a hardware or software backing. | |
49 SOFTWARE_RESOURCE | |
50 }; | |
51 | |
52 ResourceType type; | |
53 std::vector<TextureMailbox> mailboxes; | |
54 std::vector<ReleaseCallbackImpl> release_callbacks; | |
55 | |
56 // TODO(danakj): Remove these too. | |
57 std::vector<unsigned> software_resources; | |
58 ReleaseCallbackImpl software_release_callback; | |
59 | |
60 VideoFrameExternalResources(); | |
61 ~VideoFrameExternalResources(); | |
62 }; | |
63 | |
64 // VideoResourceUpdater is used by the video system to produce frame content as | |
65 // resources consumable by the compositor. | |
66 class CC_EXPORT VideoResourceUpdater | |
67 : public base::SupportsWeakPtr<VideoResourceUpdater> { | |
68 public: | |
69 VideoResourceUpdater(ContextProvider* context_provider, | |
70 ResourceProvider* resource_provider); | |
71 ~VideoResourceUpdater(); | |
72 | |
73 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame( | |
74 const scoped_refptr<media::VideoFrame>& video_frame); | |
75 | |
76 private: | |
77 struct PlaneResource { | |
78 unsigned resource_id; | |
79 gfx::Size resource_size; | |
80 ResourceFormat resource_format; | |
81 gpu::Mailbox mailbox; | |
82 // The balance between the number of times this resource has been returned | |
83 // from CreateForSoftwarePlanes vs released in RecycleResource. | |
84 int ref_count; | |
85 // These last three members will be used for identifying the data stored in | |
86 // this resource, and uniquely identifies a media::VideoFrame plane. The | |
87 // frame pointer will only be used for pointer comparison, i.e. the | |
88 // underlying data will not be accessed. | |
89 const void* frame_ptr; | |
90 int plane_index; | |
91 base::TimeDelta timestamp; | |
92 | |
93 PlaneResource(unsigned resource_id, | |
94 const gfx::Size& resource_size, | |
95 ResourceFormat resource_format, | |
96 gpu::Mailbox mailbox); | |
97 }; | |
98 | |
99 static bool PlaneResourceMatchesUniqueID(const PlaneResource& plane_resource, | |
100 const media::VideoFrame* video_frame, | |
101 int plane_index); | |
102 | |
103 static void SetPlaneResourceUniqueId(const media::VideoFrame* video_frame, | |
104 int plane_index, | |
105 PlaneResource* plane_resource); | |
106 | |
107 // This needs to be a container where iterators can be erased without | |
108 // invalidating other iterators. | |
109 typedef std::list<PlaneResource> ResourceList; | |
110 ResourceList::iterator AllocateResource(const gfx::Size& plane_size, | |
111 ResourceFormat format, | |
112 bool has_mailbox); | |
113 void DeleteResource(ResourceList::iterator resource_it); | |
114 bool VerifyFrame(const scoped_refptr<media::VideoFrame>& video_frame); | |
115 VideoFrameExternalResources CreateForHardwarePlanes( | |
116 const scoped_refptr<media::VideoFrame>& video_frame); | |
117 VideoFrameExternalResources CreateForSoftwarePlanes( | |
118 const scoped_refptr<media::VideoFrame>& video_frame); | |
119 | |
120 static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater, | |
121 unsigned resource_id, | |
122 uint32 sync_point, | |
123 bool lost_resource, | |
124 BlockingTaskRunner* main_thread_task_runner); | |
125 static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater, | |
126 const scoped_refptr<media::VideoFrame>& video_frame, | |
127 uint32 sync_point, | |
128 bool lost_resource, | |
129 BlockingTaskRunner* main_thread_task_runner); | |
130 | |
131 ContextProvider* context_provider_; | |
132 ResourceProvider* resource_provider_; | |
133 scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_; | |
134 std::vector<uint8_t> upload_pixels_; | |
135 | |
136 // Recycle resources so that we can reduce the number of allocations and | |
137 // data transfers. | |
138 ResourceList all_resources_; | |
139 | |
140 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater); | |
141 }; | |
142 | |
143 } // namespace cc | |
144 | |
145 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | |
OLD | NEW |