Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / resources / video_resource_updater.h
blob13f81b8f06e98bddb043979062a4d7a573367f61
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_
8 #include <list>
9 #include <vector>
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"
21 namespace media {
22 class SkCanvasVideoRenderer;
23 class VideoFrame;
26 namespace cc {
27 class ContextProvider;
28 class ResourceProvider;
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 RGBA_RESOURCE,
39 STREAM_TEXTURE_RESOURCE,
40 IO_SURFACE,
42 #if defined(VIDEO_HOLE)
43 // TODO(danakj): Implement this with a solid color layer instead of a video
44 // frame and video layer.
45 HOLE,
46 #endif // defined(VIDEO_HOLE)
48 // TODO(danakj): Remove this and abstract TextureMailbox into
49 // "ExternalResource" that can hold a hardware or software backing.
50 SOFTWARE_RESOURCE
53 ResourceType type;
54 std::vector<TextureMailbox> mailboxes;
55 std::vector<ReleaseCallbackImpl> release_callbacks;
57 // TODO(danakj): Remove these too.
58 std::vector<unsigned> software_resources;
59 ReleaseCallbackImpl software_release_callback;
61 VideoFrameExternalResources();
62 ~VideoFrameExternalResources();
65 // VideoResourceUpdater is used by the video system to produce frame content as
66 // resources consumable by the compositor.
67 class CC_EXPORT VideoResourceUpdater
68 : public base::SupportsWeakPtr<VideoResourceUpdater> {
69 public:
70 VideoResourceUpdater(ContextProvider* context_provider,
71 ResourceProvider* resource_provider);
72 ~VideoResourceUpdater();
74 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame(
75 const scoped_refptr<media::VideoFrame>& video_frame);
77 private:
78 struct PlaneResource {
79 unsigned resource_id;
80 gfx::Size resource_size;
81 ResourceFormat resource_format;
82 gpu::Mailbox mailbox;
83 // The balance between the number of times this resource has been returned
84 // from CreateForSoftwarePlanes vs released in RecycleResource.
85 int ref_count;
86 // These last three members will be used for identifying the data stored in
87 // this resource, and uniquely identifies a media::VideoFrame plane. The
88 // frame pointer will only be used for pointer comparison, i.e. the
89 // underlying data will not be accessed.
90 const void* frame_ptr;
91 int plane_index;
92 base::TimeDelta timestamp;
94 PlaneResource(unsigned resource_id,
95 const gfx::Size& resource_size,
96 ResourceFormat resource_format,
97 gpu::Mailbox mailbox);
100 static bool PlaneResourceMatchesUniqueID(const PlaneResource& plane_resource,
101 const media::VideoFrame* video_frame,
102 int plane_index);
104 static void SetPlaneResourceUniqueId(const media::VideoFrame* video_frame,
105 int plane_index,
106 PlaneResource* plane_resource);
108 // This needs to be a container where iterators can be erased without
109 // invalidating other iterators.
110 typedef std::list<PlaneResource> ResourceList;
111 ResourceList::iterator AllocateResource(const gfx::Size& plane_size,
112 ResourceFormat format,
113 bool has_mailbox);
114 void DeleteResource(ResourceList::iterator resource_it);
115 bool VerifyFrame(const scoped_refptr<media::VideoFrame>& video_frame);
116 VideoFrameExternalResources CreateForHardwarePlanes(
117 const scoped_refptr<media::VideoFrame>& video_frame);
118 VideoFrameExternalResources CreateForSoftwarePlanes(
119 const scoped_refptr<media::VideoFrame>& video_frame);
121 static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater,
122 unsigned resource_id,
123 uint32 sync_point,
124 bool lost_resource,
125 BlockingTaskRunner* main_thread_task_runner);
126 static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater,
127 const scoped_refptr<media::VideoFrame>& video_frame,
128 uint32 sync_point,
129 bool lost_resource,
130 BlockingTaskRunner* main_thread_task_runner);
132 ContextProvider* context_provider_;
133 ResourceProvider* resource_provider_;
134 scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_;
135 std::vector<uint8_t> upload_pixels_;
137 // Recycle resources so that we can reduce the number of allocations and
138 // data transfers.
139 ResourceList all_resources_;
141 DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater);
144 } // namespace cc
146 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_