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

content / renderer / media / win / dcomp_texture_factory.h [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_MEDIA_WIN_DCOMP_TEXTURE_FACTORY_H_
#define CONTENT_RENDERER_MEDIA_WIN_DCOMP_TEXTURE_FACTORY_H_

#include <stdint.h>

#include <memory>

#include "base/memory/ref_counted.h"
#include "base/task/sequenced_task_runner.h"
#include "base/unguessable_token.h"
#include "cc/layers/video_frame_provider.h"
#include "content/common/content_export.h"
#include "content/renderer/media/win/dcomp_texture_host.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/ipc/common/gpu_channel.mojom.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace gpu {
class ClientSharedImageInterface;
class GpuChannelHost;
class SharedImageInterface;
}  // namespace gpu

namespace content {

// Factory class for managing DirectCompostion based textures.
//
// Threading Model: This class is created/constructed on the render main thread,
// IsLost() is also called on the main task runner. Other than that, the class
// lives and is destructed on the media task runner.
class CONTENT_EXPORT DCOMPTextureFactory
    : public base::RefCountedThreadSafe<DCOMPTextureFactory> {
 public:
  static scoped_refptr<DCOMPTextureFactory> Create(
      scoped_refptr<gpu::GpuChannelHost> channel,
      scoped_refptr<base::SequencedTaskRunner> media_task_runner);

  // Create the DCOMPTextureHost object. This internally creates a
  // gpu::DCOMPTexture and returns its route_id. If this route_id is invalid
  // nullptr is returned. If the route_id is valid it returns a valid
  // DCOMPTextureHost object.
  std::unique_ptr<DCOMPTextureHost> CreateDCOMPTextureHost(
      DCOMPTextureHost::Listener* listener);

  // Returns true if the DCOMPTextureFactory's channel is lost.
  bool IsLost() const;

  gpu::SharedImageInterface* SharedImageInterface();

 protected:
  DCOMPTextureFactory(
      scoped_refptr<gpu::GpuChannelHost> channel,
      scoped_refptr<base::SequencedTaskRunner> media_task_runner);
  DCOMPTextureFactory(const DCOMPTextureFactory&) = delete;
  DCOMPTextureFactory& operator=(const DCOMPTextureFactory&) = delete;
  virtual ~DCOMPTextureFactory();

 private:
  friend class base::RefCountedThreadSafe<DCOMPTextureFactory>;

  scoped_refptr<gpu::GpuChannelHost> channel_;
  scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
  scoped_refptr<gpu::ClientSharedImageInterface> shared_image_interface_;
};

}  // namespace content

#endif  // CONTENT_RENDERER_MEDIA_WIN_DCOMP_TEXTURE_FACTORY_H_