summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 04:24:37 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 04:24:37 +0000
commit408292f44ad2b7087fae088ec10b1ad92470b4bd (patch)
treef16d1dc9f965c481039c0580e56aabfcff6a73cd /remoting
parent695041b3034cdf4535481488883a584f33b7e14b (diff)
downloadchromium_src-408292f44ad2b7087fae088ec10b1ad92470b4bd.zip
chromium_src-408292f44ad2b7087fae088ec10b1ad92470b4bd.tar.gz
chromium_src-408292f44ad2b7087fae088ec10b1ad92470b4bd.tar.bz2
Fix up mac capturer to flip image.
BUG=74078 TEST=Connect to a mac host. Image should come right side up. Review URL: http://codereview.chromium.org/6610007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/capturer_mac.cc23
-rw-r--r--remoting/host/capturer_mac.h1
2 files changed, 18 insertions, 6 deletions
diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc
index e5b4c8a..dd94649 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,28 @@ 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.
+ for (int y = 0; y < h; ++y) {
+ uint8* flip_row = &(flip_buffer[y * bytes_per_row_]);
+ uint8* current_row = &(current_buffer[(h - (y + 1)) * bytes_per_row_]);
+ memcpy(current_row, flip_row, bytes_per_row_);
+ }
+
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);
}
diff --git a/remoting/host/capturer_mac.h b/remoting/host/capturer_mac.h
index 96ea159..eaedb47 100644
--- a/remoting/host/capturer_mac.h
+++ b/remoting/host/capturer_mac.h
@@ -43,6 +43,7 @@ class CapturerMac : public Capturer {
void ReleaseBuffers();
CGLContextObj cgl_context_;
scoped_array<uint8> buffers_[kNumBuffers];
+ scoped_array<uint8> flip_buffer_;
DISALLOW_COPY_AND_ASSIGN(CapturerMac);
};