Chromium Code Reviews| Index: remoting/host/capturer_mac.cc |
| diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc |
| index e5b4c8a829bb4349747c718c40658d3dc2de0434..9b06ac6707aa68c777183c84c4047decffb95c6b 100644 |
| --- a/remoting/host/capturer_mac.cc |
| +++ b/remoting/host/capturer_mac.cc |
| @@ -55,6 +55,7 @@ void CapturerMac::ScreenConfigurationChanged() { |
| for (int i = 0; i < kNumBuffers; ++i) { |
| buffers_[i].reset(new uint8[buffer_size]); |
| } |
| + flip_buffer_.reset(new uint8[buffer_size]); |
| CGLPixelFormatAttribute attributes[] = { |
| kCGLPFAFullScreen, |
| kCGLPFADisplayMask, |
| @@ -92,18 +93,33 @@ void CapturerMac::CaptureRects(const InvalidRects& rects, |
| glPixelStorei(GL_PACK_SKIP_PIXELS, 0); |
| // Read a block of pixels from the frame buffer. |
| - glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, |
| - buffers_[current_buffer_].get()); |
| + int h = height(); |
| + int w = width(); |
| + uint8* flip_buffer = flip_buffer_.get(); |
| + uint8* current_buffer = buffers_[current_buffer_].get(); |
| + |
| + 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. |
| + DCHECK_EQ(bytes_per_row_ % sizeof(uint32_t), 0U); |
| + for (int y = 0; y < h; ++y) { |
| + uint32_t* flip_row = reinterpret_cast<uint32_t*>( |
| + &(flip_buffer[y * bytes_per_row_])); |
| + uint32_t* current_row = reinterpret_cast<uint32_t*>( |
| + &(current_buffer[(h - (y + 1)) * bytes_per_row_])); |
| + for (int x = 0; x < w; ++x) { |
|
Alpha Left Google
2011/03/03 01:43:33
Do a memcpy instead of doing yourself, memcpy is p
|
| + current_row[x] = flip_row[x]; |
| + } |
| + } |
| + |
| DataPlanes planes; |
| planes.data[0] = buffers_[current_buffer_].get(); |
| planes.strides[0] = bytes_per_row_; |
| - scoped_refptr<CaptureData> data(new CaptureData(planes, |
| - width(), |
| - height(), |
| - pixel_format())); |
| + scoped_refptr<CaptureData> data( |
| + new CaptureData(planes, w, h, pixel_format())); |
| data->mutable_dirty_rects() = rects; |
| FinishCapture(data, callback); |
| } |