~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/server/compositor/timeout_frame_dropping_policy_factory.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
ImportĀ upstreamĀ versionĀ 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include "mir/compositor/frame_dropping_policy.h"
 
21
#include "mir/lockable_callback_wrapper.h"
21
22
 
22
23
#include "timeout_frame_dropping_policy_factory.h"
23
24
 
33
34
class TimeoutFrameDroppingPolicy : public mc::FrameDroppingPolicy
34
35
{
35
36
public:
36
 
    TimeoutFrameDroppingPolicy(std::shared_ptr<mir::time::Timer> const& timer,
 
37
    TimeoutFrameDroppingPolicy(std::shared_ptr<mir::time::AlarmFactory> const& factory,
37
38
                               std::chrono::milliseconds timeout,
38
 
                               std::function<void()> const& drop_frame,
39
 
                               std::function<void()> const& lock,
40
 
                               std::function<void()> const& unlock);
 
39
                               std::shared_ptr<mir::LockableCallback> const& drop_frame);
41
40
 
42
41
    void swap_now_blocking() override;
43
42
    void swap_unblocked() override;
51
50
    std::unique_ptr<mir::time::Alarm> const alarm;
52
51
};
53
52
 
54
 
TimeoutFrameDroppingPolicy::TimeoutFrameDroppingPolicy(std::shared_ptr<mir::time::Timer> const& timer,
 
53
TimeoutFrameDroppingPolicy::TimeoutFrameDroppingPolicy(std::shared_ptr<mir::time::AlarmFactory> const& factory,
55
54
                                                       std::chrono::milliseconds timeout,
56
 
                                                       std::function<void()> const& drop_frame,
57
 
                                                       std::function<void()> const& lock,
58
 
                                                       std::function<void()> const& unlock)
 
55
                                                       std::shared_ptr<mir::LockableCallback> const& callback)
59
56
    : timeout{timeout},
60
57
      pending_swaps{0},
61
 
      alarm{timer->create_alarm([this, drop_frame]
62
 
        {
63
 
            assert(pending_swaps.load() > 0);
64
 
            drop_frame();
65
 
            if (--pending_swaps > 0)
66
 
                alarm->reschedule_in(this->timeout);
67
 
        }, lock, unlock)}
 
58
      alarm{factory->create_alarm(
 
59
          std::make_shared<mir::LockableCallbackWrapper>(callback,
 
60
              [this] { assert(pending_swaps.load() > 0); },
 
61
              [this] { if (--pending_swaps > 0) alarm->reschedule_in(this->timeout);} ))}
68
62
{
69
63
}
70
64
 
87
81
}
88
82
 
89
83
mc::TimeoutFrameDroppingPolicyFactory::TimeoutFrameDroppingPolicyFactory(
90
 
    std::shared_ptr<mir::time::Timer> const& timer,
 
84
    std::shared_ptr<mir::time::AlarmFactory> const& timer,
91
85
    std::chrono::milliseconds timeout)
92
 
    : timer{timer},
 
86
    : factory{timer},
93
87
      timeout{timeout}
94
88
{
95
89
}
96
90
 
97
91
std::unique_ptr<mc::FrameDroppingPolicy>
98
 
mc::TimeoutFrameDroppingPolicyFactory::create_policy(std::function<void()> const& drop_frame,
99
 
    std::function<void()> const& lock,
100
 
    std::function<void()> const& unlock) const
 
92
mc::TimeoutFrameDroppingPolicyFactory::create_policy(std::shared_ptr<LockableCallback> const& drop_frame) const
101
93
{
102
 
    return std::unique_ptr<mc::FrameDroppingPolicy>{new TimeoutFrameDroppingPolicy{timer, timeout, drop_frame, lock, unlock}};
 
94
    return std::make_unique<TimeoutFrameDroppingPolicy>(factory, timeout, drop_frame);
103
95
}