summaryrefslogtreecommitdiffstats
path: root/gfx/gl/SharedSurfaceAndroidHardwareBuffer.h
blob: ef40ad622dc642046f8c1e06b02f4b4e03601ec3 (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
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef SHARED_SURFACE_ANDROID_HARDWARE_BUFFER_H_
#define SHARED_SURFACE_ANDROID_HARDWARE_BUFFER_H_

#include "mozilla/Attributes.h"
#include "mozilla/Mutex.h"
#include "CompositorTypes.h"
#include "SharedSurface.h"

namespace mozilla {

namespace layers {
class AndroidHardwareBuffer;
}  // namespace layers

namespace gl {

class SharedSurface_AndroidHardwareBuffer final : public SharedSurface {
 public:
  const UniquePtr<Texture> mTex;
  const RefPtr<layers::AndroidHardwareBuffer> mAndroidHardwareBuffer;
  EGLSync mSync = 0;

  static UniquePtr<SharedSurface_AndroidHardwareBuffer> Create(
      const SharedSurfaceDesc&);

 protected:
  SharedSurface_AndroidHardwareBuffer(
      const SharedSurfaceDesc&, UniquePtr<MozFramebuffer>, UniquePtr<Texture>,
      RefPtr<layers::AndroidHardwareBuffer> buffer);

 public:
  virtual ~SharedSurface_AndroidHardwareBuffer();

  void LockProdImpl() override {}
  void UnlockProdImpl() override {}

  void ProducerAcquireImpl() override {}
  void ProducerReleaseImpl() override;

  Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() override;

  void WaitForBufferOwnership() override;
};

class SurfaceFactory_AndroidHardwareBuffer final : public SurfaceFactory {
 public:
  static UniquePtr<SurfaceFactory_AndroidHardwareBuffer> Create(GLContext&);

 private:
  explicit SurfaceFactory_AndroidHardwareBuffer(
      const PartialSharedSurfaceDesc& desc)
      : SurfaceFactory(desc) {}

 public:
  virtual UniquePtr<SharedSurface> CreateSharedImpl(
      const SharedSurfaceDesc& desc) override {
    return SharedSurface_AndroidHardwareBuffer::Create(desc);
  }
};

}  // namespace gl

} /* namespace mozilla */

#endif /* SHARED_SURFACE_ANDROID_HARDWARE_BUFFER_H_ */