summaryrefslogtreecommitdiffstats
path: root/cc/RateLimiter.cpp
blob: a52152561ca1f151d603e4468389330c14dd503e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#if USE(ACCELERATED_COMPOSITING)
#include "RateLimiter.h"

#include "CCProxy.h"
#include "CCThread.h"
#include "TraceEvent.h"
#include <public/WebGraphicsContext3D.h>
#include <wtf/RefPtr.h>

namespace cc {

class RateLimiter::Task : public CCThread::Task {
public:
    static PassOwnPtr<Task> create(RateLimiter* rateLimiter)
    {
        return adoptPtr(new Task(rateLimiter));
    }
    virtual ~Task() { }

private:
    explicit Task(RateLimiter* rateLimiter)
        : CCThread::Task(this)
        , m_rateLimiter(rateLimiter)
    {
    }

    virtual void performTask() OVERRIDE
    {
        m_rateLimiter->rateLimitContext();
    }

    scoped_refptr<RateLimiter> m_rateLimiter;
};

scoped_refptr<RateLimiter> RateLimiter::create(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client)
{
    return make_scoped_refptr(new RateLimiter(context, client));
}

RateLimiter::RateLimiter(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client)
    : m_context(context)
    , m_active(false)
    , m_client(client)
{
    ASSERT(context);
}

RateLimiter::~RateLimiter()
{
}

void RateLimiter::start()
{
    if (m_active)
        return;

    TRACE_EVENT0("cc", "RateLimiter::start");
    m_active = true;
    CCProxy::mainThread()->postTask(RateLimiter::Task::create(this));
}

void RateLimiter::stop()
{
    TRACE_EVENT0("cc", "RateLimiter::stop");
    m_client = 0;
}

void RateLimiter::rateLimitContext()
{
    if (!m_client)
        return;

    TRACE_EVENT0("cc", "RateLimiter::rateLimitContext");

    m_active = false;
    m_client->rateLimit();
    m_context->rateLimitOffscreenContextCHROMIUM();
}

}
#endif // USE(ACCELERATED_COMPOSITING)