OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Don't include this file in any .h files because it pulls in some X headers. | 5 // Don't include this file in any .h files because it pulls in some X headers. |
6 | 6 |
7 #ifndef MEDIA_VIDEO_CAPTURE_SCREEN_X11_X_SERVER_PIXEL_BUFFER_H_ | 7 #ifndef MEDIA_VIDEO_CAPTURE_SCREEN_X11_X_SERVER_PIXEL_BUFFER_H_ |
8 #define MEDIA_VIDEO_CAPTURE_SCREEN_X11_X_SERVER_PIXEL_BUFFER_H_ | 8 #define MEDIA_VIDEO_CAPTURE_SCREEN_X11_X_SERVER_PIXEL_BUFFER_H_ |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "third_party/skia/include/core/SkRect.h" | 11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
12 | 12 |
13 #include <X11/Xutil.h> | 13 #include <X11/Xutil.h> |
14 #include <X11/extensions/XShm.h> | 14 #include <X11/extensions/XShm.h> |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 // A class to allow the X server's pixel buffer to be accessed as efficiently | 18 // A class to allow the X server's pixel buffer to be accessed as efficiently |
19 // as possible. | 19 // as possible. |
20 class XServerPixelBuffer { | 20 class XServerPixelBuffer { |
21 public: | 21 public: |
22 XServerPixelBuffer(); | 22 XServerPixelBuffer(); |
23 ~XServerPixelBuffer(); | 23 ~XServerPixelBuffer(); |
24 | 24 |
25 void Release(); | 25 void Release(); |
26 | 26 |
27 // Allocate (or reallocate) the pixel buffer with the given size, which is | 27 // Allocate (or reallocate) the pixel buffer with the given size, which is |
28 // assumed to be the current size of the root window. | 28 // assumed to be the current size of the root window. |
29 // |screen_size| should either come from GetRootWindowSize(), or | 29 // |screen_size| should either come from GetRootWindowSize(), or |
30 // from a recent ConfigureNotify event on the root window. | 30 // from a recent ConfigureNotify event on the root window. |
31 void Init(Display* display, const SkISize& screen_size); | 31 void Init(Display* display, const webrtc::DesktopSize& screen_size); |
32 | 32 |
33 // Request the current size of the root window from the X Server. | 33 // Request the current size of the root window from the X Server. |
34 static SkISize GetRootWindowSize(Display* display); | 34 static webrtc::DesktopSize GetRootWindowSize(Display* display); |
35 | 35 |
36 // If shared memory is being used without pixmaps, synchronize this pixel | 36 // If shared memory is being used without pixmaps, synchronize this pixel |
37 // buffer with the root window contents (otherwise, this is a no-op). | 37 // buffer with the root window contents (otherwise, this is a no-op). |
38 // This is to avoid doing a full-screen capture for each individual | 38 // This is to avoid doing a full-screen capture for each individual |
39 // rectangle in the capture list, when it only needs to be done once at the | 39 // rectangle in the capture list, when it only needs to be done once at the |
40 // beginning. | 40 // beginning. |
41 void Synchronize(); | 41 void Synchronize(); |
42 | 42 |
43 // Capture the specified rectangle and return a pointer to its top-left pixel | 43 // Capture the specified rectangle and return a pointer to its top-left pixel |
44 // or NULL if capture fails. The returned pointer remains valid until the next | 44 // or NULL if capture fails. The returned pointer remains valid until the next |
45 // call to CaptureRect. | 45 // call to CaptureRect. |
46 // In the case where the full-screen data is captured by Synchronize(), this | 46 // In the case where the full-screen data is captured by Synchronize(), this |
47 // simply returns the pointer without doing any more work. | 47 // simply returns the pointer without doing any more work. |
48 // The caller must ensure that |rect| is no larger than the screen size | 48 // The caller must ensure that |rect| is no larger than the screen size |
49 // supplied to Init(). | 49 // supplied to Init(). |
50 uint8* CaptureRect(const SkIRect& rect); | 50 uint8* CaptureRect(const webrtc::DesktopRect& rect); |
51 | 51 |
52 // Return information about the most recent capture. This is only guaranteed | 52 // Return information about the most recent capture. This is only guaranteed |
53 // to be valid between CaptureRect calls. | 53 // to be valid between CaptureRect calls. |
54 int GetStride() const; | 54 int GetStride() const; |
55 int GetDepth() const; | 55 int GetDepth() const; |
56 int GetBitsPerPixel() const; | 56 int GetBitsPerPixel() const; |
57 int GetRedMask() const; | 57 int GetRedMask() const; |
58 int GetBlueMask() const; | 58 int GetBlueMask() const; |
59 int GetGreenMask() const; | 59 int GetGreenMask() const; |
60 | 60 |
61 private: | 61 private: |
62 void InitShm(int screen); | 62 void InitShm(int screen); |
63 bool InitPixmaps(int depth); | 63 bool InitPixmaps(int depth); |
64 | 64 |
65 Display* display_; | 65 Display* display_; |
66 Window root_window_; | 66 Window root_window_; |
67 SkISize root_window_size_; | 67 webrtc::DesktopSize root_window_size_; |
68 XImage* x_image_; | 68 XImage* x_image_; |
69 XShmSegmentInfo* shm_segment_info_; | 69 XShmSegmentInfo* shm_segment_info_; |
70 Pixmap shm_pixmap_; | 70 Pixmap shm_pixmap_; |
71 GC shm_gc_; | 71 GC shm_gc_; |
72 | 72 |
73 DISALLOW_COPY_AND_ASSIGN(XServerPixelBuffer); | 73 DISALLOW_COPY_AND_ASSIGN(XServerPixelBuffer); |
74 }; | 74 }; |
75 | 75 |
76 } // namespace media | 76 } // namespace media |
77 | 77 |
78 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_X11_X_SERVER_PIXEL_BUFFER_H_ | 78 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_X11_X_SERVER_PIXEL_BUFFER_H_ |
OLD | NEW |