diff options
-rw-r--r-- | content/browser/devtools/protocol/frame_recorder.cc | 165 | ||||
-rw-r--r-- | content/browser/devtools/protocol/frame_recorder.h | 78 | ||||
-rw-r--r-- | content/browser/devtools/protocol/page_handler.cc | 19 | ||||
-rw-r--r-- | content/browser/devtools/protocol/page_handler.h | 6 | ||||
-rw-r--r-- | content/content_browser.gypi | 2 |
5 files changed, 2 insertions, 268 deletions
diff --git a/content/browser/devtools/protocol/frame_recorder.cc b/content/browser/devtools/protocol/frame_recorder.cc deleted file mode 100644 index 44e4f78..0000000 --- a/content/browser/devtools/protocol/frame_recorder.cc +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2014 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 "content/browser/devtools/protocol/frame_recorder.h" - -#include "base/base64.h" -#include "base/bind.h" -#include "base/macros.h" -#include "base/task_runner_util.h" -#include "base/threading/worker_pool.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/renderer_host/render_widget_host_view_base.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/geometry/size.h" - -namespace content { -namespace devtools { -namespace page { - -namespace { - -static int kMaxRecordFrameCount = 180; - -scoped_ptr<EncodedFrame> EncodeFrame( - const SkBitmap& bitmap, double timestamp) { - std::vector<unsigned char> data; - SkAutoLockPixels lock_image(bitmap); - bool encoded = gfx::PNGCodec::Encode( - reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), - gfx::PNGCodec::FORMAT_SkBitmap, - gfx::Size(bitmap.width(), bitmap.height()), - bitmap.width() * bitmap.bytesPerPixel(), - false, std::vector<gfx::PNGCodec::Comment>(), &data); - - scoped_ptr<EncodedFrame> result(new EncodedFrame(std::string(), timestamp)); - - if (!encoded) - return result.Pass(); - - std::string base_64_data; - base::Base64Encode( - base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), - &result->first); - - return result.Pass(); -} -} // namespace - -typedef DevToolsProtocolClient::Response Response; - -FrameRecorder::FrameRecorder() - : host_(nullptr), - state_(Ready), - inflight_requests_count_(0), - max_frame_count_(0), - captured_frames_count_(0), - last_captured_frame_timestamp_(base::Time()), - weak_factory_(this) { -} - -FrameRecorder::~FrameRecorder() { -} - -void FrameRecorder::SetRenderViewHost(RenderViewHostImpl* host) { - host_ = host; -} - -Response FrameRecorder::StartRecordingFrames(int max_frame_count) { - if (max_frame_count <= 0 || max_frame_count > kMaxRecordFrameCount) - return Response::InvalidParams("maxFrameCount"); - if (state_ != Ready) - return Response::InternalError("Already recording"); - state_ = Recording; - max_frame_count_ = max_frame_count; - captured_frames_count_ = 0; - frame_encoded_callback_.Reset(base::Bind( - &FrameRecorder::FrameEncoded, weak_factory_.GetWeakPtr())); - last_captured_frame_timestamp_ = base::Time(); - std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames; - frames.reserve(max_frame_count); - frames_.swap(frames); - - return Response::OK(); -} - -Response FrameRecorder::StopRecordingFrames( - StopRecordingFramesCallback callback) { - if (state_ != Recording) - return Response::InternalError("Not recording"); - state_ = Encoding; - callback_ = callback; - MaybeSendResponse(); - return Response::OK(); -} - -Response FrameRecorder::CancelRecordingFrames() { - frame_encoded_callback_.Cancel(); - std::vector<scoped_refptr<devtools::page::RecordedFrame>> no_frames; - frames_.swap(no_frames); - if (state_ == Encoding) - callback_.Run(StopRecordingFramesResponse::Create()->set_frames(frames_)); - state_ = Ready; - return Response::OK(); -} - -void FrameRecorder::OnSwapCompositorFrame() { - if (!host_ || state_ != Recording) - return; - if (captured_frames_count_ >= max_frame_count_) - return; - RenderWidgetHostViewBase* view = - static_cast<RenderWidgetHostViewBase*>(host_->GetView()); - if (!view) - return; - - inflight_requests_count_++; - view->CopyFromCompositingSurface( - gfx::Rect(), - gfx::Size(), - base::Bind(&FrameRecorder::FrameCaptured, weak_factory_.GetWeakPtr()), - kN32_SkColorType); -} - -void FrameRecorder::FrameCaptured( - const SkBitmap& bitmap, ReadbackResponse response) { - inflight_requests_count_--; - base::Time timestamp = last_captured_frame_timestamp_; - last_captured_frame_timestamp_ = base::Time::Now(); - if (timestamp.is_null() || response != READBACK_SUCCESS) { - MaybeSendResponse(); - return; - } - - captured_frames_count_++; - base::PostTaskAndReplyWithResult( - base::WorkerPool::GetTaskRunner(true).get(), - FROM_HERE, - base::Bind(&EncodeFrame, bitmap, timestamp.ToDoubleT()), - frame_encoded_callback_.callback()); -} - -void FrameRecorder::FrameEncoded( - const scoped_ptr<EncodedFrame>& encoded_frame) { - frames_.push_back(RecordedFrame::Create() - ->set_data(encoded_frame->first) - ->set_timestamp(encoded_frame->second)); - MaybeSendResponse(); -} - -void FrameRecorder::MaybeSendResponse() { - if (state_ != Encoding) - return; - if (inflight_requests_count_ || frames_.size() != captured_frames_count_) - return; - callback_.Run(StopRecordingFramesResponse::Create()->set_frames(frames_)); - std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames; - frames_.swap(frames); - state_ = Ready; -} - -} // namespace page -} // namespace devtools -} // namespace content diff --git a/content/browser/devtools/protocol/frame_recorder.h b/content/browser/devtools/protocol/frame_recorder.h deleted file mode 100644 index 56926ef..0000000 --- a/content/browser/devtools/protocol/frame_recorder.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2014 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. - -#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ -#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ - -#include <string> -#include <utility> -#include <vector> - -#include "base/callback.h" -#include "base/cancelable_callback.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "base/time/time.h" -#include "content/browser/devtools/protocol/devtools_protocol_handler.h" -#include "content/public/browser/readback_types.h" - -class SkBitmap; - -namespace content { - -class RenderViewHostImpl; - -namespace devtools { -namespace page { - -using EncodedFrame = std::pair<std::string, double>; - -class FrameRecorder { - public: - using Response = DevToolsProtocolClient::Response; - using StopRecordingFramesCallback = - base::Callback<void(scoped_refptr<StopRecordingFramesResponse>)>; - - explicit FrameRecorder(); - virtual ~FrameRecorder(); - - Response StartRecordingFrames(int max_frame_count); - Response StopRecordingFrames(StopRecordingFramesCallback callback); - Response CancelRecordingFrames(); - - void SetRenderViewHost(RenderViewHostImpl* host); - void OnSwapCompositorFrame(); - - private: - enum State { - Ready, - Recording, - Encoding - }; - - void FrameCaptured(const SkBitmap& bitmap, ReadbackResponse response); - void FrameEncoded(const scoped_ptr<EncodedFrame>& encoded_frame); - void MaybeSendResponse(); - - RenderViewHostImpl* host_; - State state_; - StopRecordingFramesCallback callback_; - size_t inflight_requests_count_; - size_t max_frame_count_; - size_t captured_frames_count_; - base::Time last_captured_frame_timestamp_; - std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames_; - - base::CancelableCallback<void(const scoped_ptr<EncodedFrame>&)> - frame_encoded_callback_; - base::WeakPtrFactory<FrameRecorder> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(FrameRecorder); -}; - -} // namespace page -} // namespace devtools -} // namespace content - -#endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ diff --git a/content/browser/devtools/protocol/page_handler.cc b/content/browser/devtools/protocol/page_handler.cc index 15dee24..827473b2d 100644 --- a/content/browser/devtools/protocol/page_handler.cc +++ b/content/browser/devtools/protocol/page_handler.cc @@ -12,7 +12,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/worker_pool.h" #include "content/browser/devtools/protocol/color_picker.h" -#include "content/browser/devtools/protocol/frame_recorder.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/web_contents/web_contents_impl.h" @@ -99,7 +98,6 @@ PageHandler::PageHandler() processing_screencast_frame_(false), color_picker_(new ColorPicker(base::Bind( &PageHandler::OnColorPicked, base::Unretained(this)))), - frame_recorder_(new FrameRecorder()), host_(nullptr), screencast_listener_(nullptr), weak_factory_(this) { @@ -113,7 +111,6 @@ void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { return; color_picker_->SetRenderViewHost(host); - frame_recorder_->SetRenderViewHost(host); host_ = host; } @@ -135,7 +132,6 @@ void PageHandler::OnSwapCompositorFrame( if (screencast_enabled_) InnerSwapCompositorFrame(); color_picker_->OnSwapCompositorFrame(); - frame_recorder_->OnSwapCompositorFrame(); } void PageHandler::OnVisibilityChanged(bool visible) { @@ -305,16 +301,11 @@ Response PageHandler::StopScreencast() { } Response PageHandler::StartRecordingFrames(int max_frame_count) { - return frame_recorder_->StartRecordingFrames(max_frame_count); + return Response::OK(); } Response PageHandler::StopRecordingFrames(DevToolsCommandId command_id) { - return frame_recorder_->StopRecordingFrames(base::Bind( - &PageHandler::OnFramesRecorded, base::Unretained(this), command_id)); -} - -Response PageHandler::CancelRecordingFrames() { - return frame_recorder_->CancelRecordingFrames(); + return Response::OK(); } Response PageHandler::ScreencastFrameAck(int frame_number) { @@ -498,12 +489,6 @@ void PageHandler::OnColorPicked(int r, int g, int b, int a) { client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); } -void PageHandler::OnFramesRecorded( - DevToolsCommandId command_id, - scoped_refptr<StopRecordingFramesResponse> response_data) { - client_->SendStopRecordingFramesResponse(command_id, response_data); -} - } // namespace page } // namespace devtools } // namespace content diff --git a/content/browser/devtools/protocol/page_handler.h b/content/browser/devtools/protocol/page_handler.h index 4348a4f..1f20ac6 100644 --- a/content/browser/devtools/protocol/page_handler.h +++ b/content/browser/devtools/protocol/page_handler.h @@ -23,7 +23,6 @@ namespace devtools { namespace page { class ColorPicker; -class FrameRecorder; class PageHandler { public: @@ -75,7 +74,6 @@ class PageHandler { Response StartRecordingFrames(int max_frame_count); Response StopRecordingFrames(DevToolsCommandId command_id); - Response CancelRecordingFrames(); Response HandleJavaScriptDialog(bool accept, const std::string* prompt_text); @@ -100,9 +98,6 @@ class PageHandler { size_t png_size); void OnColorPicked(int r, int g, int b, int a); - void OnFramesRecorded( - DevToolsCommandId command_id, - scoped_refptr<StopRecordingFramesResponse> response_data); bool enabled_; @@ -120,7 +115,6 @@ class PageHandler { bool processing_screencast_frame_; scoped_ptr<ColorPicker> color_picker_; - scoped_ptr<FrameRecorder> frame_recorder_; RenderViewHostImpl* host_; scoped_ptr<Client> client_; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 0412880..acab46b 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -528,8 +528,6 @@ 'browser/devtools/protocol/dom_handler.h', 'browser/devtools/protocol/emulation_handler.cc', 'browser/devtools/protocol/emulation_handler.h', - 'browser/devtools/protocol/frame_recorder.cc', - 'browser/devtools/protocol/frame_recorder.h', 'browser/devtools/protocol/input_handler.cc', 'browser/devtools/protocol/input_handler.h', 'browser/devtools/protocol/inspector_handler.cc', |