summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/media/gpu_video_decode_accelerator_factory_impl.h
blob: de3db4c42f42dd9b4961d1dffd8ca07d81afe8d9 (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
// Copyright 2016 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_GPU_VIDEO_DECODE_ACCELERATOR_FACTORY_IMPL_H_
#define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_FACTORY_IMPL_H_

#include "base/callback.h"
#include "base/threading/thread_checker.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/config/gpu_info.h"
#include "media/video/video_decode_accelerator.h"

namespace gfx {
class GLContext;
}

namespace gl {
class GLImage;
}

namespace gpu {
struct GpuPreferences;

namespace gles2 {
class GLES2Decoder;
}
}

namespace content {

// TODO(posciak): this class should be an implementation of
// content::GpuVideoDecodeAcceleratorFactory, however that can only be achieved
// once this is moved out of content/common, see crbug.com/597150 and related.
class GpuVideoDecodeAcceleratorFactoryImpl {
 public:
  ~GpuVideoDecodeAcceleratorFactoryImpl();

  // Return current GLContext.
  using GetGLContextCallback = base::Callback<gfx::GLContext*(void)>;

  // Make the applicable GL context current. To be called by VDAs before
  // executing any GL calls. Return true on success, false otherwise.
  using MakeGLContextCurrentCallback = base::Callback<bool(void)>;

  // Bind |image| to |client_texture_id| given |texture_target|. If
  // |can_bind_to_sampler| is true, then the image may be used as a sampler
  // directly, otherwise a copy to a staging buffer is required.
  // Return true on success, false otherwise.
  using BindGLImageCallback =
      base::Callback<bool(uint32_t client_texture_id,
                          uint32_t texture_target,
                          const scoped_refptr<gl::GLImage>& image,
                          bool can_bind_to_sampler)>;

  // Return a WeakPtr to a GLES2Decoder, if one is available.
  using GetGLES2DecoderCallback =
      base::Callback<base::WeakPtr<gpu::gles2::GLES2Decoder>(void)>;

  static scoped_ptr<GpuVideoDecodeAcceleratorFactoryImpl> Create(
      const GetGLContextCallback& get_gl_context_cb,
      const MakeGLContextCurrentCallback& make_context_current_cb,
      const BindGLImageCallback& bind_image_cb);

  static scoped_ptr<GpuVideoDecodeAcceleratorFactoryImpl>
  CreateWithGLES2Decoder(
      const GetGLContextCallback& get_gl_context_cb,
      const MakeGLContextCurrentCallback& make_context_current_cb,
      const BindGLImageCallback& bind_image_cb,
      const GetGLES2DecoderCallback& get_gles2_decoder_cb);

  static gpu::VideoDecodeAcceleratorCapabilities GetDecoderCapabilities(
      const gpu::GpuPreferences& gpu_preferences);

  scoped_ptr<media::VideoDecodeAccelerator> CreateVDA(
      media::VideoDecodeAccelerator::Client* client,
      const media::VideoDecodeAccelerator::Config& config,
      const gpu::GpuPreferences& gpu_preferences);

 private:
  GpuVideoDecodeAcceleratorFactoryImpl(
      const GetGLContextCallback& get_gl_context_cb,
      const MakeGLContextCurrentCallback& make_context_current_cb,
      const BindGLImageCallback& bind_image_cb,
      const GetGLES2DecoderCallback& get_gles2_decoder_cb);

#if defined(OS_WIN)
  scoped_ptr<media::VideoDecodeAccelerator> CreateDXVAVDA(
      const gpu::GpuPreferences& gpu_preferences) const;
#endif
#if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
  scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2VDA(
      const gpu::GpuPreferences& gpu_preferences) const;
  scoped_ptr<media::VideoDecodeAccelerator> CreateV4L2SVDA(
      const gpu::GpuPreferences& gpu_preferences) const;
#endif
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
  scoped_ptr<media::VideoDecodeAccelerator> CreateVaapiVDA(
      const gpu::GpuPreferences& gpu_preferences) const;
#endif
#if defined(OS_MACOSX)
  scoped_ptr<media::VideoDecodeAccelerator> CreateVTVDA(
      const gpu::GpuPreferences& gpu_preferences) const;
#endif
#if !defined(OS_CHROMEOS) && defined(USE_OZONE)
  scoped_ptr<media::VideoDecodeAccelerator> CreateOzoneVDA(
      const gpu::GpuPreferences& gpu_preferences) const;
#endif
#if defined(OS_ANDROID)
  scoped_ptr<media::VideoDecodeAccelerator> CreateAndroidVDA(
      const gpu::GpuPreferences& gpu_preferences) const;
#endif

  const GetGLContextCallback get_gl_context_cb_;
  const MakeGLContextCurrentCallback make_context_current_cb_;
  const BindGLImageCallback bind_image_cb_;
  const GetGLES2DecoderCallback get_gles2_decoder_cb_;

  base::ThreadChecker thread_checker_;

  DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAcceleratorFactoryImpl);
};

}  // namespace content

#endif  // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_FACTORY_IMPL_H_