Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_ | |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/modules/desktop_capture/desktop_frame.h" | |
| 17 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 18 #include "webrtc/modules/desktop_capture/desktop_region.h" | |
| 19 #include "webrtc/modules/desktop_capture/shared_memory.h" | |
| 20 | |
| 21 namespace webrtc { | |
| 22 | |
| 23 // A functor to generate a DesktopFrame. | |
| 24 class DesktopFrameGenerator { | |
| 25 public: | |
| 26 DesktopFrameGenerator(); | |
| 27 virtual ~DesktopFrameGenerator(); | |
| 28 | |
| 29 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.
| |
| 30 SharedMemoryFactory* factory) = 0; | |
| 31 }; | |
| 32 | |
| 33 // A base implementation of DesktopFrameGenerator to take care about the | |
| 34 // DesktopFrame | |
| 35 // size, filling updated_region(), etc, but only requires derived classes to | |
| 36 // implement the Paint() function. | |
| 37 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
| |
| 38 public: | |
| 39 BaseDesktopFrameGenerator(); | |
| 40 ~BaseDesktopFrameGenerator() override; | |
| 41 | |
| 42 std::unique_ptr<DesktopFrame> operator()(SharedMemoryFactory* factory) final; | |
| 43 | |
| 44 // Sets the size of the frame which will be returned in next operator() | |
| 45 // call. | |
| 46 DesktopSize* size(); | |
| 47 | |
| 48 // Decides whether BaseDesktopFrameGenerator returns a frame in next Capture() | |
| 49 // callback. If return_frame_ is true, BaseDesktopFrameGenerator will create a | |
| 50 // frame according to both size_ and SharedMemoryFactory input, and uses | |
| 51 // Paint() function to paint it. | |
| 52 void set_return_frame(bool return_frame); | |
| 53 | |
| 54 // Decides whether MockScreenCapturer returns a frame with updated regions. | |
| 55 // MockScreenCapturer will keep DesktopFrame::updated_region() empty if this | |
| 56 // field is false. | |
| 57 void set_provide_updated_region_hints(bool provide_updated_region_hints); | |
| 58 | |
| 59 // Decides whether MockScreenCapturer randomly enlarges updated regions in the | |
| 60 // DesktopFrame. Set this field to true to simulate an inaccurate updated | |
| 61 // regions' return from OS APIs. | |
| 62 void set_enlarge_updated_region(bool enlarge_updated_region); | |
| 63 | |
| 64 // The range to enlarge a updated region if |enlarge_updated_region_| is true. | |
| 65 // If this field is less than zero, it will be treated as zero, and | |
| 66 // |enlarge_updated_region_| will be ignored. | |
| 67 void set_enlarge_range(int enlarge_range); | |
| 68 | |
| 69 // Decides whether BaseDesktopFrameGenerator randomly add some updated regions | |
| 70 // in the | |
| 71 // DesktopFrame. Set this field to true to simulate an inaccurate updated | |
| 72 // regions' return from OS APIs. | |
| 73 void set_add_random_updated_region(bool add_random_updated_region); | |
| 74 | |
| 75 private: | |
| 76 // Paints on the |frame|, and updates |updated_region| to indicate | |
| 77 // rectangles painted. If this function returns false, | |
| 78 // BaseDesktopFrameGenerator will | |
| 79 // returns a nullptr from operator() call. | |
| 80 virtual bool Paint(DesktopFrame* frame, DesktopRegion* updated_region) = 0; | |
| 81 | |
| 82 DesktopSize size_; | |
| 83 bool return_frame_; | |
| 84 bool provide_updated_region_hints_; | |
| 85 bool enlarge_updated_region_; | |
| 86 int enlarge_range_; | |
| 87 bool add_random_updated_region_; | |
| 88 }; | |
| 89 | |
| 90 // An implementation of BaseDesktopFrameGenerator to paint block on | |
| 91 // mutable_updated_region(), and white elsewhere. | |
| 92 class BlackWhiteDesktopFrameGenerator : public BaseDesktopFrameGenerator { | |
| 93 public: | |
| 94 BlackWhiteDesktopFrameGenerator(); | |
| 95 ~BlackWhiteDesktopFrameGenerator() override; | |
| 96 | |
| 97 // The black regions of the frame which will be returned in next operator() | |
| 98 // call. BlackWhiteDesktopFrameGenerator will return a white frame, with black | |
| 99 // in the | |
| 100 // updated_region_. Each operator() call with return_frame_ as true will | |
| 101 // consume updated_region_. | |
| 102 DesktopRegion* updated_region(); | |
| 103 | |
| 104 private: | |
| 105 bool Paint(DesktopFrame* frame, DesktopRegion* updated_region) override; | |
| 106 | |
| 107 DesktopRegion updated_region_; | |
| 108 }; | |
| 109 | |
| 110 } // namespace webrtc | |
| 111 | |
| 112 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_ | |
| OLD | NEW |