electron/atom/browser/api/frame_subscriber.h

53 lines
1.4 KiB
C
Raw Normal View History

// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
#define ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
2018-05-14 15:55:39 +00:00
#include "content/public/browser/web_contents.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
2018-05-14 15:55:39 +00:00
#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/image/image.h"
#include "v8/include/v8.h"
namespace atom {
namespace api {
2018-05-14 15:55:39 +00:00
class WebContents;
class FrameSubscriber : public content::WebContentsObserver {
public:
using FrameCaptureCallback =
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
FrameSubscriber(v8::Isolate* isolate,
2018-05-14 15:55:39 +00:00
content::WebContents* web_contents,
const FrameCaptureCallback& callback,
bool only_dirty);
2018-05-14 15:55:39 +00:00
~FrameSubscriber();
private:
2018-05-14 15:55:39 +00:00
gfx::Rect GetDamageRect();
void DidReceiveCompositorFrame() override;
void Done(const gfx::Rect& damage, const SkBitmap& frame);
v8::Isolate* isolate_;
FrameCaptureCallback callback_;
bool only_dirty_;
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_