1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
10 #include "base/memory/linked_ptr.h"
11 #import "base/mac/scoped_nsobject.h"
12 #include "content/common/gpu/gpu_command_buffer_stub.h"
13 #include "content/common/gpu/image_transport_surface.h"
14 #include "ui/accelerated_widget_mac/display_link_mac.h"
15 #include "ui/gl/gl_surface.h"
22 class ImageTransportSurfaceOverlayMac
: public gfx::GLSurface
,
23 public ImageTransportSurface
{
25 ImageTransportSurfaceOverlayMac(GpuChannelManager
* manager
,
26 GpuCommandBufferStub
* stub
,
27 gfx::PluginWindowHandle handle
);
29 // GLSurface implementation
30 bool Initialize() override
;
31 void Destroy() override
;
32 bool IsOffscreen() override
;
33 gfx::SwapResult
SwapBuffers() override
;
34 gfx::SwapResult
PostSubBuffer(int x
, int y
, int width
, int height
) override
;
35 bool SupportsPostSubBuffer() override
;
36 gfx::Size
GetSize() override
;
37 void* GetHandle() override
;
39 bool ScheduleOverlayPlane(int z_order
,
40 gfx::OverlayTransform transform
,
42 const gfx::Rect
& bounds_rect
,
43 const gfx::RectF
& crop_rect
) override
;
44 bool IsSurfaceless() const override
;
46 // ImageTransportSurface implementation
47 void OnBufferPresented(
48 const AcceleratedSurfaceMsg_BufferPresented_Params
& params
) override
;
49 void OnResize(gfx::Size pixel_size
, float scale_factor
) override
;
50 void SetLatencyInfo(const std::vector
<ui::LatencyInfo
>&) override
;
51 void WakeUpGpu() override
;
56 ~ImageTransportSurfaceOverlayMac() override
;
58 gfx::SwapResult
SwapBuffersInternal(const gfx::Rect
& pixel_damage_rect
);
60 // Returns true if the front of |pending_swaps_| has completed, or has timed
62 bool IsFirstPendingSwapReadyToDisplay(
63 const base::TimeTicks
& now
);
64 // Sets the CALayer contents to the IOSurface for the front of
65 // |pending_swaps_|, and removes it from the queue.
66 void DisplayFirstPendingSwapImmediately();
67 // Force that all of |pending_swaps_| displayed immediately, and the list be
69 void FinishAllPendingSwaps();
70 // Callback issued during the next vsync period ofter a SwapBuffers call,
71 // to check if the swap is completed, and display the frame. Note that if
72 // another SwapBuffers happens before this callback, the pending swap will
73 // be tested at that time, too.
74 void CheckPendingSwapsCallback();
75 // Function to post the above callback. The argument |now| is passed as an
76 // argument to avoid redundant calls to base::TimeTicks::Now.
77 void PostCheckPendingSwapsCallbackIfNeeded(const base::TimeTicks
& now
);
79 scoped_ptr
<ImageTransportHelper
> helper_
;
80 base::scoped_nsobject
<CAContext
> ca_context_
;
81 base::scoped_nsobject
<CALayer
> layer_
;
82 base::scoped_nsobject
<CALayer
> partial_damage_layer_
;
84 gfx::Size pixel_size_
;
86 std::vector
<ui::LatencyInfo
> latency_info_
;
88 // Weak pointer to the image provided when ScheduleOverlayPlane is called. Is
89 // consumed and reset when SwapBuffers is called. For now, only one overlay
90 // plane is supported.
91 gfx::GLImage
* pending_overlay_image_
;
93 // A queue of all frames that have been created by SwapBuffersInternal but
94 // have not yet been displayed. This queue is checked at the beginning of
95 // every swap and also by a callback.
96 std::deque
<linked_ptr
<PendingSwap
>> pending_swaps_
;
98 // The union of the damage rects of SwapBuffersInternal since the last
100 gfx::Rect accumulated_partial_damage_pixel_rect_
;
102 // The display link used to compute the time for callbacks.
103 scoped_refptr
<ui::DisplayLinkMac
> display_link_mac_
;
105 // True if there is a pending call to CheckPendingSwapsCallback posted.
106 bool has_pending_callback_
;
108 base::WeakPtrFactory
<ImageTransportSurfaceOverlayMac
> weak_factory_
;
111 } // namespace content
113 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_