#ifndef UI_GL_PRESENTER_H_
#define UI_GL_PRESENTER_H_
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/delegated_ink_metadata.h"
#include "ui/gfx/frame_data.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/swap_result.h"
#include "ui/gl/gl_export.h"
#if BUILDFLAG(IS_OZONE)
#include "ui/gfx/native_pixmap.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"
#endif
namespace gfx {
namespace mojom {
class DelegatedInkPointRenderer;
}
class ColorSpace;
class GpuFence;
struct OverlayPlaneData;
}
namespace ui {
struct CARendererLayerParams;
}
namespace gl {
struct DCLayerOverlayParams;
#if BUILDFLAG(IS_OZONE)
using OverlayImage = scoped_refptr<gfx::NativePixmap>;
#elif BUILDFLAG(IS_APPLE)
using OverlayImage = gfx::ScopedIOSurface;
#elif BUILDFLAG(IS_ANDROID)
using OverlayImage =
std::unique_ptr<base::android::ScopedHardwareBufferFenceSync>;
#else
struct OverlayImage {};
#endif
class GL_EXPORT Presenter : public base::RefCounted<Presenter> {
public:
using PresentationCallback =
base::OnceCallback<void(const gfx::PresentationFeedback& feedback)>;
using SwapCompletionCallback =
base::OnceCallback<void(gfx::SwapCompletionResult)>;
Presenter();
virtual bool SupportsOverridePlatformSize() const;
virtual bool SupportsViewporter() const;
virtual bool SupportsPlaneGpuFences() const;
virtual bool SupportsGpuVSync() const;
virtual void SetGpuVSyncEnabled(bool enabled) {}
virtual void SetVSyncDisplayID(int64_t display_id) {}
virtual bool Resize(const gfx::Size& size,
float scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha);
virtual bool ScheduleOverlayPlane(
OverlayImage image,
std::unique_ptr<gfx::GpuFence> gpu_fence,
const gfx::OverlayPlaneData& overlay_plane_data);
virtual bool ScheduleCALayer(const ui::CARendererLayerParams& params);
virtual bool ScheduleDCLayer(std::unique_ptr<DCLayerOverlayParams> params);
virtual void Present(SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback,
gfx::FrameData data) = 0;
virtual void SetCALayerErrorCode(gfx::CALayerResult ca_layer_error_code) {}
virtual void SetFrameRate(float frame_rate) {}
virtual void SetChoreographerVsyncIdForNextFrame(
absl::optional<int64_t> choreographer_vsync_id) {}
virtual void PreserveChildSurfaceControls() {}
#if BUILDFLAG(IS_WIN)
virtual bool SetDrawRectangle(const gfx::Rect& rect) = 0;
virtual bool SupportsDelegatedInk() = 0;
virtual void SetDelegatedInkTrailStartPoint(
std::unique_ptr<gfx::DelegatedInkMetadata> metadata) {}
virtual void InitDelegatedInkPointRendererReceiver(
mojo::PendingReceiver<gfx::mojom::DelegatedInkPointRenderer>
pending_receiver) {}
#endif
virtual void SetRelyOnImplicitSync() {}
protected:
friend class base::RefCounted<Presenter>;
virtual ~Presenter();
};
}
#endif