Revert 279472 "Mojo: Add mojo_shell_tests to the Linux bots."
[chromium-blink-merge.git] / cc / resources / video_resource_updater.h
blobeaaa8c10d69bf677c52c55689a495268d55ec06e
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 <vector>
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"
20 namespace media {
21 class SkCanvasVideoRenderer;
22 class VideoFrame;
25 namespace cc {
26 class ContextProvider;
27 class ResourceProvider;
29 class CC_EXPORT VideoFrameExternalResources {
30 public:
31 // Specifies what type of data is contained in the mailboxes, as well as how
32 // many mailboxes will be present.
33 enum ResourceType {
34 NONE,
35 YUV_RESOURCE,
36 RGB_RESOURCE,
37 STREAM_TEXTURE_RESOURCE,
38 IO_SURFACE,
40 #if defined(VIDEO_HOLE)
41 // TODO(danakj): Implement this with a solid color layer instead of a video
42 // frame and video layer.
43 HOLE,
44 #endif // defined(VIDEO_HOLE)
46 // TODO(danakj): Remove this and abstract TextureMailbox into
47 // "ExternalResource" that can hold a hardware or software backing.
48 SOFTWARE_RESOURCE
51 ResourceType type;
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> {
67 public:
68 explicit VideoResourceUpdater(ContextProvider* context_provider,
69 ResourceProvider* resource_provider);
70 ~VideoResourceUpdater();
72 VideoFrameExternalResources CreateExternalResourcesFromVideoFrame(
73 const scoped_refptr<media::VideoFrame>& video_frame);
75 private:
76 struct PlaneResource {
77 unsigned resource_id;
78 gfx::Size resource_size;
79 ResourceFormat resource_format;
80 gpu::Mailbox mailbox;
82 PlaneResource(unsigned resource_id,
83 const gfx::Size& resource_size,
84 ResourceFormat resource_format,
85 gpu::Mailbox mailbox)
86 : resource_id(resource_id),
87 resource_size(resource_size),
88 resource_format(resource_format),
89 mailbox(mailbox) {}
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,
107 uint32 sync_point,
108 bool lost_resource);
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);
120 } // namespace cc
122 #endif // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_