Chromium Code Reviews| Index: webrtc/modules/desktop_capture/desktop_frame_generator.h |
| diff --git a/webrtc/modules/desktop_capture/desktop_frame_generator.h b/webrtc/modules/desktop_capture/desktop_frame_generator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9348e6ed36eb437294a00108a932c4944a523b24 |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/desktop_frame_generator.h |
| @@ -0,0 +1,112 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_ |
| +#define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_ |
| + |
| +#include <memory> |
| + |
| +#include "webrtc/modules/desktop_capture/desktop_frame.h" |
| +#include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| +#include "webrtc/modules/desktop_capture/desktop_region.h" |
| +#include "webrtc/modules/desktop_capture/shared_memory.h" |
| + |
| +namespace webrtc { |
| + |
| +// A functor to generate a DesktopFrame. |
| +class DesktopFrameGenerator { |
| + public: |
| + DesktopFrameGenerator(); |
| + virtual ~DesktopFrameGenerator(); |
| + |
| + virtual std::unique_ptr<DesktopFrame> operator()( |
|
Sergey Ulanov
2016/08/18 05:07:58
style guide discourages operator overloading. http
Hzj_jie
2016/08/23 00:54:59
Done.
|
| + SharedMemoryFactory* factory) = 0; |
| +}; |
| + |
| +// A base implementation of DesktopFrameGenerator to take care about the |
| +// DesktopFrame |
| +// size, filling updated_region(), etc, but only requires derived classes to |
| +// implement the Paint() function. |
| +class BaseDesktopFrameGenerator : public DesktopFrameGenerator { |
|
Sergey Ulanov
2016/08/18 05:07:58
I don't think you really need inheritance here. St
Hzj_jie
2016/08/23 00:54:59
I think you must mean the BlackWhiteDesktopFrameGe
|
| + public: |
| + BaseDesktopFrameGenerator(); |
| + ~BaseDesktopFrameGenerator() override; |
| + |
| + std::unique_ptr<DesktopFrame> operator()(SharedMemoryFactory* factory) final; |
| + |
| + // Sets the size of the frame which will be returned in next operator() |
| + // call. |
| + DesktopSize* size(); |
| + |
| + // Decides whether BaseDesktopFrameGenerator returns a frame in next Capture() |
| + // callback. If return_frame_ is true, BaseDesktopFrameGenerator will create a |
| + // frame according to both size_ and SharedMemoryFactory input, and uses |
| + // Paint() function to paint it. |
| + void set_return_frame(bool return_frame); |
| + |
| + // Decides whether MockScreenCapturer returns a frame with updated regions. |
| + // MockScreenCapturer will keep DesktopFrame::updated_region() empty if this |
| + // field is false. |
| + void set_provide_updated_region_hints(bool provide_updated_region_hints); |
| + |
| + // Decides whether MockScreenCapturer randomly enlarges updated regions in the |
| + // DesktopFrame. Set this field to true to simulate an inaccurate updated |
| + // regions' return from OS APIs. |
| + void set_enlarge_updated_region(bool enlarge_updated_region); |
| + |
| + // The range to enlarge a updated region if |enlarge_updated_region_| is true. |
| + // If this field is less than zero, it will be treated as zero, and |
| + // |enlarge_updated_region_| will be ignored. |
| + void set_enlarge_range(int enlarge_range); |
| + |
| + // Decides whether BaseDesktopFrameGenerator randomly add some updated regions |
| + // in the |
| + // DesktopFrame. Set this field to true to simulate an inaccurate updated |
| + // regions' return from OS APIs. |
| + void set_add_random_updated_region(bool add_random_updated_region); |
| + |
| + private: |
| + // Paints on the |frame|, and updates |updated_region| to indicate |
| + // rectangles painted. If this function returns false, |
| + // BaseDesktopFrameGenerator will |
| + // returns a nullptr from operator() call. |
| + virtual bool Paint(DesktopFrame* frame, DesktopRegion* updated_region) = 0; |
| + |
| + DesktopSize size_; |
| + bool return_frame_; |
| + bool provide_updated_region_hints_; |
| + bool enlarge_updated_region_; |
| + int enlarge_range_; |
| + bool add_random_updated_region_; |
| +}; |
| + |
| +// An implementation of BaseDesktopFrameGenerator to paint block on |
| +// mutable_updated_region(), and white elsewhere. |
| +class BlackWhiteDesktopFrameGenerator : public BaseDesktopFrameGenerator { |
| + public: |
| + BlackWhiteDesktopFrameGenerator(); |
| + ~BlackWhiteDesktopFrameGenerator() override; |
| + |
| + // The black regions of the frame which will be returned in next operator() |
| + // call. BlackWhiteDesktopFrameGenerator will return a white frame, with black |
| + // in the |
| + // updated_region_. Each operator() call with return_frame_ as true will |
| + // consume updated_region_. |
| + DesktopRegion* updated_region(); |
| + |
| + private: |
| + bool Paint(DesktopFrame* frame, DesktopRegion* updated_region) override; |
| + |
| + DesktopRegion updated_region_; |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_ |