// 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.

module blink.mojom;

import "skia/public/mojom/bitmap.mojom";
import "gpu/ipc/common/exported_shared_image.mojom";
import "gpu/ipc/common/sync_token.mojom";
import "skia/public/mojom/image_info.mojom";
import "mojo/public/mojom/base/values.mojom";

// This interface is used to manage the lifetime of the
// AcceleratedStaticBitmapImage transferred in the TranferableMessage.
// While the message pipe is open, the sender will keep the reference
// alive.
// The only interface method is used to update the source image sync token
// so that reference management in the receiver process and the destruction
// in the sender process are ordered correctly in the GPU command buffer.
// It is also fine to simply destroy the Remote without calling the method.
// In that case the image will be released without any updates to the SyncToken.
interface ImageReleaseCallback {
  // Updates the sync token on the associated AcceleratedStaticBitmapImage
  // and releases it.
  Release(gpu.mojom.SharedImageExportResult token);
};

// Holds all information, necessary to recreate the accelerated image.
struct AcceleratedStaticBitmapImage {
  // ExportedSharedImage contains SharedImage reference:
  // mailbox, metadata, creation sync token and texture target.
  gpu.mojom.ExportedSharedImage shared_image;
  // Sync token that must be waited on before reading the shared image
  // associated with this AcceleratedStaticBitmapImage.
  gpu.mojom.SyncToken sync_token;
  // Image alpha type.
  skia.mojom.AlphaType alpha_type;
  // Resource lifetime management callback. Until this pending remote is
  // destroyed or the callback is called the sender shall keep the
  // resource alive.
  pending_remote<ImageReleaseCallback> release_callback;
};

// StaticBitmapImage may be sent as a software SkBitmap or
// as a GPU backed texture reference.
union SerializedStaticBitmapImage {
  skia.mojom.BitmapN32 bitmap;
  AcceleratedStaticBitmapImage accelerated_image;
};
