draw_waiter_for_test.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef UI_COMPOSITOR_TEST_DRAW_WAITER_FOR_TEST_H_
  5. #define UI_COMPOSITOR_TEST_DRAW_WAITER_FOR_TEST_H_
  6. #include <memory>
  7. #include "base/run_loop.h"
  8. #include "ui/compositor/compositor_observer.h"
  9. class Compositor;
  10. namespace ui {
  11. // This is only to be used for test. It allows execution of other tasks on
  12. // the current message loop before the current task finishs (there is a
  13. // potential for re-entrancy).
  14. class DrawWaiterForTest : public CompositorObserver {
  15. public:
  16. DrawWaiterForTest(const DrawWaiterForTest&) = delete;
  17. DrawWaiterForTest& operator=(const DrawWaiterForTest&) = delete;
  18. // Waits for a draw to be issued by the compositor. If the test times out
  19. // here, there may be a logic error in the compositor code causing it
  20. // not to draw.
  21. static void WaitForCompositingStarted(Compositor* compositor);
  22. // Waits for a swap to be completed from the compositor.
  23. static void WaitForCompositingEnded(Compositor* compositor);
  24. // Waits for a commit instead of a draw.
  25. static void WaitForCommit(Compositor* compositor);
  26. private:
  27. enum WaitEvent {
  28. WAIT_FOR_COMMIT,
  29. WAIT_FOR_COMPOSITING_STARTED,
  30. WAIT_FOR_COMPOSITING_ENDED,
  31. };
  32. DrawWaiterForTest(WaitEvent wait_event);
  33. ~DrawWaiterForTest() override;
  34. void WaitImpl(Compositor* compositor);
  35. // CompositorObserver implementation.
  36. void OnCompositingDidCommit(Compositor* compositor) override;
  37. void OnCompositingStarted(Compositor* compositor,
  38. base::TimeTicks start_time) override;
  39. void OnCompositingEnded(Compositor* compositor) override;
  40. std::unique_ptr<base::RunLoop> wait_run_loop_;
  41. WaitEvent wait_event_;
  42. };
  43. } // namespace ui
  44. #endif // UI_COMPOSITOR_TEST_DRAW_WAITER_FOR_TEST_H_