OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/task.h" |
| 12 #include "gfx/rect.h" |
| 13 #include "remoting/base/protocol/chromotocol.pb.h" |
| 14 |
| 15 namespace remoting { |
| 16 |
| 17 typedef std::vector<gfx::Rect> DirtyRects; |
| 18 |
| 19 // A class to perform the task of capturing the image of a window. |
| 20 // The capture action is asynchronous to allow maximum throughput. |
| 21 // |
| 22 // Implementation has to ensure the following gurantees: |
| 23 // 1. Double buffering |
| 24 // Since data can be read while another capture action is |
| 25 // happening. |
| 26 class Capturer { |
| 27 public: |
| 28 Capturer(); |
| 29 virtual ~Capturer(); |
| 30 |
| 31 // Capture the full screen. When the action is completed |done_task| |
| 32 // is called. |
| 33 // |
| 34 // It is OK to call this methods while another thread is reading |
| 35 // data of the last capture. |
| 36 // There can be at most one concurrent read going on when this |
| 37 // methods is called. |
| 38 virtual void CaptureFullScreen(Task* done_task) = 0; |
| 39 |
| 40 // Capture the updated regions since last capture. If the last |
| 41 // capture doesn't exist, the full window is captured. |
| 42 // |
| 43 // When complete |done_task| is called. |
| 44 // |
| 45 // It is OK to call this method while another thread is reading |
| 46 // data of the last capture. |
| 47 // There can be at most one concurrent read going on when this |
| 48 // methods is called. |
| 49 virtual void CaptureDirtyRects(Task* done_task) = 0; |
| 50 |
| 51 // Capture the specified screen rect and call |done_task| when complete. |
| 52 // Dirty or invalid regions are ignored and only the given |rect| area is |
| 53 // captured. |
| 54 // |
| 55 // It is OK to call this method while another thread is reading |
| 56 // data of the last capture. |
| 57 // There can be at most one concurrent read going on when this |
| 58 // methods is called. |
| 59 virtual void CaptureRect(const gfx::Rect& rect, Task* done_task) = 0; |
| 60 |
| 61 // Get the image data of the last capture. The pointers to data is |
| 62 // written to |planes|. |planes| should be an array of 3 elements. |
| 63 virtual void GetData(const uint8* planes[]) const = 0; |
| 64 |
| 65 // Get the image data stride of the last capture. This size of strides |
| 66 // is written to |strides|. |strides| should be array of 3 elements. |
| 67 virtual void GetDataStride(int strides[]) const = 0; |
| 68 |
| 69 // Get the list of updated rectangles in the last capture. The result is |
| 70 // written into |rects|. |
| 71 virtual void GetDirtyRects(DirtyRects* rects) const; |
| 72 |
| 73 // Get the width of the image captured. |
| 74 virtual int GetWidth() const; |
| 75 |
| 76 // Get the height of the image captured. |
| 77 virtual int GetHeight() const; |
| 78 |
| 79 // Get the pixel format of the image captured. |
| 80 virtual chromotocol_pb::PixelFormat GetPixelFormat() const; |
| 81 |
| 82 // Invalidate the specified screen rect. |
| 83 virtual void InvalidateRect(gfx::Rect dirty); |
| 84 |
| 85 protected: |
| 86 // Finish/cleanup capture task. |
| 87 // This should be called at the end of each of the CaptureXxx() routines. |
| 88 // This routine should (at least): |
| 89 // (1) Call the |done_task| routine. |
| 90 // (2) Select the next screen buffer. |
| 91 // Note that capturers are required to be double-buffered so that we can |
| 92 // read from one which capturing into another. |
| 93 virtual void FinishCapture(Task* done_task); |
| 94 |
| 95 // Number of screen buffers. |
| 96 static const int kNumBuffers = 2; |
| 97 |
| 98 // Capture screen dimensions. |
| 99 int width_; |
| 100 int height_; |
| 101 |
| 102 // Format of pixels returned in buffer. |
| 103 chromotocol_pb::PixelFormat pixel_format_; |
| 104 |
| 105 // Information about screen. |
| 106 int bytes_per_pixel_; |
| 107 int bytes_per_row_; |
| 108 |
| 109 // The current buffer with valid data for reading. |
| 110 int current_buffer_; |
| 111 |
| 112 // List of dirty rects. |
| 113 // These are the rects that we send to the client to update. |
| 114 DirtyRects dirty_rects_; |
| 115 |
| 116 // Rects that have been manually invalidated (through InvalidateRect). |
| 117 // These will be merged into |dirty_rects_| during the next capture. |
| 118 DirtyRects inval_rects_; |
| 119 }; |
| 120 |
| 121 } // namespace remoting |
| 122 |
| 123 #endif // REMOTING_HOST_CAPTURER_H_ |
OLD | NEW |