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 #ifndef CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | 5 #ifndef CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ |
6 #define CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | 6 #define CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ |
7 | 7 |
| 8 #include <list> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "cc/base/cc_export.h" | 15 #include "cc/base/cc_export.h" |
15 #include "cc/resources/release_callback_impl.h" | 16 #include "cc/resources/release_callback_impl.h" |
16 #include "cc/resources/resource_format.h" | 17 #include "cc/resources/resource_format.h" |
17 #include "cc/resources/texture_mailbox.h" | 18 #include "cc/resources/texture_mailbox.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 72 |
72 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame( | 73 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame( |
73 const scoped_refptr<media::VideoFrame>& video_frame); | 74 const scoped_refptr<media::VideoFrame>& video_frame); |
74 | 75 |
75 private: | 76 private: |
76 struct PlaneResource { | 77 struct PlaneResource { |
77 unsigned resource_id; | 78 unsigned resource_id; |
78 gfx::Size resource_size; | 79 gfx::Size resource_size; |
79 ResourceFormat resource_format; | 80 ResourceFormat resource_format; |
80 gpu::Mailbox mailbox; | 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; |
81 // These last three members will be used for identifying the data stored in | 85 // These last three members will be used for identifying the data stored in |
82 // this resource, and uniquely identifies a media::VideoFrame plane. The | 86 // this resource, and uniquely identifies a media::VideoFrame plane. The |
83 // frame pointer will only be used for pointer comparison, i.e. the | 87 // frame pointer will only be used for pointer comparison, i.e. the |
84 // underlying data will not be accessed. | 88 // underlying data will not be accessed. |
85 const void* frame_ptr; | 89 const void* frame_ptr; |
86 int plane_index; | 90 int plane_index; |
87 base::TimeDelta timestamp; | 91 base::TimeDelta timestamp; |
88 | 92 |
89 PlaneResource(unsigned resource_id, | 93 PlaneResource(unsigned resource_id, |
90 const gfx::Size& resource_size, | 94 const gfx::Size& resource_size, |
91 ResourceFormat resource_format, | 95 ResourceFormat resource_format, |
92 gpu::Mailbox mailbox); | 96 gpu::Mailbox mailbox); |
93 }; | 97 }; |
94 | 98 |
95 static bool PlaneResourceMatchesUniqueID(const PlaneResource& plane_resource, | 99 static bool PlaneResourceMatchesUniqueID(const PlaneResource& plane_resource, |
96 const media::VideoFrame* video_frame, | 100 const media::VideoFrame* video_frame, |
97 int plane_index); | 101 int plane_index); |
98 | 102 |
99 static void SetPlaneResourceUniqueId(const media::VideoFrame* video_frame, | 103 static void SetPlaneResourceUniqueId(const media::VideoFrame* video_frame, |
100 int plane_index, | 104 int plane_index, |
101 PlaneResource* plane_resource); | 105 PlaneResource* plane_resource); |
102 | 106 |
103 void DeleteResource(unsigned resource_id); | 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); |
104 bool VerifyFrame(const scoped_refptr<media::VideoFrame>& video_frame); | 114 bool VerifyFrame(const scoped_refptr<media::VideoFrame>& video_frame); |
105 VideoFrameExternalResources CreateForHardwarePlanes( | 115 VideoFrameExternalResources CreateForHardwarePlanes( |
106 const scoped_refptr<media::VideoFrame>& video_frame); | 116 const scoped_refptr<media::VideoFrame>& video_frame); |
107 VideoFrameExternalResources CreateForSoftwarePlanes( | 117 VideoFrameExternalResources CreateForSoftwarePlanes( |
108 const scoped_refptr<media::VideoFrame>& video_frame); | 118 const scoped_refptr<media::VideoFrame>& video_frame); |
109 | 119 |
110 static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater, | 120 static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater, |
111 PlaneResource data, | 121 unsigned resource_id, |
112 uint32 sync_point, | 122 uint32 sync_point, |
113 bool lost_resource, | 123 bool lost_resource, |
114 BlockingTaskRunner* main_thread_task_runner); | 124 BlockingTaskRunner* main_thread_task_runner); |
115 static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater, | 125 static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater, |
116 const scoped_refptr<media::VideoFrame>& video_frame, | 126 const scoped_refptr<media::VideoFrame>& video_frame, |
117 uint32 sync_point, | 127 uint32 sync_point, |
118 bool lost_resource, | 128 bool lost_resource, |
119 BlockingTaskRunner* main_thread_task_runner); | 129 BlockingTaskRunner* main_thread_task_runner); |
120 | 130 |
121 ContextProvider* context_provider_; | 131 ContextProvider* context_provider_; |
122 ResourceProvider* resource_provider_; | 132 ResourceProvider* resource_provider_; |
123 scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_; | 133 scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_; |
124 | 134 |
125 std::vector<unsigned> all_resources_; | |
126 // Recycle resources so that we can reduce the number of allocations and | 135 // Recycle resources so that we can reduce the number of allocations and |
127 // data transfers. | 136 // data transfers. |
128 std::vector<PlaneResource> recycled_resources_; | 137 ResourceList all_resources_; |
129 | 138 |
130 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater); | 139 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater); |
131 }; | 140 }; |
132 | 141 |
133 } // namespace cc | 142 } // namespace cc |
134 | 143 |
135 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | 144 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ |
OLD | NEW |