| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 : public base::SupportsWeakPtr<VideoResourceUpdater> { | 79 : public base::SupportsWeakPtr<VideoResourceUpdater> { |
| 80 public: | 80 public: |
| 81 VideoResourceUpdater(ContextProvider* context_provider, | 81 VideoResourceUpdater(ContextProvider* context_provider, |
| 82 ResourceProvider* resource_provider); | 82 ResourceProvider* resource_provider); |
| 83 ~VideoResourceUpdater(); | 83 ~VideoResourceUpdater(); |
| 84 | 84 |
| 85 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame( | 85 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame( |
| 86 scoped_refptr<media::VideoFrame> video_frame); | 86 scoped_refptr<media::VideoFrame> video_frame); |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 struct PlaneResource { | 89 class PlaneResource { |
| 90 unsigned resource_id; | 90 public: |
| 91 gfx::Size resource_size; | |
| 92 ResourceFormat resource_format; | |
| 93 gpu::Mailbox mailbox; | |
| 94 // The balance between the number of times this resource has been returned | |
| 95 // from CreateForSoftwarePlanes vs released in RecycleResource. | |
| 96 int ref_count; | |
| 97 // These last three members will be used for identifying the data stored in | |
| 98 // this resource, and uniquely identifies a media::VideoFrame plane. The | |
| 99 // frame pointer will only be used for pointer comparison, i.e. the | |
| 100 // underlying data will not be accessed. | |
| 101 const void* frame_ptr; | |
| 102 #if DCHECK_IS_ON() | |
| 103 // This is marked true when the orginal VideoFrame is destructed. It is | |
| 104 // used to detect clients that are not setting the VideoFrame's timestamp | |
| 105 // field correctly, as required. The memory allocator can and will re-use | |
| 106 // the same pointer for new VideoFrame instances, so a destruction observer | |
| 107 // is used to detect that. | |
| 108 bool destructed; | |
| 109 #endif | |
| 110 size_t plane_index; | |
| 111 base::TimeDelta timestamp; | |
| 112 | |
| 113 PlaneResource(unsigned resource_id, | 91 PlaneResource(unsigned resource_id, |
| 114 const gfx::Size& resource_size, | 92 const gfx::Size& resource_size, |
| 115 ResourceFormat resource_format, | 93 ResourceFormat resource_format, |
| 116 gpu::Mailbox mailbox); | 94 gpu::Mailbox mailbox); |
| 117 PlaneResource(const PlaneResource& other); | 95 PlaneResource(const PlaneResource& other); |
| 96 |
| 97 // Returns true if this resource matches the unique identifiers of another |
| 98 // VideoFrame resource. |
| 99 bool Matches(int unique_frame_id, size_t plane_index); |
| 100 |
| 101 // Sets the unique identifiers for this resource, may only be called when |
| 102 // there is a single reference to the resource (i.e. |ref_count_| == 1). |
| 103 void SetUniqueId(int unique_frame_id, size_t plane_index); |
| 104 |
| 105 // Accessors for resource identifiers provided at construction time. |
| 106 unsigned resource_id() const { return resource_id_; } |
| 107 const gfx::Size& resource_size() const { return resource_size_; } |
| 108 ResourceFormat resource_format() const { return resource_format_; } |
| 109 const gpu::Mailbox& mailbox() const { return mailbox_; } |
| 110 |
| 111 // Various methods for managing references. See |ref_count_| for details. |
| 112 void add_ref() { ++ref_count_; } |
| 113 void remove_ref() { --ref_count_; } |
| 114 void clear_refs() { ref_count_ = 0; } |
| 115 bool has_refs() const { return ref_count_ != 0; } |
| 116 |
| 117 private: |
| 118 // The balance between the number of times this resource has been returned |
| 119 // from CreateForSoftwarePlanes vs released in RecycleResource. |
| 120 int ref_count_ = 0; |
| 121 |
| 122 // These two members are used for identifying the data stored in this |
| 123 // resource; they uniquely identify a media::VideoFrame plane. |
| 124 int unique_frame_id_ = 0; |
| 125 size_t plane_index_ = 0u; |
| 126 // Indicates if the above two members have been set or not. |
| 127 bool has_unique_frame_id_and_plane_index_ = false; |
| 128 |
| 129 const unsigned resource_id_; |
| 130 const gfx::Size resource_size_; |
| 131 const ResourceFormat resource_format_; |
| 132 const gpu::Mailbox mailbox_; |
| 118 }; | 133 }; |
| 119 | 134 |
| 120 static bool PlaneResourceMatchesUniqueID(const PlaneResource& plane_resource, | |
| 121 const media::VideoFrame* video_frame, | |
| 122 size_t plane_index); | |
| 123 | |
| 124 static void SetPlaneResourceUniqueId(const media::VideoFrame* video_frame, | |
| 125 size_t plane_index, | |
| 126 PlaneResource* plane_resource); | |
| 127 | |
| 128 // This needs to be a container where iterators can be erased without | 135 // This needs to be a container where iterators can be erased without |
| 129 // invalidating other iterators. | 136 // invalidating other iterators. |
| 130 typedef std::list<PlaneResource> ResourceList; | 137 typedef std::list<PlaneResource> ResourceList; |
| 131 ResourceList::iterator AllocateResource(const gfx::Size& plane_size, | 138 ResourceList::iterator AllocateResource(const gfx::Size& plane_size, |
| 132 ResourceFormat format, | 139 ResourceFormat format, |
| 133 bool has_mailbox, | 140 bool has_mailbox, |
| 134 bool immutable_hint); | 141 bool immutable_hint); |
| 135 void DeleteResource(ResourceList::iterator resource_it); | 142 void DeleteResource(ResourceList::iterator resource_it); |
| 136 void CopyPlaneTexture(media::VideoFrame* video_frame, | 143 void CopyPlaneTexture(media::VideoFrame* video_frame, |
| 137 const gpu::MailboxHolder& mailbox_holder, | 144 const gpu::MailboxHolder& mailbox_holder, |
| 138 VideoFrameExternalResources* external_resources); | 145 VideoFrameExternalResources* external_resources); |
| 139 VideoFrameExternalResources CreateForHardwarePlanes( | 146 VideoFrameExternalResources CreateForHardwarePlanes( |
| 140 scoped_refptr<media::VideoFrame> video_frame); | 147 scoped_refptr<media::VideoFrame> video_frame); |
| 141 VideoFrameExternalResources CreateForSoftwarePlanes( | 148 VideoFrameExternalResources CreateForSoftwarePlanes( |
| 142 scoped_refptr<media::VideoFrame> video_frame); | 149 scoped_refptr<media::VideoFrame> video_frame); |
| 143 | 150 |
| 144 static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater, | 151 static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater, |
| 145 unsigned resource_id, | 152 unsigned resource_id, |
| 146 const gpu::SyncToken& sync_token, | 153 const gpu::SyncToken& sync_token, |
| 147 bool lost_resource, | 154 bool lost_resource, |
| 148 BlockingTaskRunner* main_thread_task_runner); | 155 BlockingTaskRunner* main_thread_task_runner); |
| 149 static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater, | 156 static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater, |
| 150 const scoped_refptr<media::VideoFrame>& video_frame, | 157 const scoped_refptr<media::VideoFrame>& video_frame, |
| 151 const gpu::SyncToken& sync_token, | 158 const gpu::SyncToken& sync_token, |
| 152 bool lost_resource, | 159 bool lost_resource, |
| 153 BlockingTaskRunner* main_thread_task_runner); | 160 BlockingTaskRunner* main_thread_task_runner); |
| 154 #if DCHECK_IS_ON() | |
| 155 // Mark the |destructed| as true when the orginal VideoFrame is destructed. | |
| 156 static void MarkOldResource(base::WeakPtr<VideoResourceUpdater> updater, | |
| 157 const media::VideoFrame* video_frame_ptr, | |
| 158 base::TimeDelta timestamp); | |
| 159 #endif | |
| 160 | 161 |
| 161 ContextProvider* context_provider_; | 162 ContextProvider* context_provider_; |
| 162 ResourceProvider* resource_provider_; | 163 ResourceProvider* resource_provider_; |
| 163 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; | 164 std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_; |
| 164 std::vector<uint8_t> upload_pixels_; | 165 std::vector<uint8_t> upload_pixels_; |
| 165 | 166 |
| 166 // Recycle resources so that we can reduce the number of allocations and | 167 // Recycle resources so that we can reduce the number of allocations and |
| 167 // data transfers. | 168 // data transfers. |
| 168 ResourceList all_resources_; | 169 ResourceList all_resources_; |
| 169 | 170 |
| 170 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater); | 171 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater); |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 } // namespace cc | 174 } // namespace cc |
| 174 | 175 |
| 175 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ | 176 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_ |
| OLD | NEW |