1 // Copyright (c) 2011 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 MEDIA_VIDEO_PICTURE_H_
6 #define MEDIA_VIDEO_PICTURE_H_
7 
8 #include <stdint.h>
9 
10 #include <vector>
11 
12 #include "gpu/command_buffer/common/mailbox.h"
13 #include "media/base/media_export.h"
14 #include "media/base/video_types.h"
15 #include "ui/gfx/color_space.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/size.h"
18 
19 namespace media {
20 
21 // A picture buffer that is composed of one or more GLES2 textures.
22 // This is the media-namespace equivalent of PP_PictureBuffer_Dev.
23 class MEDIA_EXPORT PictureBuffer {
24  public:
25   using TextureIds = std::vector<uint32_t>;
26 
27   PictureBuffer(int32_t id, const gfx::Size& size);
28   PictureBuffer(int32_t id,
29                 const gfx::Size& size,
30                 const TextureIds& client_texture_ids);
31   PictureBuffer(int32_t id,
32                 const gfx::Size& size,
33                 const TextureIds& client_texture_ids,
34                 const TextureIds& service_texture_ids,
35                 uint32_t texture_target,
36                 VideoPixelFormat pixel_format);
37   PictureBuffer(int32_t id,
38                 const gfx::Size& size,
39                 const TextureIds& client_texture_ids,
40                 const std::vector<gpu::Mailbox>& texture_mailboxes,
41                 uint32_t texture_target,
42                 VideoPixelFormat pixel_format);
43   PictureBuffer(const PictureBuffer& other);
44   ~PictureBuffer();
45 
46   // Returns the client-specified id of the buffer.
id()47   int32_t id() const { return id_; }
48 
49   // Returns the size of the buffer.
size()50   gfx::Size size() const { return size_; }
51 
set_size(const gfx::Size & size)52   void set_size(const gfx::Size& size) { size_ = size; }
53 
54   // The client texture ids, i.e., those returned by Chrome's GL service.
client_texture_ids()55   const TextureIds& client_texture_ids() const { return client_texture_ids_; }
56 
57   // The service texture ids, i.e., the real platform ids corresponding to
58   // |client_texture_ids|.
service_texture_ids()59   const TextureIds& service_texture_ids() const { return service_texture_ids_; }
60 
texture_target()61   uint32_t texture_target() const { return texture_target_; }
62 
pixel_format()63   VideoPixelFormat pixel_format() const { return pixel_format_; }
64 
65   gpu::Mailbox texture_mailbox(size_t plane) const;
66 
67  private:
68   int32_t id_;
69   gfx::Size size_;
70   TextureIds client_texture_ids_;
71   TextureIds service_texture_ids_;
72   std::vector<gpu::Mailbox> texture_mailboxes_;
73   uint32_t texture_target_ = 0;
74   VideoPixelFormat pixel_format_ = PIXEL_FORMAT_UNKNOWN;
75 };
76 
77 // A decoded picture frame.
78 // This is the media-namespace equivalent of PP_Picture_Dev.
79 class MEDIA_EXPORT Picture {
80  public:
81   // Defaults |size_changed_| to false. Size changed is currently only used
82   // by AVDA and is set via set_size_changd().
83   Picture(int32_t picture_buffer_id,
84           int32_t bitstream_buffer_id,
85           const gfx::Rect& visible_rect,
86           const gfx::ColorSpace& color_space,
87           bool allow_overlay);
88   Picture(const Picture&);
89   ~Picture();
90 
91   // Returns the id of the picture buffer where this picture is contained.
picture_buffer_id()92   int32_t picture_buffer_id() const { return picture_buffer_id_; }
93 
94   // Returns the id of the bitstream buffer from which this frame was decoded.
bitstream_buffer_id()95   int32_t bitstream_buffer_id() const { return bitstream_buffer_id_; }
96 
97   // Returns the color space of the picture.
color_space()98   const gfx::ColorSpace& color_space() const { return color_space_; }
99 
100   // Returns the visible rectangle of the picture. Its size may be smaller
101   // than the size of the PictureBuffer, as it is the only visible part of the
102   // Picture contained in the PictureBuffer.
visible_rect()103   gfx::Rect visible_rect() const { return visible_rect_; }
104 
allow_overlay()105   bool allow_overlay() const { return allow_overlay_; }
106 
read_lock_fences_enabled()107   bool read_lock_fences_enabled() const { return read_lock_fences_enabled_; }
108 
set_read_lock_fences_enabled(bool read_lock_fences_enabled)109   void set_read_lock_fences_enabled(bool read_lock_fences_enabled) {
110     read_lock_fences_enabled_ = read_lock_fences_enabled;
111   }
112 
113   // Returns true when the VDA has adjusted the resolution of this Picture
114   // without requesting new PictureBuffers. GpuVideoDecoder should read this
115   // as a signal to update the size of the corresponding PicutreBuffer using
116   // visible_rect() upon receiving this Picture from a VDA.
size_changed()117   bool size_changed() const { return size_changed_; }
118 
set_size_changed(bool size_changed)119   void set_size_changed(bool size_changed) { size_changed_ = size_changed; }
120 
texture_owner()121   bool texture_owner() const { return texture_owner_; }
122 
set_texture_owner(bool texture_owner)123   void set_texture_owner(bool texture_owner) { texture_owner_ = texture_owner; }
124 
wants_promotion_hint()125   bool wants_promotion_hint() const { return wants_promotion_hint_; }
126 
set_wants_promotion_hint(bool wants_promotion_hint)127   void set_wants_promotion_hint(bool wants_promotion_hint) {
128     wants_promotion_hint_ = wants_promotion_hint;
129   }
130 
131  private:
132   int32_t picture_buffer_id_;
133   int32_t bitstream_buffer_id_;
134   gfx::Rect visible_rect_;
135   gfx::ColorSpace color_space_;
136   bool allow_overlay_;
137   bool read_lock_fences_enabled_;
138   bool size_changed_;
139   bool texture_owner_;
140   bool wants_promotion_hint_;
141 };
142 
143 }  // namespace media
144 
145 #endif  // MEDIA_VIDEO_PICTURE_H_
146