2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 // Don't include this file in any .h files because it pulls in some X headers.
13 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_X11_X_SERVER_PIXEL_BUFFER_H_
14 #define WEBRTC_MODULES_DESKTOP_CAPTURE_X11_X_SERVER_PIXEL_BUFFER_H_
16 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
18 #include <X11/Xutil.h>
19 #include <X11/extensions/XShm.h>
25 // A class to allow the X server's pixel buffer to be accessed as efficiently
27 class XServerPixelBuffer {
30 ~XServerPixelBuffer();
34 // Allocate (or reallocate) the pixel buffer for |window|. Returns false in
35 // case of an error (e.g. window doesn't exist).
36 bool Init(Display* display, Window window);
38 bool is_initialized() { return window_ != 0; }
40 // Returns the size of the window the buffer was initialized for.
41 const DesktopSize& window_size() { return window_size_; }
43 // Returns true if the window can be found.
44 bool IsWindowValid() const;
46 // If shared memory is being used without pixmaps, synchronize this pixel
47 // buffer with the root window contents (otherwise, this is a no-op).
48 // This is to avoid doing a full-screen capture for each individual
49 // rectangle in the capture list, when it only needs to be done once at the
53 // Capture the specified rectangle and stores it in the |frame|. In the case
54 // where the full-screen data is captured by Synchronize(), this simply
55 // returns the pointer without doing any more work. The caller must ensure
56 // that |rect| is not larger than window_size().
57 void CaptureRect(const DesktopRect& rect, DesktopFrame* frame);
60 void InitShm(const XWindowAttributes& attributes);
61 bool InitPixmaps(int depth);
63 // We expose two forms of blitting to handle variations in the pixel format.
64 // In FastBlit(), the operation is effectively a memcpy.
65 void FastBlit(uint8_t* image,
66 const DesktopRect& rect,
68 void SlowBlit(uint8_t* image,
69 const DesktopRect& rect,
74 DesktopSize window_size_;
76 XShmSegmentInfo* shm_segment_info_;
80 DISALLOW_COPY_AND_ASSIGN(XServerPixelBuffer);
85 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_X11_X_SERVER_PIXEL_BUFFER_H_