summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/media/avda_codec_image.h
blob: 0ced55c5a58ec6fbd53cd3122fc039073a20fcc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_
#define CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_

#include "content/common/gpu/media/avda_shared_state.h"
#include "ui/gl/gl_image.h"

namespace content {

// GLImage that renders MediaCodec buffers to a SurfaceTexture as needed
// in order to draw them.
class AVDACodecImage : public gfx::GLImage {
 public:
  AVDACodecImage(const scoped_refptr<AVDASharedState>&,
                 media::VideoCodecBridge* codec,
                 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder,
                 const scoped_refptr<gfx::SurfaceTexture>& surface_texture);

 protected:
  ~AVDACodecImage() override;

 public:
  // gfx::GLImage implementation
  void Destroy(bool have_context) override;
  gfx::Size GetSize() override;
  unsigned GetInternalFormat() override;
  bool BindTexImage(unsigned target) override;
  void ReleaseTexImage(unsigned target) override;
  bool CopyTexImage(unsigned target) override;
  bool CopyTexSubImage(unsigned target,
                       const gfx::Point& offset,
                       const gfx::Rect& rect) override;
  bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
                            int z_order,
                            gfx::OverlayTransform transform,
                            const gfx::Rect& bounds_rect,
                            const gfx::RectF& crop_rect) override;
  void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
                    uint64_t process_tracing_id,
                    const std::string& dump_name) override;

 public:
  // Decoded buffer index that has the image for us to display.
  void SetMediaCodecBufferIndex(int buffer_index);

  // Return the codec buffer that we will return to the codec, or
  // <0 if there is no such buffer.
  int GetMediaCodecBufferIndex() const;

  // Set the size of the current image.
  void SetSize(const gfx::Size& size);

  void SetMediaCodec(media::MediaCodecBridge* codec);

 private:
  // Make sure that the surface texture's front buffer is current.
  // Returns true if the ST's texture was bound to the active unit.
  bool UpdateSurfaceTexture();

  // Attach the surface texture to our GL context, with a texture that we
  // create for it.
  void AttachSurfaceTextureToContext();

  // Shared state between the AVDA and all AVDACodecImages.
  scoped_refptr<AVDASharedState> shared_state_;

  // Codec's buffer index that we should render to the surface texture,
  // or <0 if none.
  int codec_buffer_index_;

  // Our image size.
  gfx::Size size_;

  // May be null.
  media::MediaCodecBridge* media_codec_;

  const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder_;

  const scoped_refptr<gfx::SurfaceTexture> surface_texture_;

  // Should we detach |surface_texture_| from its GL context when we are
  // deleted?  This happens when it's using our Texture's texture handle.
  bool detach_surface_texture_on_destruction_;

  DISALLOW_COPY_AND_ASSIGN(AVDACodecImage);
};

}  // namespace content

#endif  // CONTENT_COMMON_GPU_MEDIA_AVDA_CODEC_IMAGE_H_