| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_HOST_CAPTURER_H_ | |
| 6 #define REMOTING_HOST_CAPTURER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "media/base/video_frame.h" | |
| 11 #include "third_party/skia/include/core/SkRegion.h" | |
| 12 | |
| 13 namespace remoting { | |
| 14 | |
| 15 namespace protocol { | |
| 16 class CursorShapeInfo; | |
| 17 } | |
| 18 | |
| 19 class CaptureData; | |
| 20 | |
| 21 // A class to perform the task of capturing the image of a window. | |
| 22 // The capture action is asynchronous to allow maximum throughput. | |
| 23 // | |
| 24 // The full capture process is as follows: | |
| 25 // | |
| 26 // (1) Start | |
| 27 // This is when pre-capture steps are executed, such as flagging the | |
| 28 // display to prevent it from sleeping during a session. | |
| 29 // | |
| 30 // (2) InvalidateRects | |
| 31 // This is an optional step where regions of the screen are marked as | |
| 32 // invalid. Some platforms (Windows, for now) won't use this and will | |
| 33 // instead calculate the diff-regions later (in step (2). Other | |
| 34 // platforms (Mac) will use this to mark all the changed regions of the | |
| 35 // screen. Some limited rect-merging (e.g., to eliminate exact | |
| 36 // duplicates) may be done here. | |
| 37 // | |
| 38 // (3) CaptureInvalidRects | |
| 39 // This is where the bits for the invalid rects are packaged up and sent | |
| 40 // to the encoder. | |
| 41 // A screen capture is performed if needed. For example, Windows requires | |
| 42 // a capture to calculate the diff from the previous screen, whereas the | |
| 43 // Mac version does not. | |
| 44 // | |
| 45 // (4) Stop | |
| 46 // This is when post-capture steps are executed, such as releasing the | |
| 47 // assertion that prevents the display from sleeping. | |
| 48 // | |
| 49 // Implementation has to ensure the following guarantees: | |
| 50 // 1. Double buffering | |
| 51 // Since data can be read while another capture action is happening. | |
| 52 class Capturer { | |
| 53 public: | |
| 54 // CaptureCompletedCallback is called when the capturer has completed. | |
| 55 typedef base::Callback<void(scoped_refptr<CaptureData>)> | |
| 56 CaptureCompletedCallback; | |
| 57 | |
| 58 // CursorShapeChangedCallback is called when the cursor shape has changed. | |
| 59 typedef base::Callback<void(scoped_ptr<protocol::CursorShapeInfo>)> | |
| 60 CursorShapeChangedCallback; | |
| 61 | |
| 62 virtual ~Capturer() {}; | |
| 63 | |
| 64 // Create platform-specific capturer. | |
| 65 static Capturer* Create(); | |
| 66 | |
| 67 #if defined(OS_LINUX) | |
| 68 // Set whether the Capturer should try to use X DAMAGE support if it is | |
| 69 // available. This needs to be called before the Capturer is created. | |
| 70 // This is used by the Virtual Me2Me host, since the XDamage extension is | |
| 71 // known to work reliably in this case. | |
| 72 | |
| 73 // TODO(lambroslambrou): This currently sets a global flag, referenced during | |
| 74 // Capturer::Create(). This is a temporary solution, until the | |
| 75 // DesktopEnvironment class is refactored to allow applications to control | |
| 76 // the creation of various stubs (including the Capturer) - see | |
| 77 // http://crbug.com/104544 | |
| 78 static void EnableXDamage(bool enable); | |
| 79 #endif // defined(OS_LINUX) | |
| 80 | |
| 81 // Called at the beginning of a capturing session. | |
| 82 virtual void Start( | |
| 83 const CursorShapeChangedCallback& callback) = 0; | |
| 84 | |
| 85 // Called at the end of a capturing session. | |
| 86 virtual void Stop() = 0; | |
| 87 | |
| 88 // Called when the screen configuration is changed. | |
| 89 virtual void ScreenConfigurationChanged() = 0; | |
| 90 | |
| 91 // Return the pixel format of the screen. | |
| 92 virtual media::VideoFrame::Format pixel_format() const = 0; | |
| 93 | |
| 94 // Clear out the invalid region. | |
| 95 virtual void ClearInvalidRegion() = 0; | |
| 96 | |
| 97 // Invalidate the specified region. | |
| 98 virtual void InvalidateRegion(const SkRegion& invalid_region) = 0; | |
| 99 | |
| 100 // Invalidate the entire screen, of a given size. | |
| 101 virtual void InvalidateScreen(const SkISize& size) = 0; | |
| 102 | |
| 103 // Invalidate the entire screen, using the size of the most recently | |
| 104 // captured screen. | |
| 105 virtual void InvalidateFullScreen() = 0; | |
| 106 | |
| 107 // Capture the screen data associated with each of the accumulated | |
| 108 // dirty region. | |
| 109 // When the capture is complete, |callback| is called even if the dirty region | |
| 110 // is empty. | |
| 111 // | |
| 112 // It is OK to call this method while another thread is reading | |
| 113 // data of the previous capture. | |
| 114 // There can be at most one concurrent read going on when this | |
| 115 // method is called. | |
| 116 virtual void CaptureInvalidRegion( | |
| 117 const CaptureCompletedCallback& callback) = 0; | |
| 118 | |
| 119 // Get the size of the most recently captured screen. | |
| 120 virtual const SkISize& size_most_recent() const = 0; | |
| 121 }; | |
| 122 | |
| 123 } // namespace remoting | |
| 124 | |
| 125 #endif // REMOTING_HOST_CAPTURER_H_ | |
| OLD | NEW |