| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "remoting/host/capturer.h" | 5 #include "remoting/host/capturer.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #include <X11/Xutil.h> | 8 #include <X11/Xutil.h> |
| 9 #include <X11/extensions/Xdamage.h> | 9 #include <X11/extensions/Xdamage.h> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 public: | 34 public: |
| 35 VideoFrameBuffer() : bytes_per_row_(0), needs_update_(true) {} | 35 VideoFrameBuffer() : bytes_per_row_(0), needs_update_(true) {} |
| 36 | 36 |
| 37 void Update(Display* display, Window root_window) { | 37 void Update(Display* display, Window root_window) { |
| 38 if (needs_update_) { | 38 if (needs_update_) { |
| 39 needs_update_ = false; | 39 needs_update_ = false; |
| 40 XWindowAttributes root_attr; | 40 XWindowAttributes root_attr; |
| 41 XGetWindowAttributes(display, root_window, &root_attr); | 41 XGetWindowAttributes(display, root_window, &root_attr); |
| 42 if (root_attr.width != size_.width() || | 42 if (root_attr.width != size_.width() || |
| 43 root_attr.height != size_.height()) { | 43 root_attr.height != size_.height()) { |
| 44 size_.SetSize(root_attr.width, root_attr.height); | 44 size_.set(root_attr.width, root_attr.height); |
| 45 bytes_per_row_ = size_.width() * kBytesPerPixel; | 45 bytes_per_row_ = size_.width() * kBytesPerPixel; |
| 46 size_t buffer_size = size_.width() * size_.height() * kBytesPerPixel; | 46 size_t buffer_size = size_.width() * size_.height() * kBytesPerPixel; |
| 47 ptr_.reset(new uint8[buffer_size]); | 47 ptr_.reset(new uint8[buffer_size]); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 gfx::Size size() const { return size_; } | 52 SkISize size() const { return size_; } |
| 53 int bytes_per_row() const { return bytes_per_row_; } | 53 int bytes_per_row() const { return bytes_per_row_; } |
| 54 uint8* ptr() const { return ptr_.get(); } | 54 uint8* ptr() const { return ptr_.get(); } |
| 55 | 55 |
| 56 void set_needs_update() { needs_update_ = true; } | 56 void set_needs_update() { needs_update_ = true; } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 gfx::Size size_; | 59 SkISize size_; |
| 60 int bytes_per_row_; | 60 int bytes_per_row_; |
| 61 scoped_array<uint8> ptr_; | 61 scoped_array<uint8> ptr_; |
| 62 bool needs_update_; | 62 bool needs_update_; |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer); | 64 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // A class to perform capturing for Linux. | 67 // A class to perform capturing for Linux. |
| 68 class CapturerLinux : public Capturer { | 68 class CapturerLinux : public Capturer { |
| 69 public: | 69 public: |
| 70 CapturerLinux(); | 70 CapturerLinux(); |
| 71 virtual ~CapturerLinux(); | 71 virtual ~CapturerLinux(); |
| 72 | 72 |
| 73 bool Init(); // TODO(ajwong): Do we really want this to be synchronous? | 73 bool Init(); // TODO(ajwong): Do we really want this to be synchronous? |
| 74 | 74 |
| 75 // Capturer interface. | 75 // Capturer interface. |
| 76 virtual void ScreenConfigurationChanged() OVERRIDE; | 76 virtual void ScreenConfigurationChanged() OVERRIDE; |
| 77 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 77 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
| 78 virtual void ClearInvalidRegion() OVERRIDE; | 78 virtual void ClearInvalidRegion() OVERRIDE; |
| 79 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 79 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
| 80 virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; | 80 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; |
| 81 virtual void InvalidateFullScreen() OVERRIDE; | 81 virtual void InvalidateFullScreen() OVERRIDE; |
| 82 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) | 82 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) |
| 83 OVERRIDE; | 83 OVERRIDE; |
| 84 virtual const gfx::Size& size_most_recent() const OVERRIDE; | 84 virtual const SkISize& size_most_recent() const OVERRIDE; |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 void InitXDamage(); | 87 void InitXDamage(); |
| 88 | 88 |
| 89 // Read and handle all currently-pending XEvents. | 89 // Read and handle all currently-pending XEvents. |
| 90 // In the DAMAGE case, process the XDamage events and store the resulting | 90 // In the DAMAGE case, process the XDamage events and store the resulting |
| 91 // damage rectangles in the CapturerHelper. | 91 // damage rectangles in the CapturerHelper. |
| 92 // In all cases, call ScreenConfigurationChanged() in response to any | 92 // In all cases, call ScreenConfigurationChanged() in response to any |
| 93 // ConfigNotify events. | 93 // ConfigNotify events. |
| 94 void ProcessPendingXEvents(); | 94 void ProcessPendingXEvents(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 247 } |
| 248 | 248 |
| 249 void CapturerLinux::ClearInvalidRegion() { | 249 void CapturerLinux::ClearInvalidRegion() { |
| 250 helper_.ClearInvalidRegion(); | 250 helper_.ClearInvalidRegion(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void CapturerLinux::InvalidateRegion(const SkRegion& invalid_region) { | 253 void CapturerLinux::InvalidateRegion(const SkRegion& invalid_region) { |
| 254 helper_.InvalidateRegion(invalid_region); | 254 helper_.InvalidateRegion(invalid_region); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void CapturerLinux::InvalidateScreen(const gfx::Size& size) { | 257 void CapturerLinux::InvalidateScreen(const SkISize& size) { |
| 258 helper_.InvalidateScreen(size); | 258 helper_.InvalidateScreen(size); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void CapturerLinux::InvalidateFullScreen() { | 261 void CapturerLinux::InvalidateFullScreen() { |
| 262 helper_.InvalidateFullScreen(); | 262 helper_.InvalidateFullScreen(); |
| 263 last_buffer_ = NULL; | 263 last_buffer_ = NULL; |
| 264 } | 264 } |
| 265 | 265 |
| 266 void CapturerLinux::CaptureInvalidRegion( | 266 void CapturerLinux::CaptureInvalidRegion( |
| 267 CaptureCompletedCallback* callback) { | 267 CaptureCompletedCallback* callback) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 uint32_t b = (((pixel & blue_mask) >> blue_shift) * 255) / max_blue; | 492 uint32_t b = (((pixel & blue_mask) >> blue_shift) * 255) / max_blue; |
| 493 uint32_t g = (((pixel & green_mask) >> green_shift) * 255) / max_green; | 493 uint32_t g = (((pixel & green_mask) >> green_shift) * 255) / max_green; |
| 494 // Write as 32-bit RGB. | 494 // Write as 32-bit RGB. |
| 495 dst_pos_32[x] = r << 16 | g << 8 | b; | 495 dst_pos_32[x] = r << 16 | g << 8 | b; |
| 496 } | 496 } |
| 497 dst_pos += dst_stride; | 497 dst_pos += dst_stride; |
| 498 src_pos += src_stride; | 498 src_pos += src_stride; |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 const gfx::Size& CapturerLinux::size_most_recent() const { | 502 const SkISize& CapturerLinux::size_most_recent() const { |
| 503 return helper_.size_most_recent(); | 503 return helper_.size_most_recent(); |
| 504 } | 504 } |
| 505 | 505 |
| 506 } // namespace | 506 } // namespace |
| 507 | 507 |
| 508 // static | 508 // static |
| 509 Capturer* Capturer::Create() { | 509 Capturer* Capturer::Create() { |
| 510 CapturerLinux* capturer = new CapturerLinux(); | 510 CapturerLinux* capturer = new CapturerLinux(); |
| 511 if (!capturer->Init()) { | 511 if (!capturer->Init()) { |
| 512 delete capturer; | 512 delete capturer; |
| 513 capturer = NULL; | 513 capturer = NULL; |
| 514 } | 514 } |
| 515 return capturer; | 515 return capturer; |
| 516 } | 516 } |
| 517 | 517 |
| 518 } // namespace remoting | 518 } // namespace remoting |
| OLD | NEW |