Chromium Code Reviews| Index: third_party/WebKit/Source/modules/mediacapturefromelement/TimedCanvasDrawListener.cpp |
| diff --git a/third_party/WebKit/Source/modules/mediacapturefromelement/TimedCanvasDrawListener.cpp b/third_party/WebKit/Source/modules/mediacapturefromelement/TimedCanvasDrawListener.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0850ad47a5357da61472c3fdfaa700f7cf9e2aab |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/mediacapturefromelement/TimedCanvasDrawListener.cpp |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2015 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" |
| +#include "modules/mediacapturefromelement/TimedCanvasDrawListener.h" |
| + |
| +#include "platform/Task.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebSkImage.h" |
| +#include "public/platform/WebTaskRunner.h" |
| +#include "public/platform/WebTraceLocation.h" |
| + |
| +namespace blink { |
| + |
| +TimedCanvasDrawListener::TimedCanvasDrawListener(const PassOwnPtr<WebCanvasCaptureHandler>& handler, double frameRate) |
| + : CanvasDrawListener(handler) |
| +{ |
| + m_frameInterval = 1000 / frameRate; |
| + requestNewFrame(); |
|
esprehn
2015/12/15 23:58:01
can we do this in the caller? The constructor havi
emircan
2015/12/16 15:36:21
Done.
|
| +} |
| + |
| +TimedCanvasDrawListener::~TimedCanvasDrawListener() {} |
| + |
| +// static |
| +TimedCanvasDrawListener* TimedCanvasDrawListener::create(const PassOwnPtr<WebCanvasCaptureHandler>& handler, double frameRate) |
| +{ |
| + return new TimedCanvasDrawListener(handler, frameRate); |
| +} |
| + |
| +bool TimedCanvasDrawListener::needsNewFrame() const |
| +{ |
| + return m_requestFrame && CanvasDrawListener::needsNewFrame(); |
| +} |
| + |
| +void TimedCanvasDrawListener::sendNewFrame(const WTF::PassRefPtr<SkImage>& image) |
| +{ |
| + m_requestFrame = false; |
| + CanvasDrawListener::sendNewFrame(image); |
| +} |
| + |
| +void TimedCanvasDrawListener::requestNewFrame() |
| +{ |
| + m_requestFrame = true; |
| + Platform::current()->currentThread()->taskRunner()->postDelayedTask(BLINK_FROM_HERE, new Task(bind(&TimedCanvasDrawListener::requestNewFrame, this)), m_frameInterval); |
| +} |
| + |
| +} // namespace blink |