OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_mac.h" | 5 #include "remoting/host/capturer_mac.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <OpenGL/CGLMacro.h> | 9 #include <OpenGL/CGLMacro.h> |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 &pixel_format, | 64 &pixel_format, |
65 &matching_pixel_format_count); | 65 &matching_pixel_format_count); |
66 DCHECK_EQ(err, kCGLNoError); | 66 DCHECK_EQ(err, kCGLNoError); |
67 err = CGLCreateContext(pixel_format, NULL, &cgl_context_); | 67 err = CGLCreateContext(pixel_format, NULL, &cgl_context_); |
68 DCHECK_EQ(err, kCGLNoError); | 68 DCHECK_EQ(err, kCGLNoError); |
69 CGLDestroyPixelFormat(pixel_format); | 69 CGLDestroyPixelFormat(pixel_format); |
70 CGLSetFullScreen(cgl_context_); | 70 CGLSetFullScreen(cgl_context_); |
71 CGLSetCurrentContext(cgl_context_); | 71 CGLSetCurrentContext(cgl_context_); |
72 } | 72 } |
73 | 73 |
74 void CapturerMac::CaptureRects(const RectVector& rects, | 74 void CapturerMac::CalculateInvalidRects() { |
| 75 // Since the Mac gets its list of invalid rects via calls to InvalidateRect(), |
| 76 // this step only needs to perform post-processing optimizations on the rect |
| 77 // list (if needed). |
| 78 } |
| 79 |
| 80 void CapturerMac::CaptureRects(const InvalidRects& rects, |
75 CaptureCompletedCallback* callback) { | 81 CaptureCompletedCallback* callback) { |
76 // TODO(dmaclach): something smarter here in the future. | 82 // TODO(dmaclach): something smarter here in the future. |
77 gfx::Rect dirtyRect; | 83 gfx::Rect dirtyRect; |
78 for (RectVector::const_iterator i = rects.begin(); i < rects.end(); ++i) { | 84 for (InvalidRects::const_iterator i = rects.begin(); i != rects.end(); ++i) { |
79 dirtyRect = dirtyRect.Union(*i); | 85 dirtyRect = dirtyRect.Union(*i); |
80 } | 86 } |
81 | 87 |
82 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 88 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
83 glReadBuffer(GL_FRONT); | 89 glReadBuffer(GL_FRONT); |
84 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); | 90 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); |
85 | 91 |
86 glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment. | 92 glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment. |
87 glPixelStorei(GL_PACK_ROW_LENGTH, 0); | 93 glPixelStorei(GL_PACK_ROW_LENGTH, 0); |
88 glPixelStorei(GL_PACK_SKIP_ROWS, 0); | 94 glPixelStorei(GL_PACK_SKIP_ROWS, 0); |
89 glPixelStorei(GL_PACK_SKIP_PIXELS, 0); | 95 glPixelStorei(GL_PACK_SKIP_PIXELS, 0); |
90 | 96 |
91 // Read a block of pixels from the frame buffer. | 97 // Read a block of pixels from the frame buffer. |
92 glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, | 98 glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, |
93 buffers_[current_buffer_].get()); | 99 buffers_[current_buffer_].get()); |
94 glPopClientAttrib(); | 100 glPopClientAttrib(); |
95 | 101 |
96 DataPlanes planes; | 102 DataPlanes planes; |
97 planes.data[0] = buffers_[current_buffer_].get(); | 103 planes.data[0] = buffers_[current_buffer_].get(); |
98 planes.strides[0] = bytes_per_row_; | 104 planes.strides[0] = bytes_per_row_; |
99 | 105 |
100 scoped_refptr<CaptureData> data(new CaptureData(planes, | 106 scoped_refptr<CaptureData> data(new CaptureData(planes, |
101 width(), | 107 width(), |
102 height(), | 108 height(), |
103 pixel_format())); | 109 pixel_format())); |
104 data->mutable_dirty_rects().assign(1, dirtyRect); | 110 data->mutable_dirty_rects().clear(); |
| 111 data->mutable_dirty_rects().insert(dirtyRect); |
105 FinishCapture(data, callback); | 112 FinishCapture(data, callback); |
106 } | 113 } |
107 | 114 |
108 | |
109 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { | 115 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { |
110 RectVector rects; | 116 InvalidRects rects; |
111 for (CGRectCount i = 0; i < count; ++i) { | 117 for (CGRectCount i = 0; i < count; ++i) { |
112 CGRect rect = rect_array[i]; | 118 CGRect rect = rect_array[i]; |
113 rect.origin.y = height() - rect.size.height; | 119 rect.origin.y = height() - rect.size.height; |
114 rects.push_back(gfx::Rect(rect)); | 120 rects.insert(gfx::Rect(rect)); |
115 } | 121 } |
116 InvalidateRects(rects); | 122 InvalidateRects(rects); |
117 | |
118 } | 123 } |
119 | 124 |
120 void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 125 void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
121 size_t count, | 126 size_t count, |
122 const CGRect *rect_array) { | 127 const CGRect *rect_array) { |
123 RectVector rects; | 128 InvalidRects rects; |
124 for (CGRectCount i = 0; i < count; ++i) { | 129 for (CGRectCount i = 0; i < count; ++i) { |
125 CGRect rect = rect_array[i]; | 130 CGRect rect = rect_array[i]; |
126 rect.origin.y = height() - rect.size.height; | 131 rect.origin.y = height() - rect.size.height; |
127 rects.push_back(gfx::Rect(rect)); | 132 rects.insert(gfx::Rect(rect)); |
128 rect = CGRectOffset(rect, delta.dX, delta.dY); | 133 rect = CGRectOffset(rect, delta.dX, delta.dY); |
129 rects.push_back(gfx::Rect(rect)); | 134 rects.insert(gfx::Rect(rect)); |
130 } | 135 } |
131 InvalidateRects(rects); | 136 InvalidateRects(rects); |
132 } | 137 } |
133 | 138 |
134 void CapturerMac::ScreenRefreshCallback(CGRectCount count, | 139 void CapturerMac::ScreenRefreshCallback(CGRectCount count, |
135 const CGRect *rect_array, | 140 const CGRect *rect_array, |
136 void *user_parameter) { | 141 void *user_parameter) { |
137 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 142 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
138 capturer->ScreenRefresh(count, rect_array); | 143 capturer->ScreenRefresh(count, rect_array); |
139 } | 144 } |
(...skipping 11 matching lines...) Expand all Loading... |
151 CGDisplayChangeSummaryFlags flags, | 156 CGDisplayChangeSummaryFlags flags, |
152 void *user_parameter) { | 157 void *user_parameter) { |
153 if ((display == CGMainDisplayID()) && | 158 if ((display == CGMainDisplayID()) && |
154 !(flags & kCGDisplayBeginConfigurationFlag)) { | 159 !(flags & kCGDisplayBeginConfigurationFlag)) { |
155 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 160 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
156 capturer->ScreenConfigurationChanged(); | 161 capturer->ScreenConfigurationChanged(); |
157 } | 162 } |
158 } | 163 } |
159 | 164 |
160 } // namespace remoting | 165 } // namespace remoting |
OLD | NEW |