Chromium Code Reviews| 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 <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <OpenGL/CGLMacro.h> | 8 #include <OpenGL/CGLMacro.h> |
| 9 #include <OpenGL/OpenGL.h> | 9 #include <OpenGL/OpenGL.h> |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer); | 121 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer); |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 // A class to perform capturing for mac. | 124 // A class to perform capturing for mac. |
| 125 class CapturerMac : public Capturer { | 125 class CapturerMac : public Capturer { |
| 126 public: | 126 public: |
| 127 CapturerMac(); | 127 CapturerMac(); |
| 128 virtual ~CapturerMac(); | 128 virtual ~CapturerMac(); |
| 129 | 129 |
| 130 // Enable or disable capturing. Capturing should be disabled while a screen | |
| 131 // reconfiguration is in progress, otherwise reading from the screen base | |
| 132 // address is likely to segfault. | |
| 133 void EnableCapture(bool enable); | |
| 134 | |
| 135 // Capturer interface. | 130 // Capturer interface. |
| 136 virtual void ScreenConfigurationChanged() OVERRIDE; | 131 virtual void ScreenConfigurationChanged() OVERRIDE; |
| 137 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 132 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
| 138 virtual void ClearInvalidRegion() OVERRIDE; | 133 virtual void ClearInvalidRegion() OVERRIDE; |
| 139 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 134 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
| 140 virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; | 135 virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; |
| 141 virtual void InvalidateFullScreen() OVERRIDE; | 136 virtual void InvalidateFullScreen() OVERRIDE; |
| 142 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) | 137 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) |
| 143 OVERRIDE; | 138 OVERRIDE; |
| 144 virtual const gfx::Size& size_most_recent() const OVERRIDE; | 139 virtual const gfx::Size& size_most_recent() const OVERRIDE; |
| 145 | 140 |
| 146 private: | 141 private: |
| 147 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); | 142 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 148 void GlBlitSlow(const VideoFrameBuffer& buffer); | 143 void GlBlitSlow(const VideoFrameBuffer& buffer); |
| 149 void CgBlit(const VideoFrameBuffer& buffer, const SkRegion& region); | 144 void CgBlit(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 150 void CaptureRegion(const SkRegion& region, | 145 void CaptureRegion(const SkRegion& region, |
| 151 CaptureCompletedCallback* callback); | 146 CaptureCompletedCallback* callback); |
| 152 | 147 |
| 153 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); | 148 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); |
| 154 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 149 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
| 155 size_t count, | 150 size_t count, |
| 156 const CGRect *rect_array); | 151 const CGRect *rect_array); |
| 152 void DisplaysReconfigured(CGDirectDisplayID display, | |
| 153 CGDisplayChangeSummaryFlags flags); | |
| 157 static void ScreenRefreshCallback(CGRectCount count, | 154 static void ScreenRefreshCallback(CGRectCount count, |
| 158 const CGRect *rect_array, | 155 const CGRect *rect_array, |
| 159 void *user_parameter); | 156 void *user_parameter); |
| 160 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 157 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
| 161 size_t count, | 158 size_t count, |
| 162 const CGRect *rect_array, | 159 const CGRect *rect_array, |
| 163 void *user_parameter); | 160 void *user_parameter); |
| 164 static void DisplaysReconfiguredCallback(CGDirectDisplayID display, | 161 static void DisplaysReconfiguredCallback(CGDirectDisplayID display, |
| 165 CGDisplayChangeSummaryFlags flags, | 162 CGDisplayChangeSummaryFlags flags, |
| 166 void *user_parameter); | 163 void *user_parameter); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 181 // The previous buffer into which we captured, or NULL for the first capture | 178 // The previous buffer into which we captured, or NULL for the first capture |
| 182 // for a particular screen resolution. | 179 // for a particular screen resolution. |
| 183 uint8* last_buffer_; | 180 uint8* last_buffer_; |
| 184 | 181 |
| 185 // Contains an invalid region from the previous capture. | 182 // Contains an invalid region from the previous capture. |
| 186 SkRegion last_invalid_region_; | 183 SkRegion last_invalid_region_; |
| 187 | 184 |
| 188 // Format of pixels returned in buffer. | 185 // Format of pixels returned in buffer. |
| 189 media::VideoFrame::Format pixel_format_; | 186 media::VideoFrame::Format pixel_format_; |
| 190 | 187 |
| 191 bool capturing_; | 188 // Lock controlling who currently owns our local display_configuration |
| 189 // information. Usually owned by the capture_thread or the main_thread. | |
|
Jamie
2011/08/15 21:29:27
Usually? If this is worth documenting, I think it
dmac
2011/08/16 19:18:55
Done.
| |
| 190 base::Lock display_configuration_capture_lock_; | |
| 192 | 191 |
| 193 DISALLOW_COPY_AND_ASSIGN(CapturerMac); | 192 DISALLOW_COPY_AND_ASSIGN(CapturerMac); |
| 194 }; | 193 }; |
| 195 | 194 |
| 196 CapturerMac::CapturerMac() | 195 CapturerMac::CapturerMac() |
| 197 : cgl_context_(NULL), | 196 : cgl_context_(NULL), |
| 198 current_buffer_(0), | 197 current_buffer_(0), |
| 199 last_buffer_(NULL), | 198 last_buffer_(NULL), |
| 200 pixel_format_(media::VideoFrame::RGB32), | 199 pixel_format_(media::VideoFrame::RGB32) { |
| 201 capturing_(true) { | |
| 202 // TODO(dmaclach): move this initialization out into session_manager, | 200 // TODO(dmaclach): move this initialization out into session_manager, |
| 203 // or at least have session_manager call into here to initialize it. | 201 // or at least have session_manager call into here to initialize it. |
| 204 CGError err = | 202 CGError err = |
| 205 CGRegisterScreenRefreshCallback(CapturerMac::ScreenRefreshCallback, | 203 CGRegisterScreenRefreshCallback(CapturerMac::ScreenRefreshCallback, |
| 206 this); | 204 this); |
| 207 DCHECK_EQ(err, kCGErrorSuccess); | 205 DCHECK_EQ(err, kCGErrorSuccess); |
| 208 err = CGScreenRegisterMoveCallback(CapturerMac::ScreenUpdateMoveCallback, | 206 err = CGScreenRegisterMoveCallback(CapturerMac::ScreenUpdateMoveCallback, |
| 209 this); | 207 this); |
| 210 DCHECK_EQ(err, kCGErrorSuccess); | 208 DCHECK_EQ(err, kCGErrorSuccess); |
| 211 err = CGDisplayRegisterReconfigurationCallback( | 209 err = CGDisplayRegisterReconfigurationCallback( |
| 212 CapturerMac::DisplaysReconfiguredCallback, this); | 210 CapturerMac::DisplaysReconfiguredCallback, this); |
| 213 DCHECK_EQ(err, kCGErrorSuccess); | 211 DCHECK_EQ(err, kCGErrorSuccess); |
| 214 ScreenConfigurationChanged(); | 212 ScreenConfigurationChanged(); |
| 215 } | 213 } |
| 216 | 214 |
| 217 CapturerMac::~CapturerMac() { | 215 CapturerMac::~CapturerMac() { |
| 218 ReleaseBuffers(); | 216 ReleaseBuffers(); |
| 219 CGUnregisterScreenRefreshCallback(CapturerMac::ScreenRefreshCallback, this); | 217 CGUnregisterScreenRefreshCallback(CapturerMac::ScreenRefreshCallback, this); |
| 220 CGScreenUnregisterMoveCallback(CapturerMac::ScreenUpdateMoveCallback, this); | 218 CGScreenUnregisterMoveCallback(CapturerMac::ScreenUpdateMoveCallback, this); |
| 221 CGDisplayRemoveReconfigurationCallback( | 219 CGDisplayRemoveReconfigurationCallback( |
| 222 CapturerMac::DisplaysReconfiguredCallback, this); | 220 CapturerMac::DisplaysReconfiguredCallback, this); |
| 223 } | 221 } |
| 224 | 222 |
| 225 void CapturerMac::EnableCapture(bool enable) { | |
| 226 capturing_ = enable; | |
| 227 } | |
| 228 | |
| 229 void CapturerMac::ReleaseBuffers() { | 223 void CapturerMac::ReleaseBuffers() { |
| 230 if (cgl_context_) { | 224 if (cgl_context_) { |
| 231 pixel_buffer_object_.Release(); | 225 pixel_buffer_object_.Release(); |
| 232 CGLDestroyContext(cgl_context_); | 226 CGLDestroyContext(cgl_context_); |
| 233 cgl_context_ = NULL; | 227 cgl_context_ = NULL; |
| 234 } | 228 } |
| 235 // The buffers might be in use by the encoder, so don't delete them here. | 229 // The buffers might be in use by the encoder, so don't delete them here. |
| 236 // Instead, mark them as "needs update"; next time the buffers are used by | 230 // Instead, mark them as "needs update"; next time the buffers are used by |
| 237 // the capturer, they will be recreated if necessary. | 231 // the capturer, they will be recreated if necessary. |
| 238 for (int i = 0; i < kNumBuffers; ++i) { | 232 for (int i = 0; i < kNumBuffers; ++i) { |
| 239 buffers_[i].set_needs_update(); | 233 buffers_[i].set_needs_update(); |
| 240 } | 234 } |
| 235 last_buffer_ = NULL; | |
|
Jamie
2011/08/15 21:29:27
Why move this?
dmac
2011/08/16 19:18:55
Done.
| |
| 241 } | 236 } |
| 242 | 237 |
| 243 void CapturerMac::ScreenConfigurationChanged() { | 238 void CapturerMac::ScreenConfigurationChanged() { |
| 244 ReleaseBuffers(); | 239 ReleaseBuffers(); |
| 245 helper_.ClearInvalidRegion(); | 240 helper_.ClearInvalidRegion(); |
| 246 last_buffer_ = NULL; | |
| 247 | 241 |
| 248 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 242 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
| 249 int width = CGDisplayPixelsWide(mainDevice); | 243 int width = CGDisplayPixelsWide(mainDevice); |
| 250 int height = CGDisplayPixelsHigh(mainDevice); | 244 int height = CGDisplayPixelsHigh(mainDevice); |
| 251 InvalidateScreen(gfx::Size(width, height)); | 245 InvalidateScreen(gfx::Size(width, height)); |
| 252 | 246 |
| 253 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { | 247 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { |
| 254 VLOG(3) << "OpenGL support not available."; | 248 VLOG(3) << "OpenGL support not available."; |
| 255 return; | 249 return; |
| 256 } | 250 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 285 |
| 292 void CapturerMac::InvalidateScreen(const gfx::Size& size) { | 286 void CapturerMac::InvalidateScreen(const gfx::Size& size) { |
| 293 helper_.InvalidateScreen(size); | 287 helper_.InvalidateScreen(size); |
| 294 } | 288 } |
| 295 | 289 |
| 296 void CapturerMac::InvalidateFullScreen() { | 290 void CapturerMac::InvalidateFullScreen() { |
| 297 helper_.InvalidateFullScreen(); | 291 helper_.InvalidateFullScreen(); |
| 298 } | 292 } |
| 299 | 293 |
| 300 void CapturerMac::CaptureInvalidRegion(CaptureCompletedCallback* callback) { | 294 void CapturerMac::CaptureInvalidRegion(CaptureCompletedCallback* callback) { |
| 295 // Only allow captures when the display configuration is not occurring. | |
| 296 base::AutoLock locker(display_configuration_capture_lock_); | |
| 301 scoped_refptr<CaptureData> data; | 297 scoped_refptr<CaptureData> data; |
| 302 if (capturing_) { | 298 SkRegion region; |
| 303 SkRegion region; | 299 helper_.SwapInvalidRegion(®ion); |
| 304 helper_.SwapInvalidRegion(®ion); | 300 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; |
| 305 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; | 301 current_buffer.Update(); |
| 306 current_buffer.Update(); | |
| 307 | 302 |
| 308 bool flip = true; // GL capturers need flipping. | 303 bool flip = true; // GL capturers need flipping. |
| 309 if (cgl_context_) { | 304 if (cgl_context_) { |
| 310 if (pixel_buffer_object_.get() != 0) { | 305 if (pixel_buffer_object_.get() != 0) { |
| 311 GlBlitFast(current_buffer, region); | 306 GlBlitFast(current_buffer, region); |
| 312 } else { | |
| 313 // See comment in scoped_pixel_buffer_object::Init about why the slow | |
| 314 // path is always used on 10.5. | |
| 315 GlBlitSlow(current_buffer); | |
| 316 } | |
| 317 } else { | 307 } else { |
| 318 CgBlit(current_buffer, region); | 308 // See comment in scoped_pixel_buffer_object::Init about why the slow |
| 319 flip = false; | 309 // path is always used on 10.5. |
| 310 GlBlitSlow(current_buffer); | |
| 320 } | 311 } |
| 312 } else { | |
| 313 CgBlit(current_buffer, region); | |
| 314 flip = false; | |
| 315 } | |
| 321 | 316 |
| 322 DataPlanes planes; | 317 DataPlanes planes; |
| 323 planes.data[0] = current_buffer.ptr(); | 318 planes.data[0] = current_buffer.ptr(); |
| 324 planes.strides[0] = current_buffer.bytes_per_row(); | 319 planes.strides[0] = current_buffer.bytes_per_row(); |
| 325 if (flip) { | 320 if (flip) { |
| 326 planes.strides[0] = -planes.strides[0]; | 321 planes.strides[0] = -planes.strides[0]; |
| 327 planes.data[0] += | 322 planes.data[0] += |
| 328 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); | 323 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); |
| 329 } | 324 } |
| 330 | 325 |
| 331 data = new CaptureData(planes, gfx::Size(current_buffer.size()), | 326 data = new CaptureData(planes, gfx::Size(current_buffer.size()), |
| 332 pixel_format()); | 327 pixel_format()); |
| 333 data->mutable_dirty_region() = region; | 328 data->mutable_dirty_region() = region; |
| 334 | 329 |
| 335 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | 330 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; |
| 336 helper_.set_size_most_recent(data->size()); | 331 helper_.set_size_most_recent(data->size()); |
| 337 } | |
| 338 | 332 |
| 339 callback->Run(data); | 333 callback->Run(data); |
|
Jamie
2011/08/15 21:29:27
Is it worth scoping the lock more tightly so that
dmac
2011/08/16 19:18:55
Done.
| |
| 340 delete callback; | 334 delete callback; |
| 341 } | 335 } |
| 342 | 336 |
| 343 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, | 337 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, |
| 344 const SkRegion& region) { | 338 const SkRegion& region) { |
| 339 const int buffer_height = buffer.size().height(); | |
| 340 const int buffer_width = buffer.size().width(); | |
| 341 | |
| 342 // Clip to the size of our current screen. | |
| 343 SkIRect clip_rect = SkIRect::MakeWH(buffer_width, buffer_height); | |
|
Jamie
2011/08/15 21:29:27
Is clipping required for any of the other Blit fun
dmac
2011/08/16 19:18:55
Done.
| |
| 345 if (last_buffer_) { | 344 if (last_buffer_) { |
| 346 // We are doing double buffer for the capture data so we just need to copy | 345 // We are doing double buffer for the capture data so we just need to copy |
| 347 // the invalid region from the previous capture in the current buffer. | 346 // the invalid region from the previous capture in the current buffer. |
| 348 // TODO(hclam): We can reduce the amount of copying here by subtracting | 347 // TODO(hclam): We can reduce the amount of copying here by subtracting |
| 349 // |capturer_helper_|s region from |last_invalid_region_|. | 348 // |capturer_helper_|s region from |last_invalid_region_|. |
| 350 // http://crbug.com/92354 | 349 // http://crbug.com/92354 |
| 351 | 350 |
| 352 // Since the image obtained from OpenGL is upside-down, need to do some | 351 // Since the image obtained from OpenGL is upside-down, need to do some |
| 353 // magic here to copy the correct rectangle. | 352 // magic here to copy the correct rectangle. |
| 354 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); | 353 const int y_offset = (buffer_height - 1) * buffer.bytes_per_row(); |
| 355 for(SkRegion::Iterator i(last_invalid_region_); !i.done(); i.next()) { | 354 for(SkRegion::Iterator i(last_invalid_region_); !i.done(); i.next()) { |
| 355 SkIRect copy_rect = i.rect(); | |
| 356 copy_rect.intersect(clip_rect); | |
| 356 CopyRect(last_buffer_ + y_offset, | 357 CopyRect(last_buffer_ + y_offset, |
| 357 -buffer.bytes_per_row(), | 358 -buffer.bytes_per_row(), |
| 358 buffer.ptr() + y_offset, | 359 buffer.ptr() + y_offset, |
| 359 -buffer.bytes_per_row(), | 360 -buffer.bytes_per_row(), |
| 360 4, // Bytes for pixel for RGBA. | 361 4, // Bytes for pixel for RGBA. |
| 361 i.rect()); | 362 copy_rect); |
| 362 } | 363 } |
| 363 } | 364 } |
| 364 last_buffer_ = buffer.ptr(); | 365 last_buffer_ = buffer.ptr(); |
| 365 last_invalid_region_ = region; | 366 last_invalid_region_ = region; |
| 366 | 367 |
| 367 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 368 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
| 368 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); | 369 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); |
| 369 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), | 370 glReadPixels(0, 0, buffer_width, buffer_height, GL_BGRA, GL_UNSIGNED_BYTE, 0); |
| 370 GL_BGRA, GL_UNSIGNED_BYTE, 0); | |
| 371 GLubyte* ptr = static_cast<GLubyte*>( | 371 GLubyte* ptr = static_cast<GLubyte*>( |
| 372 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); | 372 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); |
| 373 if (ptr == NULL) { | 373 if (ptr == NULL) { |
| 374 // If the buffer can't be mapped, assume that it's no longer valid and | 374 // If the buffer can't be mapped, assume that it's no longer valid and |
| 375 // release it. | 375 // release it. |
| 376 pixel_buffer_object_.Release(); | 376 pixel_buffer_object_.Release(); |
| 377 } else { | 377 } else { |
| 378 // Copy only from the dirty rects. Since the image obtained from OpenGL is | 378 // Copy only from the dirty rects. Since the image obtained from OpenGL is |
| 379 // upside-down we need to do some magic here to copy the correct rectangle. | 379 // upside-down we need to do some magic here to copy the correct rectangle. |
| 380 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); | 380 const int y_offset = (buffer_height - 1) * buffer.bytes_per_row(); |
| 381 for(SkRegion::Iterator i(region); !i.done(); i.next()) { | 381 for(SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 382 SkIRect copy_rect = i.rect(); | |
| 383 copy_rect.intersect(clip_rect); | |
| 382 CopyRect(ptr + y_offset, | 384 CopyRect(ptr + y_offset, |
| 383 -buffer.bytes_per_row(), | 385 -buffer.bytes_per_row(), |
| 384 buffer.ptr() + y_offset, | 386 buffer.ptr() + y_offset, |
| 385 -buffer.bytes_per_row(), | 387 -buffer.bytes_per_row(), |
| 386 4, // Bytes for pixel for RGBA. | 388 4, // Bytes for pixel for RGBA. |
| 387 i.rect()); | 389 copy_rect); |
| 388 } | 390 } |
| 389 } | 391 } |
| 390 if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) { | 392 if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) { |
| 391 // If glUnmapBuffer returns false, then the contents of the data store are | 393 // If glUnmapBuffer returns false, then the contents of the data store are |
| 392 // undefined. This might be because the screen mode has changed, in which | 394 // undefined. This might be because the screen mode has changed, in which |
| 393 // case it will be recreated in ScreenConfigurationChanged, but releasing | 395 // case it will be recreated in ScreenConfigurationChanged, but releasing |
| 394 // the object here is the best option. Capturing will fall back on | 396 // the object here is the best option. Capturing will fall back on |
| 395 // GlBlitSlow until such time as the pixel buffer object is recreated. | 397 // GlBlitSlow until such time as the pixel buffer object is recreated. |
| 396 pixel_buffer_object_.Release(); | 398 pixel_buffer_object_.Release(); |
| 397 } | 399 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 for (CGRectCount i = 0; i < count; ++i) { | 459 for (CGRectCount i = 0; i < count; ++i) { |
| 458 CGRect rect = rect_array[i]; | 460 CGRect rect = rect_array[i]; |
| 459 rect = CGRectOffset(rect, delta.dX, delta.dY); | 461 rect = CGRectOffset(rect, delta.dX, delta.dY); |
| 460 skirect_new_array[i] = gfx::CGRectToSkIRect(rect); | 462 skirect_new_array[i] = gfx::CGRectToSkIRect(rect); |
| 461 } | 463 } |
| 462 SkRegion region; | 464 SkRegion region; |
| 463 region.setRects(skirect_new_array, count); | 465 region.setRects(skirect_new_array, count); |
| 464 InvalidateRegion(region); | 466 InvalidateRegion(region); |
| 465 } | 467 } |
| 466 | 468 |
| 469 void CapturerMac::DisplaysReconfigured(CGDirectDisplayID display, | |
| 470 CGDisplayChangeSummaryFlags flags) { | |
| 471 if (display == CGMainDisplayID()) { | |
| 472 if (flags & kCGDisplayBeginConfigurationFlag) { | |
| 473 // Acquire the display_configuration_capture_lock to prevent more | |
| 474 // captures from occurring on a different thread while the displays | |
| 475 // are being reconfigured. | |
| 476 display_configuration_capture_lock_.Acquire(); | |
|
Jamie
2011/08/15 21:29:27
Does OS X impose a timeout on these callbacks? I'm
dmac
2011/08/16 19:18:55
Done.
| |
| 477 } else { | |
| 478 ScreenConfigurationChanged(); | |
| 479 // Now that the configuration has changed, release the lock. | |
| 480 display_configuration_capture_lock_.Release(); | |
| 481 } | |
| 482 } | |
| 483 } | |
| 484 | |
| 467 void CapturerMac::ScreenRefreshCallback(CGRectCount count, | 485 void CapturerMac::ScreenRefreshCallback(CGRectCount count, |
| 468 const CGRect *rect_array, | 486 const CGRect *rect_array, |
| 469 void *user_parameter) { | 487 void *user_parameter) { |
| 470 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 488 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
| 471 capturer->ScreenRefresh(count, rect_array); | 489 capturer->ScreenRefresh(count, rect_array); |
| 472 } | 490 } |
| 473 | 491 |
| 474 void CapturerMac::ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 492 void CapturerMac::ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
| 475 size_t count, | 493 size_t count, |
| 476 const CGRect *rect_array, | 494 const CGRect *rect_array, |
| 477 void *user_parameter) { | 495 void *user_parameter) { |
| 478 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 496 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
| 479 capturer->ScreenUpdateMove(delta, count, rect_array); | 497 capturer->ScreenUpdateMove(delta, count, rect_array); |
| 480 } | 498 } |
| 481 | 499 |
| 482 void CapturerMac::DisplaysReconfiguredCallback( | 500 void CapturerMac::DisplaysReconfiguredCallback( |
| 483 CGDirectDisplayID display, | 501 CGDirectDisplayID display, |
| 484 CGDisplayChangeSummaryFlags flags, | 502 CGDisplayChangeSummaryFlags flags, |
| 485 void *user_parameter) { | 503 void *user_parameter) { |
| 486 if (display == CGMainDisplayID()) { | 504 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
| 487 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 505 capturer->DisplaysReconfigured(display, flags); |
| 488 if (flags & kCGDisplayBeginConfigurationFlag) { | |
| 489 capturer->EnableCapture(false); | |
| 490 } else { | |
| 491 capturer->EnableCapture(true); | |
| 492 capturer->ScreenConfigurationChanged(); | |
| 493 } | |
| 494 } | |
| 495 } | 506 } |
| 496 | 507 |
| 497 } // namespace | 508 } // namespace |
| 498 | 509 |
| 499 // static | 510 // static |
| 500 Capturer* Capturer::Create() { | 511 Capturer* Capturer::Create() { |
| 501 return new CapturerMac(); | 512 return new CapturerMac(); |
| 502 } | 513 } |
| 503 | 514 |
| 504 } // namespace remoting | 515 } // namespace remoting |
| OLD | NEW |