diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-01 15:02:53 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-01 15:02:53 +0000 |
commit | 804c99625cc375da683a6c1a681178b0014e02fe (patch) | |
tree | 444c6deffd05f7744f0d2b50077aeabde0cc7170 /remoting/host/capturer.h | |
parent | 9da1cedf45ee5bb54cc5558ca044dc24b999b8d9 (diff) | |
download | chromium_src-804c99625cc375da683a6c1a681178b0014e02fe.zip chromium_src-804c99625cc375da683a6c1a681178b0014e02fe.tar.gz chromium_src-804c99625cc375da683a6c1a681178b0014e02fe.tar.bz2 |
Revamp capturer to clean up the interface, and to keep data as atomic as possible when making calls across threads.
TEST=build remoting
BUG=none
Review URL: http://codereview.chromium.org/2805025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/capturer.h')
-rw-r--r-- | remoting/host/capturer.h | 131 |
1 files changed, 89 insertions, 42 deletions
diff --git a/remoting/host/capturer.h b/remoting/host/capturer.h index 77a8aad..6e16098 100644 --- a/remoting/host/capturer.h +++ b/remoting/host/capturer.h @@ -8,13 +8,15 @@ #include <vector> #include "base/basictypes.h" +#include "base/callback.h" +#include "base/lock.h" #include "base/task.h" #include "gfx/rect.h" #include "remoting/base/protocol/chromotocol.pb.h" namespace remoting { -typedef std::vector<gfx::Rect> DirtyRects; +typedef std::vector<gfx::Rect> RectVector; // A class to perform the task of capturing the image of a window. // The capture action is asynchronous to allow maximum throughput. @@ -25,72 +27,118 @@ typedef std::vector<gfx::Rect> DirtyRects; // happening. class Capturer { public: + + struct DataPlanes { + static const int kPlaneCount = 3; + uint8* data[kPlaneCount]; + int strides[kPlaneCount]; + + DataPlanes() { + for (int i = 0; i < kPlaneCount; ++i) { + data[i] = NULL; + strides[i] = 0; + } + } + }; + + // Stores the data and information of a capture to pass off to the + // encoding thread. + class CaptureData : public base::RefCountedThreadSafe<CaptureData> { + public: + CaptureData(const DataPlanes &data_planes, + int width, + int height, + PixelFormat format) : + data_planes_(data_planes), dirty_rects_(), + width_(width), height_(height), pixel_format_(format) { } + + // Get the data_planes data of the last capture. + const DataPlanes& data_planes() const { return data_planes_; } + + // Get the list of updated rectangles in the last capture. The result is + // written into |rects|. + const RectVector& dirty_rects() const { return dirty_rects_; } + + // Get the width of the image captured. + int width() const { return width_; } + + // Get the height of the image captured. + int height() const { return height_; } + + // Get the pixel format of the image captured. + PixelFormat pixel_format() const { return pixel_format_; } + + // Mutating methods. + RectVector& mutable_dirty_rects() { return dirty_rects_; } + + private: + const DataPlanes data_planes_; + RectVector dirty_rects_; + int width_; + int height_; + PixelFormat pixel_format_; + + friend class base::RefCountedThreadSafe<CaptureData>; + ~CaptureData() {} + }; + + // CaptureCompletedCallback is called when the capturer has completed. + typedef Callback1<scoped_refptr<CaptureData> >::Type CaptureCompletedCallback; + Capturer(); virtual ~Capturer(); - // Capture the full screen. When the action is completed |done_task| - // is called. - // - // It is OK to call this method while another thread is reading - // data of the last capture. - // There can be at most one concurrent read going on when this - // method is called. - virtual void CaptureFullScreen(Task* done_task) = 0; // Capture the updated regions since last capture. If the last // capture doesn't exist, the full window is captured. // - // When complete |done_task| is called. + // When complete |callback| is called. // // It is OK to call this method while another thread is reading // data of the last capture. // There can be at most one concurrent read going on when this // method is called. - virtual void CaptureDirtyRects(Task* done_task) = 0; + virtual void CaptureInvalidRects(CaptureCompletedCallback* callback); - // Capture the specified screen rect and call |done_task| when complete. - // Dirty or invalid regions are ignored and only the given |rect| area is + // Capture the specified screen rects and call |callback| when complete. + // Dirty or invalid regions are ignored and only the given |rects| areas are // captured. // // It is OK to call this method while another thread is reading // data of the last capture. // There can be at most one concurrent read going on when this // method is called. - virtual void CaptureRect(const gfx::Rect& rect, Task* done_task) = 0; - - // Get the image data of the last capture. The pointers to data is - // written to |planes|. |planes| should be an array of 3 elements. - virtual void GetData(const uint8* planes[]) const = 0; + virtual void CaptureRects(const RectVector& rects, + CaptureCompletedCallback* callback) = 0; - // Get the image data stride of the last capture. The size of strides - // is written to |strides|. |strides| should be array of 3 elements. - virtual void GetDataStride(int strides[]) const = 0; + // Invalidate the specified screen rects. + virtual void InvalidateRects(const RectVector& inval_rects); - // Get the list of updated rectangles in the last capture. The result is - // written into |rects|. - virtual void GetDirtyRects(DirtyRects* rects) const; + // Invalidate the entire screen. + virtual void InvalidateFullScreen(); - // Get the width of the image captured. - virtual int GetWidth() const; + // Called when the screen configuration is changed. + virtual void ScreenConfigurationChanged() = 0; - // Get the height of the image captured. - virtual int GetHeight() const; + // Return the width of the screen. + virtual int width() const { return width_; } - // Get the pixel format of the image captured. - virtual PixelFormat GetPixelFormat() const; + // Return the height of the screen + virtual int height() const { return height_; } - // Invalidate the specified screen rect. - virtual void InvalidateRect(gfx::Rect dirty); + // Return the pixel format of the screen + virtual PixelFormat pixel_format() const { return pixel_format_; } protected: // Finish/cleanup capture task. // This should be called at the end of each of the CaptureXxx() routines. // This routine should (at least): - // (1) Call the |done_task| routine. + // (1) Call the |callback| routine. // (2) Select the next screen buffer. // Note that capturers are required to be double-buffered so that we can // read from one which capturing into another. - virtual void FinishCapture(Task* done_task); + virtual void FinishCapture(scoped_refptr<CaptureData> data, + CaptureCompletedCallback* callback); // Number of screen buffers. static const int kNumBuffers = 2; @@ -101,21 +149,20 @@ class Capturer { // Format of pixels returned in buffer. PixelFormat pixel_format_; - - // Information about screen. - int bytes_per_pixel_; int bytes_per_row_; // The current buffer with valid data for reading. int current_buffer_; - // List of dirty rects. - // These are the rects that we send to the client to update. - DirtyRects dirty_rects_; + private: // Rects that have been manually invalidated (through InvalidateRect). - // These will be merged into |dirty_rects_| during the next capture. - DirtyRects inval_rects_; + // These will be returned as dirty_rects in the capture data during the next + // capture. + RectVector inval_rects_; + + // A lock protecting |inval_rects_| across threads. + Lock inval_rects_lock_; }; } // namespace remoting |