diff options
author | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-03 16:54:48 +0000 |
---|---|---|
committer | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-03 16:54:48 +0000 |
commit | d8a6ca901e27fe58e1385492b0fc0cc8bbccaa10 (patch) | |
tree | 97322432de7e2381eb065cc3af19d53abba6e2f3 /remoting/host | |
parent | 804443aef39615edd5b731aa5bfb3c611aeae697 (diff) | |
download | chromium_src-d8a6ca901e27fe58e1385492b0fc0cc8bbccaa10.zip chromium_src-d8a6ca901e27fe58e1385492b0fc0cc8bbccaa10.tar.gz chromium_src-d8a6ca901e27fe58e1385492b0fc0cc8bbccaa10.tar.bz2 |
Revert 76747 - Let the host change resolution.
The screen size flows through the video pipeline, instead of
being set statically when that pipeline is constructed.
Only the Windows host actually detects when the screen size has changed.
BUG=72469
TEST=none
Review URL: http://codereview.chromium.org/6573005
TBR=simonmorris@chromium.org
Review URL: http://codereview.chromium.org/6610018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76748 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/capturer.cc | 36 | ||||
-rw-r--r-- | remoting/host/capturer.h | 27 | ||||
-rw-r--r-- | remoting/host/capturer_fake.cc | 5 | ||||
-rw-r--r-- | remoting/host/capturer_fake.h | 3 | ||||
-rw-r--r-- | remoting/host/capturer_fake_ascii.cc | 2 | ||||
-rw-r--r-- | remoting/host/capturer_fake_ascii.h | 5 | ||||
-rw-r--r-- | remoting/host/capturer_gdi.cc | 144 | ||||
-rw-r--r-- | remoting/host/capturer_gdi.h | 38 | ||||
-rw-r--r-- | remoting/host/capturer_linux.cc | 25 | ||||
-rw-r--r-- | remoting/host/capturer_mac.cc | 23 | ||||
-rw-r--r-- | remoting/host/capturer_mac.h | 7 | ||||
-rw-r--r-- | remoting/host/chromoting_host.cc | 5 | ||||
-rw-r--r-- | remoting/host/differ.h | 5 | ||||
-rw-r--r-- | remoting/host/event_executor_win.cc | 12 |
14 files changed, 111 insertions, 226 deletions
diff --git a/remoting/host/capturer.cc b/remoting/host/capturer.cc index 0dd09ab..59854f1 100644 --- a/remoting/host/capturer.cc +++ b/remoting/host/capturer.cc @@ -11,16 +11,27 @@ namespace remoting { Capturer::Capturer(MessageLoop* message_loop) - : pixel_format_(media::VideoFrame::INVALID), + : width_(0), + height_(0), + pixel_format_(media::VideoFrame::INVALID), + bytes_per_row_(0), current_buffer_(0), - message_loop_(message_loop), - width_most_recent_(0), - height_most_recent_(0) { + message_loop_(message_loop) { } Capturer::~Capturer() { } +// Return the width of the screen. +int Capturer::width() const { + return width_; +} + +// Return the height of the screen. +int Capturer::height() const { + return height_; +} + // Return the pixel format of the screen. media::VideoFrame::Format Capturer::pixel_format() const { return pixel_format_; @@ -42,14 +53,10 @@ void Capturer::InvalidateRects(const InvalidRects& inval_rects) { } } -void Capturer::InvalidateFullScreen(int width, int height) { +void Capturer::InvalidateFullScreen() { base::AutoLock auto_inval_rects_lock(inval_rects_lock_); inval_rects_.clear(); - inval_rects_.insert(gfx::Rect(0, 0, width, height)); -} - -void Capturer::InvalidateFullScreen() { - InvalidateFullScreen(width_most_recent_, height_most_recent_); + inval_rects_.insert(gfx::Rect(0, 0, width_, height_)); } void Capturer::CaptureInvalidRects(CaptureCompletedCallback* callback) { @@ -74,19 +81,16 @@ void Capturer::FinishCapture(scoped_refptr<CaptureData> data, // Select the next buffer to be the current buffer. current_buffer_ = (current_buffer_ + 1) % kNumBuffers; - width_most_recent_ = data->width(); - height_most_recent_ = data->height(); - callback->Run(data); delete callback; } -bool Capturer::IsCaptureFullScreen(int width, int height) { +bool Capturer::IsCaptureFullScreen() { base::AutoLock auto_inval_rects_lock(inval_rects_lock_); return inval_rects_.size() == 1u && inval_rects_.begin()->x() == 0 && inval_rects_.begin()->y() == 0 && - inval_rects_.begin()->width() == width && - inval_rects_.begin()->height() == height; + inval_rects_.begin()->width() == width_ && + inval_rects_.begin()->height() == height_; } } // namespace remoting diff --git a/remoting/host/capturer.h b/remoting/host/capturer.h index a91dcd7..a769abc 100644 --- a/remoting/host/capturer.h +++ b/remoting/host/capturer.h @@ -52,6 +52,12 @@ class Capturer { // Called when the screen configuration is changed. virtual void ScreenConfigurationChanged() = 0; + // Return the width of the screen. + virtual int width() const; + + // Return the height of the screen. + virtual int height() const; + // Return the pixel format of the screen. virtual media::VideoFrame::Format pixel_format() const; @@ -61,11 +67,7 @@ class Capturer { // Invalidate the specified screen rects. void InvalidateRects(const InvalidRects& inval_rects); - // Invalidate the entire screen, of a given size. - void InvalidateFullScreen(int width, int height); - - // Invalidate the entire screen, using the size of the most recently - // captured screen. + // Invalidate the entire screen. virtual void InvalidateFullScreen(); // Capture the screen data associated with each of the accumulated @@ -83,10 +85,6 @@ class Capturer { // method is called. virtual void CaptureInvalidRects(CaptureCompletedCallback* callback); - // Get the width/height of the most recently captured screen. - int width_most_recent() { return width_most_recent_; } - int height_most_recent() { return height_most_recent_; } - protected: explicit Capturer(MessageLoop* message_loop); @@ -118,13 +116,18 @@ class Capturer { // Called by subclasses' CalculateInvalidRects() method to check if // InvalidateFullScreen() was called by user. - bool IsCaptureFullScreen(int width, int height); + bool IsCaptureFullScreen(); // Number of screen buffers. static const int kNumBuffers = 2; + // Capture screen dimensions. + int width_; + int height_; + // Format of pixels returned in buffer. media::VideoFrame::Format pixel_format_; + int bytes_per_row_; // The current buffer with valid data for reading. int current_buffer_; @@ -140,10 +143,6 @@ class Capturer { // A lock protecting |inval_rects_| across threads. base::Lock inval_rects_lock_; - - // The width and height of the most recently captured screen. - int width_most_recent_; - int height_most_recent_; }; } // namespace remoting diff --git a/remoting/host/capturer_fake.cc b/remoting/host/capturer_fake.cc index a574457..0cc0f37 100644 --- a/remoting/host/capturer_fake.cc +++ b/remoting/host/capturer_fake.cc @@ -26,7 +26,6 @@ static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. CapturerFake::CapturerFake(MessageLoop* message_loop) : Capturer(message_loop), - bytes_per_row_(0), box_pos_x_(0), box_pos_y_(0), box_speed_x_(kSpeed), @@ -40,8 +39,8 @@ CapturerFake::~CapturerFake() { void CapturerFake::ScreenConfigurationChanged() { width_ = kWidth; height_ = kHeight; - bytes_per_row_ = width_ * kBytesPerPixel; pixel_format_ = media::VideoFrame::RGB32; + bytes_per_row_ = width_ * kBytesPerPixel; // Create memory for the buffers. int buffer_size = height_ * bytes_per_row_; @@ -52,7 +51,7 @@ void CapturerFake::ScreenConfigurationChanged() { void CapturerFake::CalculateInvalidRects() { GenerateImage(); - InvalidateFullScreen(width_, height_); + InvalidateFullScreen(); } void CapturerFake::CaptureRects(const InvalidRects& rects, diff --git a/remoting/host/capturer_fake.h b/remoting/host/capturer_fake.h index 420d30e..a6279b7 100644 --- a/remoting/host/capturer_fake.h +++ b/remoting/host/capturer_fake.h @@ -29,9 +29,6 @@ class CapturerFake : public Capturer { // Generates an image in the front buffer. void GenerateImage(); - int width_; - int height_; - int bytes_per_row_; int box_pos_x_; int box_pos_y_; int box_speed_x_; diff --git a/remoting/host/capturer_fake_ascii.cc b/remoting/host/capturer_fake_ascii.cc index 8ea73c4..1729fb6 100644 --- a/remoting/host/capturer_fake_ascii.cc +++ b/remoting/host/capturer_fake_ascii.cc @@ -22,8 +22,8 @@ CapturerFakeAscii::~CapturerFakeAscii() { void CapturerFakeAscii::ScreenConfigurationChanged() { width_ = kWidth; height_ = kHeight; - bytes_per_row_ = width_ * kBytesPerPixel; pixel_format_ = media::VideoFrame::ASCII; + bytes_per_row_ = width_ * kBytesPerPixel; // Create memory for the buffers. int buffer_size = height_ * bytes_per_row_; diff --git a/remoting/host/capturer_fake_ascii.h b/remoting/host/capturer_fake_ascii.h index e68b8b4..cd02bc4 100644 --- a/remoting/host/capturer_fake_ascii.h +++ b/remoting/host/capturer_fake_ascii.h @@ -30,11 +30,6 @@ class CapturerFakeAscii : public Capturer { // Generates an image in the front buffer. void GenerateImage(); - // The screen dimensions. - int width_; - int height_; - int bytes_per_row_; - // We have two buffers for the screen images as required by Capturer. scoped_array<uint8> buffers_[kNumBuffers]; diff --git a/remoting/host/capturer_gdi.cc b/remoting/host/capturer_gdi.cc index 36c8945..bdaf756 100644 --- a/remoting/host/capturer_gdi.cc +++ b/remoting/host/capturer_gdi.cc @@ -18,7 +18,6 @@ CapturerGdi::CapturerGdi(MessageLoop* message_loop) : Capturer(message_loop), desktop_dc_(NULL), memory_dc_(NULL), - dc_size_(0, 0), capture_fullscreen_(true) { memset(target_bitmap_, 0, sizeof(target_bitmap_)); memset(buffers_, 0, sizeof(buffers_)); @@ -35,9 +34,9 @@ void CapturerGdi::ReleaseBuffers() { DeleteObject(target_bitmap_[i]); target_bitmap_[i] = NULL; } - if (buffers_[i].data) { - DeleteObject(buffers_[i].data); - buffers_[i].data = NULL; + if (buffers_[i]) { + DeleteObject(buffers_[i]); + buffers_[i] = NULL; } } @@ -49,149 +48,96 @@ void CapturerGdi::ReleaseBuffers() { } void CapturerGdi::ScreenConfigurationChanged() { - // We poll for screen configuration changes, so ignore notifications. -} - -void CapturerGdi::UpdateBufferCapture(const gfx::Size& size) { - // Make sure the DCs have the correct dimensions. - if (size != dc_size_) { - // TODO(simonmorris): screen dimensions changing isn't equivalent to needing - // a new DC, but it's good enough for now. - desktop_dc_ = GetDC(GetDesktopWindow()); - if (memory_dc_) - DeleteDC(memory_dc_); - memory_dc_ = CreateCompatibleDC(desktop_dc_); - dc_size_ = size; - } - - // Make sure the current bitmap has the correct dimensions. - if (size != buffers_[current_buffer_].size) { - ReallocateBuffer(current_buffer_, size); - capture_fullscreen_ = true; - } -} + ReleaseBuffers(); -void CapturerGdi::ReallocateBuffer(int buffer_index, const gfx::Size& size) { - // Delete any previously constructed bitmap. - if (target_bitmap_[buffer_index]) { - DeleteObject(target_bitmap_[buffer_index]); - target_bitmap_[buffer_index] = NULL; - } - if (buffers_[buffer_index].data) { - DeleteObject(buffers_[buffer_index].data); - buffers_[buffer_index].data = NULL; - } + desktop_dc_ = GetDC(GetDesktopWindow()); + memory_dc_ = CreateCompatibleDC(desktop_dc_); // Create a bitmap to keep the desktop image. - int rounded_width = (size.width() + 3) & (~3); + width_ = GetSystemMetrics(SM_CXSCREEN); + height_ = GetSystemMetrics(SM_CYSCREEN); + int rounded_width = (width_ + 3) & (~3); // Dimensions of screen. pixel_format_ = media::VideoFrame::RGB32; - int bytes_per_row = rounded_width * kBytesPerPixel; + bytes_per_row_ = rounded_width * kBytesPerPixel; + + // Create a differ for this screen size. + differ_.reset(new Differ(width_, height_, 4, bytes_per_row_)); - // Create a device independent bitmap (DIB) that is the same size. + // Create a device independant bitmap (DIB) that is the same size. BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); - bmi.bmiHeader.biHeight = -size.height(); - bmi.bmiHeader.biWidth = size.width(); + bmi.bmiHeader.biHeight = -height_; + bmi.bmiHeader.biWidth = width_; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = kBytesPerPixel * 8; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); - bmi.bmiHeader.biSizeImage = bytes_per_row * size.height(); + bmi.bmiHeader.biSizeImage = bytes_per_row_ * height_; bmi.bmiHeader.biXPelsPerMeter = kPixelsPerMeter; bmi.bmiHeader.biYPelsPerMeter = kPixelsPerMeter; // Create memory for the buffers. - target_bitmap_[buffer_index] = - CreateDIBSection(desktop_dc_, &bmi, DIB_RGB_COLORS, - static_cast<void**>(&buffers_[buffer_index].data), - NULL, 0); - buffers_[buffer_index].size = gfx::Size(bmi.bmiHeader.biWidth, - std::abs(bmi.bmiHeader.biHeight)); - buffers_[buffer_index].bytes_per_pixel = bmi.bmiHeader.biBitCount / 8; - buffers_[buffer_index].bytes_per_row = - bmi.bmiHeader.biSizeImage / std::abs(bmi.bmiHeader.biHeight); + for (int i = 0; i < kNumBuffers; i++) { + target_bitmap_[i] = CreateDIBSection(desktop_dc_, &bmi, DIB_RGB_COLORS, + static_cast<void**>(&buffers_[i]), + NULL, 0); + } + + capture_fullscreen_ = true; } void CapturerGdi::CalculateInvalidRects() { CaptureImage(); - const VideoFrameBuffer& current = buffers_[current_buffer_]; - if (IsCaptureFullScreen(current.size.width(), current.size.height())) + if (IsCaptureFullScreen()) capture_fullscreen_ = true; if (capture_fullscreen_) { - InvalidateFullScreen(current.size.width(), current.size.height()); - capture_fullscreen_ = false; - return; - } + InvalidateFullScreen(); + } else { + // Calculate the difference between the previous and current screen. + int prev_buffer_id = current_buffer_ - 1; + if (prev_buffer_id < 0) { + prev_buffer_id = kNumBuffers - 1; + } - // Find the previous and current screens. - int prev_buffer_id = current_buffer_ - 1; - if (prev_buffer_id < 0) { - prev_buffer_id = kNumBuffers - 1; - } - const VideoFrameBuffer& prev = buffers_[prev_buffer_id]; - - // Maybe the previous and current screens can't be differenced. - if ((current.size != prev.size) || - (current.bytes_per_pixel != prev.bytes_per_pixel) || - (current.bytes_per_row != prev.bytes_per_row)) { - InvalidateFullScreen(current.size.width(), current.size.height()); - return; - } + void* prev_buffer = buffers_[prev_buffer_id]; + void* curr_buffer = buffers_[current_buffer_]; - // Make sure the differencer is set up correctly for these previous and - // current screens. - if (!differ_.get() || - (differ_->width() != current.size.width()) || - (differ_->height() != current.size.height()) || - (differ_->bytes_per_pixel() != current.bytes_per_pixel) || - (differ_->bytes_per_row() != current.bytes_per_row)) { - differ_.reset(new Differ(current.size.width(), current.size.height(), - current.bytes_per_pixel, current.bytes_per_row)); - } + InvalidRects rects; + differ_->CalcDirtyRects(prev_buffer, curr_buffer, &rects); - InvalidRects rects; - differ_->CalcDirtyRects(prev.data, current.data, &rects); + InvalidateRects(rects); + } - InvalidateRects(rects); + capture_fullscreen_ = false; } void CapturerGdi::CaptureRects(const InvalidRects& rects, CaptureCompletedCallback* callback) { - const VideoFrameBuffer& buffer = buffers_[current_buffer_]; DataPlanes planes; - planes.data[0] = static_cast<uint8*>(buffer.data); - planes.strides[0] = buffer.bytes_per_row; + planes.data[0] = static_cast<uint8*>(buffers_[current_buffer_]); + planes.strides[0] = bytes_per_row_; scoped_refptr<CaptureData> data(new CaptureData(planes, - buffer.size.width(), - buffer.size.height(), - pixel_format_)); + width(), + height(), + pixel_format())); data->mutable_dirty_rects() = rects; FinishCapture(data, callback); } void CapturerGdi::CaptureImage() { - // Make sure the structures we use to capture the image have the correct size. - UpdateBufferCapture(GetScreenSize()); - // Select the target bitmap into the memory dc. SelectObject(memory_dc_, target_bitmap_[current_buffer_]); // And then copy the rect from desktop to memory. - BitBlt(memory_dc_, 0, 0, buffers_[current_buffer_].size.width(), - buffers_[current_buffer_].size.height(), desktop_dc_, 0, 0, + BitBlt(memory_dc_, 0, 0, width_, height_, desktop_dc_, 0, 0, SRCCOPY | CAPTUREBLT); } -gfx::Size CapturerGdi::GetScreenSize() { - return gfx::Size(GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN)); -} - // static Capturer* Capturer::Create(MessageLoop* message_loop) { return new CapturerGdi(message_loop); diff --git a/remoting/host/capturer_gdi.h b/remoting/host/capturer_gdi.h index 634520e..72aa261 100644 --- a/remoting/host/capturer_gdi.h +++ b/remoting/host/capturer_gdi.h @@ -26,31 +26,6 @@ class CapturerGdi : public Capturer { virtual void ScreenConfigurationChanged(); private: - struct VideoFrameBuffer { - VideoFrameBuffer(void* data, const gfx::Size& size, int bytes_per_pixel, - int bytes_per_row) - : data(data), size(size), bytes_per_pixel(bytes_per_pixel), - bytes_per_row(bytes_per_row) { - } - VideoFrameBuffer() { - data = 0; - size = gfx::Size(0, 0); - bytes_per_pixel = 0; - bytes_per_row = 0; - } - void* data; - gfx::Size size; - int bytes_per_pixel; - int bytes_per_row; - }; - - // Make sure that the current buffer has the same size as the screen. - void UpdateBufferCapture(const gfx::Size& size); - - // Allocate memory for a buffer of a given size, freeing any memory previously - // allocated for that buffer. - void ReallocateBuffer(int buffer_index, const gfx::Size& size); - virtual void CalculateInvalidRects(); virtual void CaptureRects(const InvalidRects& rects, CaptureCompletedCallback* callback); @@ -59,24 +34,13 @@ class CapturerGdi : public Capturer { // Generates an image in the current buffer. void CaptureImage(); - // Gets the current screen size and calls ScreenConfigurationChanged - // if the screen size has changed. - void MaybeChangeScreenConfiguration(); - - // Gets the screen size. - gfx::Size GetScreenSize(); - // Gdi specific information about screen. HDC desktop_dc_; HDC memory_dc_; HBITMAP target_bitmap_[kNumBuffers]; - // The screen size attached to the device contexts through which the screen - // is captured. - gfx::Size dc_size_; - // We have two buffers for the screen images as required by Capturer. - VideoFrameBuffer buffers_[kNumBuffers]; + void* buffers_[kNumBuffers]; // Class to calculate the difference between two screen bitmaps. scoped_ptr<Differ> differ_; diff --git a/remoting/host/capturer_linux.cc b/remoting/host/capturer_linux.cc index 408eda0..f8e3fc6 100644 --- a/remoting/host/capturer_linux.cc +++ b/remoting/host/capturer_linux.cc @@ -68,8 +68,6 @@ class CapturerLinuxPimpl { Display* display_; GC gc_; Window root_window_; - int width_; - int height_; // XDamage information. Damage damage_handle_; @@ -119,8 +117,6 @@ CapturerLinuxPimpl::CapturerLinuxPimpl(CapturerLinux* capturer) display_(NULL), gc_(NULL), root_window_(BadValue), - width_(0), - height_(0), damage_handle_(BadValue), damage_event_base_(-1), damage_error_base_(-1), @@ -186,21 +182,23 @@ bool CapturerLinuxPimpl::Init() { // Set up the dimensions of the catpure framebuffer. XWindowAttributes root_attr; XGetWindowAttributes(display_, root_window_, &root_attr); - width_ = root_attr.width; - height_ = root_attr.height; - stride_ = width_ * kBytesPerPixel; - VLOG(1) << "Initialized with Geometry: " << width_ << "x" << height_; + capturer_->width_ = root_attr.width; + capturer_->height_ = root_attr.height; + stride_ = capturer_->width() * kBytesPerPixel; + VLOG(1) << "Initialized with Geometry: " << capturer_->width() + << "x" << capturer_->height(); // Allocate the screen buffers. for (int i = 0; i < CapturerLinux::kNumBuffers; i++) { - buffers_[i] = new uint8[width_ * height_ * kBytesPerPixel]; + buffers_[i] = + new uint8[capturer_->width() * capturer_->height() * kBytesPerPixel]; } return true; } void CapturerLinuxPimpl::CalculateInvalidRects() { - if (capturer_->IsCaptureFullScreen(width_, height_)) + if (capturer_->IsCaptureFullScreen()) capture_fullscreen_ = true; // TODO(ajwong): The capture_fullscreen_ logic here is very ugly. Refactor. @@ -245,7 +243,8 @@ void CapturerLinuxPimpl::CaptureRects( planes.strides[0] = stride_; scoped_refptr<CaptureData> capture_data( - new CaptureData(planes, width_, height_, media::VideoFrame::RGB32)); + new CaptureData(planes, capturer_->width(), capturer_->height(), + media::VideoFrame::RGB32)); // Synchronize the current buffer with the last one since we do not capture // the entire desktop. Note that encoder may be reading from the previous @@ -260,7 +259,7 @@ void CapturerLinuxPimpl::CaptureRects( for (int i = 0; i < it->height(); ++i) { memcpy(buffer + offset, last_buffer_ + offset, it->width() * kBytesPerPixel); - offset += width_ * kBytesPerPixel; + offset += capturer_->width() * kBytesPerPixel; } } @@ -344,7 +343,7 @@ void CapturerLinuxPimpl::SlowBlit(XImage* image, int dest_x, int dest_y, unsigned int max_green = image->green_mask >> green_shift; // Produce an upside-down image. - uint8* dst_pos = dst_buffer + dst_stride * (height_ - dest_y - 1); + uint8* dst_pos = dst_buffer + dst_stride * (capturer_->height() - dest_y - 1); dst_pos += dest_x * kBytesPerPixel; // TODO(jamiewalch): Optimize, perhaps using MMX code or by converting to // YUV directly diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc index 614386f..dd94649 100644 --- a/remoting/host/capturer_mac.cc +++ b/remoting/host/capturer_mac.cc @@ -12,10 +12,7 @@ namespace remoting { CapturerMac::CapturerMac(MessageLoop* message_loop) : Capturer(message_loop), - cgl_context_(NULL), - width_(0), - height_(0), - bytes_per_row_(0) { + cgl_context_(NULL) { // TODO(dmaclach): move this initialization out into session_manager, // or at least have session_manager call into here to initialize it. CGError err = @@ -54,7 +51,7 @@ void CapturerMac::ScreenConfigurationChanged() { height_ = CGDisplayPixelsHigh(mainDevice); pixel_format_ = media::VideoFrame::RGB32; bytes_per_row_ = width_ * sizeof(uint32_t); - size_t buffer_size = height_ * bytes_per_row_; + size_t buffer_size = height() * bytes_per_row_; for (int i = 0; i < kNumBuffers; ++i) { buffers_[i].reset(new uint8[buffer_size]); } @@ -96,17 +93,19 @@ void CapturerMac::CaptureRects(const InvalidRects& rects, glPixelStorei(GL_PACK_SKIP_PIXELS, 0); // Read a block of pixels from the frame buffer. + int h = height(); + int w = width(); uint8* flip_buffer = flip_buffer_.get(); uint8* current_buffer = buffers_[current_buffer_].get(); - glReadPixels(0, 0, width_, height_, GL_BGRA, GL_UNSIGNED_BYTE, flip_buffer); + + glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, flip_buffer); glPopClientAttrib(); // OpenGL reads with a vertical flip, and sadly there is no optimized // way to get it flipped automatically. - for (int y = 0; y < height_; ++y) { + for (int y = 0; y < h; ++y) { uint8* flip_row = &(flip_buffer[y * bytes_per_row_]); - uint8* current_row = - &(current_buffer[(height_ - (y + 1)) * bytes_per_row_]); + uint8* current_row = &(current_buffer[(h - (y + 1)) * bytes_per_row_]); memcpy(current_row, flip_row, bytes_per_row_); } @@ -115,7 +114,7 @@ void CapturerMac::CaptureRects(const InvalidRects& rects, planes.strides[0] = bytes_per_row_; scoped_refptr<CaptureData> data( - new CaptureData(planes, width_, height_, pixel_format())); + new CaptureData(planes, w, h, pixel_format())); data->mutable_dirty_rects() = rects; FinishCapture(data, callback); } @@ -124,7 +123,7 @@ void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { InvalidRects rects; for (CGRectCount i = 0; i < count; ++i) { CGRect rect = rect_array[i]; - rect.origin.y = height_ - rect.size.height; + rect.origin.y = height() - rect.size.height; rects.insert(gfx::Rect(rect)); } InvalidateRects(rects); @@ -136,7 +135,7 @@ void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, InvalidRects rects; for (CGRectCount i = 0; i < count; ++i) { CGRect rect = rect_array[i]; - rect.origin.y = height_ - rect.size.height; + rect.origin.y = height() - rect.size.height; rects.insert(gfx::Rect(rect)); rect = CGRectOffset(rect, delta.dX, delta.dY); rects.insert(gfx::Rect(rect)); diff --git a/remoting/host/capturer_mac.h b/remoting/host/capturer_mac.h index 7ea8d99..eaedb47 100644 --- a/remoting/host/capturer_mac.h +++ b/remoting/host/capturer_mac.h @@ -44,13 +44,6 @@ class CapturerMac : public Capturer { CGLContextObj cgl_context_; scoped_array<uint8> buffers_[kNumBuffers]; scoped_array<uint8> flip_buffer_; - - // Screen size. - int width_; - int height_; - - int bytes_per_row_; - DISALLOW_COPY_AND_ASSIGN(CapturerMac); }; diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 5b2a21d..9522b5c 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -299,10 +299,9 @@ void ChromotingHost::OnNewClientSession( return; } - // TODO(simonmorris): The resolution is set in the video stream now, - // so it doesn't need to be set here. *protocol_config_->mutable_initial_resolution() = - protocol::ScreenResolution(2048, 2048); + protocol::ScreenResolution(desktop_environment_->capturer()->width(), + desktop_environment_->capturer()->height()); // TODO(sergeyu): Respect resolution requested by the client if supported. protocol::SessionConfig* config = protocol_config_->Select( session->candidate_config(), true /* force_host_resolution */); diff --git a/remoting/host/differ.h b/remoting/host/differ.h index a5af54f..8386e7a 100644 --- a/remoting/host/differ.h +++ b/remoting/host/differ.h @@ -27,11 +27,6 @@ class Differ { Differ(int width, int height, int bytes_per_pixel, int stride); ~Differ(); - int width() { return width_; } - int height() { return height_; } - int bytes_per_pixel() { return bytes_per_pixel_; } - int bytes_per_row() { return bytes_per_row_; } - // Given the previous and current screen buffer, calculate the set of // rectangles that enclose all the changed pixels in the new screen. void CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index 95da76b..e9229b2 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -97,14 +97,10 @@ void EventExecutorWin::HandleMouse(const MouseEvent* event) { INPUT input; input.type = INPUT_MOUSE; input.mi.time = 0; - int screen_width = capturer_->width_most_recent(); - int screen_height = capturer_->height_most_recent(); - if ((screen_width > 0) && (screen_height > 0)) { - input.mi.dx = static_cast<int>((x * 65535) / screen_width); - input.mi.dy = static_cast<int>((y * 65535) / screen_height); - input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; - SendInput(1, &input, sizeof(INPUT)); - } + input.mi.dx = static_cast<int>((x * 65535) / capturer_->width()); + input.mi.dy = static_cast<int>((y * 65535) / capturer_->height()); + input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; + SendInput(1, &input, sizeof(INPUT)); } if (event->has_wheel_offset_x() && event->has_wheel_offset_y()) { |