#ifndef GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
#define GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
#include <vector>
#include "base/memory/weak_ptr.h"
#include "gpu/ipc/service/command_buffer_stub.h"
#include "gpu/ipc/service/image_transport_surface.h"
#include "ui/gfx/ca_layer_result.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/presenter.h"
#if BUILDFLAG(IS_MAC)
#include "ui/display/mac/display_link_mac.h"
#include "ui/display/types/display_constants.h"
#endif
#if BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_IOS_TVOS)
#include <BrowserEngineKit/BrowserEngineKit.h>
#endif
@class CAContext;
@class CALayer;
namespace ui {
class CALayerTreeCoordinator;
struct CARendererLayerParams;
}
namespace gpu {
class ImageTransportSurfaceOverlayMacEGL : public gl::Presenter {
public:
ImageTransportSurfaceOverlayMacEGL(
scoped_refptr<SharedContextState> context_state,
SurfaceHandle surface_handle);
ImageTransportSurfaceOverlayMacEGL(
std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator
#if BUILDFLAG(IS_MAC)
,
std::unique_ptr<ui::VSyncCallbackMac> vsync_callback_mac
#endif
);
bool Resize(const gfx::Size& size,
float scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha) override;
void Present(SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback,
gfx::FrameData data) override;
bool ScheduleCALayer(
const ui::CARendererLayerParams& params,
std::vector<gfx::MTLSharedEventFence> backpressure_fences) override;
void SetMaxPendingSwaps(int max_pending_swaps) override;
#if BUILDFLAG(IS_MAC)
void SetVSyncDisplayID(int64_t display_id) override;
void OnVSyncPresentation(ui::VSyncParamsMac params);
#endif
private:
~ImageTransportSurfaceOverlayMacEGL() override;
gfx::SwapResult SwapBuffersInternal(
gl::GLSurface::SwapCompletionCallback completion_callback,
gl::GLSurface::PresentationCallback presentation_callback);
void BufferPresented(gl::GLSurface::PresentationCallback callback,
const gfx::PresentationFeedback& feedback);
void CommitPresentedFrameToCA();
std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;
#if BUILDFLAG(IS_MAC)
base::TimeTicks GetDisplaytime(base::TimeTicks latch_time);
int64_t display_id_ = display::kInvalidDisplayId;
scoped_refptr<ui::DisplayLinkMac> display_link_mac_;
std::unique_ptr<ui::VSyncCallbackMac> vsync_callback_mac_;
int vsync_callback_mac_keep_alive_counter_ = 0;
constexpr static int kMaxKeepAliveCounter = 8;
base::TimeTicks current_display_time_;
base::TimeTicks next_display_time_;
base::TimeDelta frame_interval_;
#endif
#if BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_IOS_TVOS)
BELayerHierarchy* __strong layer_hierarchy_;
#endif
int cap_max_pending_swaps_ = 1;
base::WeakPtrFactory<ImageTransportSurfaceOverlayMacEGL> weak_ptr_factory_;
};
}
#endif