summaryrefslogtreecommitdiff
path: root/chromium/media/gpu/android/avda_surface_bundle.h
blob: 9ea45fa1583a329c5527c7063d3891499b0fa7e3 (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
// Copyright 2017 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 MEDIA_GPU_ANDROID_AVDA_SURFACE_BUNDLE_H_
#define MEDIA_GPU_ANDROID_AVDA_SURFACE_BUNDLE_H_

#include "base/memory/ref_counted_delete_on_sequence.h"
#include "media/base/android/android_overlay.h"
#include "media/gpu/android/surface_texture_gl_owner.h"
#include "media/gpu/media_gpu_export.h"
#include "ui/gl/android/scoped_java_surface.h"

namespace media {

// AVDASurfaceBundle is a Java surface, and the TextureOwner or Overlay that
// backs it.
//
// Once a MediaCodec is configured with an output surface, the corresponding
// AVDASurfaceBundle should be kept alive as long as the codec to prevent
// crashes due to the codec losing its output surface.
// TODO(watk): Remove AVDA from the name.
struct MEDIA_GPU_EXPORT AVDASurfaceBundle
    : public base::RefCountedDeleteOnSequence<AVDASurfaceBundle> {
 public:
  using ScheduleLayoutCB = base::RepeatingCallback<void(gfx::Rect)>;

  // Create an empty bundle to be manually populated.
  explicit AVDASurfaceBundle();
  explicit AVDASurfaceBundle(std::unique_ptr<AndroidOverlay> overlay);
  explicit AVDASurfaceBundle(scoped_refptr<TextureOwner> texture_owner);

  const base::android::JavaRef<jobject>& GetJavaSurface() const;

  // Returns a callback that can be used to position this overlay.  It must be
  // called on the correct thread for the overlay.  It will not keep a ref to
  // |this|; the cb will do nothing if |this| is destroyed.
  ScheduleLayoutCB GetScheduleLayoutCB();

  // The Overlay or TextureOwner.
  std::unique_ptr<AndroidOverlay> overlay;
  scoped_refptr<TextureOwner> texture_owner_;

  // The Java surface for |texture_owner_|.
  gl::ScopedJavaSurface texture_owner_surface;

 private:
  ~AVDASurfaceBundle();
  friend class base::RefCountedDeleteOnSequence<AVDASurfaceBundle>;
  friend class base::DeleteHelper<AVDASurfaceBundle>;

  void ScheduleLayout(gfx::Rect rect);

  base::WeakPtrFactory<AVDASurfaceBundle> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(AVDASurfaceBundle);
};

}  // namespace media

#endif  // MEDIA_GPU_ANDROID_AVDA_SURFACE_BUNDLE_H_