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

content / renderer / media / win / dcomp_texture_factory.cc [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.

#include "content/renderer/media/win/dcomp_texture_factory.h"

#include "base/task/sequenced_task_runner.h"
#include "gpu/ipc/client/client_shared_image_interface.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "media/base/win/mf_helpers.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "ui/gfx/geometry/size.h"

namespace content {

// static
scoped_refptr<DCOMPTextureFactory> DCOMPTextureFactory::Create(
    scoped_refptr<gpu::GpuChannelHost> channel,
    scoped_refptr<base::SequencedTaskRunner> media_task_runner) {
  DVLOG(1) << __func__;
  return WrapRefCounted(
      new DCOMPTextureFactory(std::move(channel), media_task_runner));
}

DCOMPTextureFactory::DCOMPTextureFactory(
    scoped_refptr<gpu::GpuChannelHost> channel,
    scoped_refptr<base::SequencedTaskRunner> media_task_runner)
    : channel_(std::move(channel)), media_task_runner_(media_task_runner) {
  DVLOG_FUNC(1);
  DCHECK(channel_);
}

DCOMPTextureFactory::~DCOMPTextureFactory() = default;

std::unique_ptr<DCOMPTextureHost> DCOMPTextureFactory::CreateDCOMPTextureHost(
    DCOMPTextureHost::Listener* listener) {
  DVLOG_FUNC(1);
  DCHECK(media_task_runner_->RunsTasksInCurrentSequence());

  int32_t route_id = channel_->GenerateRouteID();
  mojo::PendingAssociatedRemote<gpu::mojom::DCOMPTexture> remote;
  bool succeeded = false;

  mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
  // Creates a DCOMPTexture in the GPU process.
  channel_->GetGpuChannel().CreateDCOMPTexture(
      route_id, remote.InitWithNewEndpointAndPassReceiver(), &succeeded);
  if (!succeeded) {
    DLOG(ERROR) << "CreateDCOMPTexture failed";
    return nullptr;
  }

  return std::make_unique<DCOMPTextureHost>(
      channel_, route_id, media_task_runner_, std::move(remote), listener);
}

bool DCOMPTextureFactory::IsLost() const {
  return channel_->IsLost();
}

gpu::SharedImageInterface* DCOMPTextureFactory::SharedImageInterface() {
  DCHECK(media_task_runner_->RunsTasksInCurrentSequence());

  if (!shared_image_interface_)
    shared_image_interface_ = channel_->CreateClientSharedImageInterface();

  DCHECK(shared_image_interface_);
  return shared_image_interface_.get();
}

}  // namespace content