summaryrefslogtreecommitdiffstats
path: root/gfx/layers/opengl/TextureClientOGL.h
blob: 7e10e4611c9e6730240dfc234a119e2c07399b92 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 MOZILLA_GFX_TEXTURECLIENTOGL_H
#define MOZILLA_GFX_TEXTURECLIENTOGL_H

#include "GLContextTypes.h"  // for SharedTextureHandle, etc
#include "GLImages.h"
#include "gfxTypes.h"
#include "mozilla/Attributes.h"  // for override
#include "mozilla/gfx/Point.h"   // for IntSize
#include "mozilla/gfx/Types.h"   // for SurfaceFormat
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
#include "mozilla/layers/TextureClient.h"   // for TextureClient, etc
#ifdef MOZ_WIDGET_ANDROID
#  include "AndroidSurfaceTexture.h"
#  include "AndroidNativeWindow.h"
#  include "mozilla/java/GeckoSurfaceWrappers.h"
#  include "mozilla/layers/AndroidHardwareBuffer.h"
#endif

namespace mozilla {

namespace gfx {

class DrawTarget;

}  // namespace gfx

namespace layers {

#ifdef MOZ_WIDGET_ANDROID

class AndroidHardwareBuffer;

class AndroidSurfaceTextureData : public TextureData {
 public:
  static already_AddRefed<TextureClient> CreateTextureClient(
      AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous,
      gl::OriginPos aOriginPos, bool aHasAlpha,
      Maybe<gfx::Matrix4x4> aTransformOverride, LayersIPCChannel* aAllocator,
      TextureFlags aFlags);

  virtual ~AndroidSurfaceTextureData();

  void FillInfo(TextureData::Info& aInfo) const override;

  bool Serialize(SurfaceDescriptor& aOutDescriptor) override;

  // Useless functions.
  bool Lock(OpenMode) override { return true; }

  void Unlock() override {}

  // Our data is always owned externally.
  void Deallocate(LayersIPCChannel*) override {}

 protected:
  AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle,
                            gfx::IntSize aSize, bool aContinuous,
                            bool aHasAlpha,
                            Maybe<gfx::Matrix4x4> aTransformOverride);

  const AndroidSurfaceTextureHandle mHandle;
  const gfx::IntSize mSize;
  const bool mContinuous;
  const bool mHasAlpha;
  const Maybe<gfx::Matrix4x4> mTransformOverride;
};

class AndroidNativeWindowTextureData : public TextureData {
 public:
  static AndroidNativeWindowTextureData* Create(gfx::IntSize aSize,
                                                gfx::SurfaceFormat aFormat);

  void FillInfo(TextureData::Info& aInfo) const override;

  bool Serialize(SurfaceDescriptor& aOutDescriptor) override;

  bool Lock(OpenMode) override;
  void Unlock() override;

  void Forget(LayersIPCChannel*) override;
  void Deallocate(LayersIPCChannel*) override {}

  already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;

  void OnForwardedToHost() override;

 protected:
  AndroidNativeWindowTextureData(java::GeckoSurface::Param aSurface,
                                 gfx::IntSize aSize,
                                 gfx::SurfaceFormat aFormat);

 private:
  java::GeckoSurface::GlobalRef mSurface;
  ANativeWindow* mNativeWindow;
  ANativeWindow_Buffer mBuffer;
  // Keeps track of whether the underlying NativeWindow is actually locked.
  bool mIsLocked;

  const gfx::IntSize mSize;
  const gfx::SurfaceFormat mFormat;
};

class AndroidHardwareBufferTextureData : public TextureData {
 public:
  static AndroidHardwareBufferTextureData* Create(gfx::IntSize aSize,
                                                  gfx::SurfaceFormat aFormat);

  virtual ~AndroidHardwareBufferTextureData();

  void FillInfo(TextureData::Info& aInfo) const override;

  bool Serialize(SurfaceDescriptor& aOutDescriptor) override;

  bool Lock(OpenMode aMode) override;
  void Unlock() override;

  void Forget(LayersIPCChannel*) override;
  void Deallocate(LayersIPCChannel*) override {}

  already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;

  void OnForwardedToHost() override;

  TextureFlags GetTextureFlags() const override;

  Maybe<uint64_t> GetBufferId() const override;

  mozilla::ipc::FileDescriptor GetAcquireFence() override;

  AndroidHardwareBufferTextureData* AsAndroidHardwareBufferTextureData()
      override {
    return this;
  }

  AndroidHardwareBuffer* GetBuffer() { return mAndroidHardwareBuffer; }

 protected:
  AndroidHardwareBufferTextureData(
      AndroidHardwareBuffer* aAndroidHardwareBuffer, gfx::IntSize aSize,
      gfx::SurfaceFormat aFormat);

  RefPtr<AndroidHardwareBuffer> mAndroidHardwareBuffer;
  const gfx::IntSize mSize;
  const gfx::SurfaceFormat mFormat;

  void* mAddress;

  // Keeps track of whether the underlying NativeWindow is actually locked.
  bool mIsLocked;
};

#endif  // MOZ_WIDGET_ANDROID

}  // namespace layers
}  // namespace mozilla

#endif