summaryrefslogtreecommitdiffstats
path: root/gfx/gl/SharedSurfaceD3D11Interop.h
blob: 960850c27ef93531285b20f303e758fc4e086c55 (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
/* -*- 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_D3D11_INTEROP_H_
#define SHARED_SURFACE_D3D11_INTEROP_H_

#include <d3d11.h>
#include <windows.h>
#include "SharedSurface.h"

namespace mozilla {

namespace gfx {
class FileHandleWrapper;
}  // namespace gfx

namespace gl {

class DXInterop2Device;
class GLContext;
class WGLLibrary;

class SharedSurface_D3D11Interop final : public SharedSurface {
 public:
  struct Data final {
    const RefPtr<DXInterop2Device> interop;
    HANDLE lockHandle;
    RefPtr<ID3D11Texture2D> texD3D;
    RefPtr<gfx::FileHandleWrapper> dxgiHandle;
    UniquePtr<Renderbuffer> interopRb;
    UniquePtr<MozFramebuffer> interopFbIfNeedsIndirect;
  };
  const Data mData;
  const bool mNeedsFinish;

 private:
  bool mLockedForGL = false;

 public:
  static UniquePtr<SharedSurface_D3D11Interop> Create(const SharedSurfaceDesc&,
                                                      DXInterop2Device*);

 private:
  SharedSurface_D3D11Interop(const SharedSurfaceDesc&,
                             UniquePtr<MozFramebuffer>&& fbForDrawing, Data&&);

 public:
  virtual ~SharedSurface_D3D11Interop();

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

  void ProducerAcquireImpl() override;
  void ProducerReleaseImpl() override;

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

class SurfaceFactory_D3D11Interop : public SurfaceFactory {
 public:
  const RefPtr<DXInterop2Device> mInterop;

  static UniquePtr<SurfaceFactory_D3D11Interop> Create(GLContext& gl);

 protected:
  SurfaceFactory_D3D11Interop(const PartialSharedSurfaceDesc&,
                              DXInterop2Device* interop);

 public:
  virtual ~SurfaceFactory_D3D11Interop();

 protected:
  UniquePtr<SharedSurface> CreateSharedImpl(
      const SharedSurfaceDesc& desc) override {
    return SharedSurface_D3D11Interop::Create(desc, mInterop);
  }
};

} /* namespace gl */
} /* namespace mozilla */

#endif /* SHARED_SURFACE_D3D11_INTEROP_H_ */