chromium/gpu/command_buffer/service/shared_image/shared_image_representation.h

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

#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_SHARED_IMAGE_REPRESENTATION_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_SHARED_IMAGE_REPRESENTATION_H_

#include <dawn/dawn_proc_table.h>
#include <dawn/webgpu_cpp.h>

#include <memory>

#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/memory/scoped_refptr.h"
#include "base/types/pass_key.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/shared_image/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
#include "gpu/gpu_gles2_export.h"
#include "gpu/vulkan/buildflags.h"
#include "skia/buildflags.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
#include "third_party/skia/include/gpu/graphite/BackendTexture.h"
#include "third_party/skia/include/private/chromium/GrPromiseImageTexture.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_fence.h"

#if BUILDFLAG(ENABLE_VULKAN)
#include <vulkan/vulkan_core.h>

namespace gpu {
class VulkanDeviceQueue;
class VulkanImage;
class VulkanImplementation;
}  // namespace gpu
#endif

#if BUILDFLAG(IS_WIN)
#include "ui/gl/dc_layer_overlay_image.h"
#endif

#if BUILDFLAG(IS_APPLE)
#include "ui/gfx/mac/io_surface.h"
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/android/scoped_hardware_buffer_fence_sync.h"

extern "C" typedef struct AHardwareBuffer AHardwareBuffer;
#endif

#if BUILDFLAG(IS_WIN)
#include <d3d11.h>
#include <wrl/client.h>
#endif

GLenum;
namespace skgpu {
class MutableTextureState;
}

namespace cc {
class PaintOpBuffer;
}  // namespace cc

namespace gfx {
class NativePixmap;
}  // namespace gfx

namespace gpu {
class TextureBase;

namespace gles2 {
class Texture;
class TexturePassthrough;
}  // namespace gles2

enum class RepresentationAccessMode {};

///////////////////////////////////////////////////////////////////////////////
// SharedImageRepresentation

// A representation of a SharedImageBacking for use with a specific use case /
// api.
class GPU_GLES2_EXPORT SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// SharedImageRepresentationFactoryRef
class SharedImageRepresentationFactoryRef : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// GLTextureImageRepresentationBase

class GPU_GLES2_EXPORT GLTextureImageRepresentationBase
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// GLTextureImageRepresentation

class GPU_GLES2_EXPORT GLTextureImageRepresentation
    : public GLTextureImageRepresentationBase {};

///////////////////////////////////////////////////////////////////////////////
// GLTexturePassthroughImageRepresentation

class GPU_GLES2_EXPORT GLTexturePassthroughImageRepresentation
    : public GLTextureImageRepresentationBase {};

///////////////////////////////////////////////////////////////////////////////
// SkiaImageRepresentation

class GPU_GLES2_EXPORT SkiaImageRepresentation
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// SkiaGaneshImageRepresentation

class GPU_GLES2_EXPORT SkiaGaneshImageRepresentation
    : public SkiaImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// SkiaGraphiteImageRepresentation

class GPU_GLES2_EXPORT SkiaGraphiteImageRepresentation
    : public SkiaImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// DawnImageRepresentation

class GPU_GLES2_EXPORT DawnImageRepresentation
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// OverlayImageRepresentation

class GPU_GLES2_EXPORT OverlayImageRepresentation
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// LegacyOverlayImageRepresentation

#if BUILDFLAG(IS_ANDROID)
class GPU_GLES2_EXPORT LegacyOverlayImageRepresentation
    : public SharedImageRepresentation {
 public:
  LegacyOverlayImageRepresentation(SharedImageManager* manager,
                                   SharedImageBacking* backing,
                                   MemoryTypeTracker* tracker)
      : SharedImageRepresentation(manager, backing, tracker) {}

  // Renders shared image to SurfaceView/Dialog overlay. Should only be called
  // if the image already promoted to overlay.
  virtual void RenderToOverlay() = 0;

  // Notifies legacy overlay system about overlay promotion.
  virtual void NotifyOverlayPromotion(bool promotion,
                                      const gfx::Rect& bounds) = 0;
};
#endif

///////////////////////////////////////////////////////////////////////////////
// MemoryImageRepresentation

class GPU_GLES2_EXPORT MemoryImageRepresentation
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// RasterImageRepresentation

// Representation of a SharedImageBacking for raster work.
// This representation is used for raster work and compositor. The raster work
// will be converted to a cc::PaintOpBuffer and stored in the
// SharedImageBacking. And then the the compositor will access the stored
// cc::PaintOpBuffer and execute paint ops in it.
class GPU_GLES2_EXPORT RasterImageRepresentation
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// VideoImageRepresentation

class GPU_GLES2_EXPORT VideoImageRepresentation
    : public SharedImageRepresentation {};

///////////////////////////////////////////////////////////////////////////////
// VulkanImageRepresentation

#if BUILDFLAG(ENABLE_VULKAN)
class GPU_GLES2_EXPORT VulkanImageRepresentation
    : public SharedImageRepresentation {};
#endif

}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_SHARED_IMAGE_REPRESENTATION_H_