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

ash / frame_sink / ui_resource.h [blame]

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

#ifndef ASH_FRAME_SINK_UI_RESOURCE_H_
#define ASH_FRAME_SINK_UI_RESOURCE_H_

#include "ash/ash_export.h"
#include "components/viz/common/gpu/raster_context_provider.h"
#include "components/viz/common/resources/resource_id.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "ui/gfx/geometry/size.h"

namespace ash {

using UiSourceId = uint32_t;
inline constexpr UiSourceId kInvalidUiSourceId(0u);

// A handle to a texture resource. Contains the meta data and context that can
// map the resource back to the source of the resource.
class ASH_EXPORT UiResource {
 public:
  UiResource();

  UiResource(const UiResource&) = delete;
  UiResource& operator=(const UiResource&) = delete;

  virtual ~UiResource();

  // It is valid to call only one of the two below setters on a given instance,
  // and that setter should be called only once.
  void SetExternallyOwnedMailbox(const gpu::Mailbox& mailbox) {
    CHECK(external_mailbox_.IsZero());
    CHECK(!client_shared_image_);
    external_mailbox_ = mailbox;
  }
  void SetClientSharedImage(
      scoped_refptr<gpu::ClientSharedImage> client_shared_image) {
    CHECK(external_mailbox_.IsZero());
    CHECK(!client_shared_image_);
    client_shared_image_ = std::move(client_shared_image);
  }

  // Returns `client_shared_image_->mailbox()` if `client_shared_image_` has
  // been set and `external_mailbox_` otherwise.
  const gpu::Mailbox& mailbox() const {
    return client_shared_image_ ? client_shared_image_->mailbox()
                                : external_mailbox_;
  }

  const scoped_refptr<gpu::ClientSharedImage>& client_shared_image() const {
    return client_shared_image_;
  }

  scoped_refptr<viz::RasterContextProvider> context_provider;
  gpu::SyncToken sync_token;
  viz::SharedImageFormat format;
  gfx::Size resource_size;

  // This id can be used to identify the resource back to the type of source
  // generating the resourse. It must be a non-zero number.
  UiSourceId ui_source_id = kInvalidUiSourceId;

  // Unique id to identify the resource.
  viz::ResourceId resource_id = viz::kInvalidResourceId;

  // If the candidate should be promoted to use hw overlays.
  bool is_overlay_candidate = false;

  // If the textures represented by the resource is damaged.
  bool damaged = true;

 private:
  gpu::Mailbox external_mailbox_;
  scoped_refptr<gpu::ClientSharedImage> client_shared_image_;
};

}  // namespace ash

#endif  // ASH_FRAME_SINK_UI_RESOURCE_H_