1 // Copyright 2014 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.
4 
5 #ifndef UI_OZONE_PLATFORM_DRM_GPU_PAGE_FLIP_REQUEST_H_
6 #define UI_OZONE_PLATFORM_DRM_GPU_PAGE_FLIP_REQUEST_H_
7 
8 #include <memory>
9 
10 #include "base/atomic_ref_count.h"
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "ui/gfx/swap_result.h"
14 #include "ui/ozone/public/swap_completion_callback.h"
15 
16 namespace ui {
17 
18 class PageFlipRequest : public base::RefCounted<PageFlipRequest> {
19  public:
20   using PageFlipCallback =
21       base::OnceCallback<void(unsigned int /* frame */,
22                               base::TimeTicks /* timestamp */)>;
23 
24   PageFlipRequest(const base::TimeDelta& refresh_interval);
25 
26   // Takes ownership of the swap completion callback to allow
27   // asynchronous notification of completion.
28   //
29   // This is only called once all of the individual flips have have been
30   // successfully submitted.
31   void TakeCallback(PresentationOnceCallback callback);
32 
33   // Add a page flip to this request. Once all page flips return, the
34   // overall callback is made with the timestamp from the page flip event
35   // that returned last.
36   PageFlipCallback AddPageFlip();
37 
page_flip_count()38   int page_flip_count() const { return page_flip_count_; }
39 
40  private:
41   void Signal(unsigned int frame, base::TimeTicks timestamp);
42 
43   friend class base::RefCounted<PageFlipRequest>;
44   ~PageFlipRequest();
45 
46   PresentationOnceCallback callback_;
47   int page_flip_count_ = 0;
48   const base::TimeDelta refresh_interval_;
49 
50   DISALLOW_COPY_AND_ASSIGN(PageFlipRequest);
51 };
52 
53 }  // namespace ui
54 
55 #endif  // UI_OZONE_PLATFORM_DRM_GPU_PAGE_FLIP_REQUEST_H_
56