OLD | NEW |
| (Empty) |
1 // Copyright 2011 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 #include "config.h" | |
6 | |
7 #if USE(ACCELERATED_COMPOSITING) | |
8 #include "RateLimiter.h" | |
9 | |
10 #include "CCProxy.h" | |
11 #include "CCThread.h" | |
12 #include "TraceEvent.h" | |
13 #include <public/WebGraphicsContext3D.h> | |
14 #include <wtf/RefPtr.h> | |
15 | |
16 namespace cc { | |
17 | |
18 class RateLimiter::Task : public CCThread::Task { | |
19 public: | |
20 static PassOwnPtr<Task> create(RateLimiter* rateLimiter) | |
21 { | |
22 return adoptPtr(new Task(rateLimiter)); | |
23 } | |
24 virtual ~Task() { } | |
25 | |
26 private: | |
27 explicit Task(RateLimiter* rateLimiter) | |
28 : CCThread::Task(this) | |
29 , m_rateLimiter(rateLimiter) | |
30 { | |
31 } | |
32 | |
33 virtual void performTask() OVERRIDE | |
34 { | |
35 m_rateLimiter->rateLimitContext(); | |
36 } | |
37 | |
38 scoped_refptr<RateLimiter> m_rateLimiter; | |
39 }; | |
40 | |
41 scoped_refptr<RateLimiter> RateLimiter::create(WebKit::WebGraphicsContext3D* con
text, RateLimiterClient *client) | |
42 { | |
43 return make_scoped_refptr(new RateLimiter(context, client)); | |
44 } | |
45 | |
46 RateLimiter::RateLimiter(WebKit::WebGraphicsContext3D* context, RateLimiterClien
t *client) | |
47 : m_context(context) | |
48 , m_active(false) | |
49 , m_client(client) | |
50 { | |
51 ASSERT(context); | |
52 } | |
53 | |
54 RateLimiter::~RateLimiter() | |
55 { | |
56 } | |
57 | |
58 void RateLimiter::start() | |
59 { | |
60 if (m_active) | |
61 return; | |
62 | |
63 TRACE_EVENT0("cc", "RateLimiter::start"); | |
64 m_active = true; | |
65 CCProxy::mainThread()->postTask(RateLimiter::Task::create(this)); | |
66 } | |
67 | |
68 void RateLimiter::stop() | |
69 { | |
70 TRACE_EVENT0("cc", "RateLimiter::stop"); | |
71 m_client = 0; | |
72 } | |
73 | |
74 void RateLimiter::rateLimitContext() | |
75 { | |
76 if (!m_client) | |
77 return; | |
78 | |
79 TRACE_EVENT0("cc", "RateLimiter::rateLimitContext"); | |
80 | |
81 m_active = false; | |
82 m_client->rateLimit(); | |
83 m_context->rateLimitOffscreenContextCHROMIUM(); | |
84 } | |
85 | |
86 } | |
87 #endif // USE(ACCELERATED_COMPOSITING) | |
OLD | NEW |