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 |
| 11 #include <stddef.h> | 11 #include <stddef.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "remoting/base/util.h" | 16 #include "remoting/base/util.h" |
| 17 #include "remoting/host/capturer_helper.h" | 17 #include "remoting/host/capturer_helper.h" |
| 18 #include "skia/ext/skia_utils_mac.h" | |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class scoped_pixel_buffer_object { | 24 class scoped_pixel_buffer_object { |
| 24 public: | 25 public: |
| 25 scoped_pixel_buffer_object(); | 26 scoped_pixel_buffer_object(); |
| 26 ~scoped_pixel_buffer_object(); | 27 ~scoped_pixel_buffer_object(); |
| 27 | 28 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 virtual ~CapturerMac(); | 128 virtual ~CapturerMac(); |
| 128 | 129 |
| 129 // Enable or disable capturing. Capturing should be disabled while a screen | 130 // Enable or disable capturing. Capturing should be disabled while a screen |
| 130 // reconfiguration is in progress, otherwise reading from the screen base | 131 // reconfiguration is in progress, otherwise reading from the screen base |
| 131 // address is likely to segfault. | 132 // address is likely to segfault. |
| 132 void EnableCapture(bool enable); | 133 void EnableCapture(bool enable); |
| 133 | 134 |
| 134 // Capturer interface. | 135 // Capturer interface. |
| 135 virtual void ScreenConfigurationChanged() OVERRIDE; | 136 virtual void ScreenConfigurationChanged() OVERRIDE; |
| 136 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 137 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
| 137 virtual void ClearInvalidRects() OVERRIDE; | 138 virtual void ClearInvalidRegion() OVERRIDE; |
| 138 virtual void InvalidateRects(const InvalidRects& inval_rects) OVERRIDE; | 139 virtual void InvalidateRegion(const SkRegion& inval_region) OVERRIDE; |
| 139 virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; | 140 virtual void InvalidateScreen(const gfx::Size& size) OVERRIDE; |
| 140 virtual void InvalidateFullScreen() OVERRIDE; | 141 virtual void InvalidateFullScreen() OVERRIDE; |
| 141 virtual void CaptureInvalidRects(CaptureCompletedCallback* callback) OVERRIDE; | 142 virtual void CaptureInvalidRegion(CaptureCompletedCallback* callback) |
| 143 OVERRIDE; | |
| 142 virtual const gfx::Size& size_most_recent() const OVERRIDE; | 144 virtual const gfx::Size& size_most_recent() const OVERRIDE; |
| 143 | 145 |
| 144 private: | 146 private: |
| 145 void GlBlitFast(const VideoFrameBuffer& buffer, const InvalidRects& rects); | 147 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 146 void GlBlitSlow(const VideoFrameBuffer& buffer); | 148 void GlBlitSlow(const VideoFrameBuffer& buffer); |
| 147 void CgBlit(const VideoFrameBuffer& buffer, const InvalidRects& rects); | 149 void CgBlit(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 148 void CaptureRects(const InvalidRects& rects, | 150 void CaptureRegion(const SkRegion& region, |
| 149 CaptureCompletedCallback* callback); | 151 CaptureCompletedCallback* callback); |
| 150 | 152 |
| 151 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); | 153 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); |
| 152 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 154 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
| 153 size_t count, | 155 size_t count, |
| 154 const CGRect *rect_array); | 156 const CGRect *rect_array); |
| 155 static void ScreenRefreshCallback(CGRectCount count, | 157 static void ScreenRefreshCallback(CGRectCount count, |
| 156 const CGRect *rect_array, | 158 const CGRect *rect_array, |
| 157 void *user_parameter); | 159 void *user_parameter); |
| 158 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 160 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
| 159 size_t count, | 161 size_t count, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 173 // recently captured screen. | 175 // recently captured screen. |
| 174 CapturerHelper helper_; | 176 CapturerHelper helper_; |
| 175 | 177 |
| 176 // The current buffer with valid data for reading. | 178 // The current buffer with valid data for reading. |
| 177 int current_buffer_; | 179 int current_buffer_; |
| 178 | 180 |
| 179 // The last buffer into which we captured, or NULL for the first capture for | 181 // The last buffer into which we captured, or NULL for the first capture for |
| 180 // a particular screen resolution. | 182 // a particular screen resolution. |
| 181 uint8* last_buffer_; | 183 uint8* last_buffer_; |
| 182 | 184 |
| 183 // Contains a list of invalid rectangles in the last capture. | 185 // Contains an invalid region from the last capture. |
| 184 InvalidRects last_invalid_rects_; | 186 SkRegion last_invalid_region_; |
| 185 | 187 |
| 186 // Format of pixels returned in buffer. | 188 // Format of pixels returned in buffer. |
| 187 media::VideoFrame::Format pixel_format_; | 189 media::VideoFrame::Format pixel_format_; |
| 188 | 190 |
| 189 bool capturing_; | 191 bool capturing_; |
| 190 | 192 |
| 191 DISALLOW_COPY_AND_ASSIGN(CapturerMac); | 193 DISALLOW_COPY_AND_ASSIGN(CapturerMac); |
| 192 }; | 194 }; |
| 193 | 195 |
| 194 CapturerMac::CapturerMac() | 196 CapturerMac::CapturerMac() |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // The buffers might be in use by the encoder, so don't delete them here. | 235 // The buffers might be in use by the encoder, so don't delete them here. |
| 234 // Instead, mark them as "needs update"; next time the buffers are used by | 236 // Instead, mark them as "needs update"; next time the buffers are used by |
| 235 // the capturer, they will be recreated if necessary. | 237 // the capturer, they will be recreated if necessary. |
| 236 for (int i = 0; i < kNumBuffers; ++i) { | 238 for (int i = 0; i < kNumBuffers; ++i) { |
| 237 buffers_[i].set_needs_update(); | 239 buffers_[i].set_needs_update(); |
| 238 } | 240 } |
| 239 } | 241 } |
| 240 | 242 |
| 241 void CapturerMac::ScreenConfigurationChanged() { | 243 void CapturerMac::ScreenConfigurationChanged() { |
| 242 ReleaseBuffers(); | 244 ReleaseBuffers(); |
| 243 InvalidRects rects; | 245 SkRegion region; |
| 244 helper_.SwapInvalidRects(rects); | 246 helper_.SwapInvalidRegion(region); |
|
Wez
2011/08/08 20:49:34
Should be clear, not swap?
dmac
2011/08/10 20:30:36
Done.
| |
| 245 last_buffer_ = NULL; | 247 last_buffer_ = NULL; |
| 246 | 248 |
| 247 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 249 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
| 248 int width = CGDisplayPixelsWide(mainDevice); | 250 int width = CGDisplayPixelsWide(mainDevice); |
| 249 int height = CGDisplayPixelsHigh(mainDevice); | 251 int height = CGDisplayPixelsHigh(mainDevice); |
| 250 InvalidateScreen(gfx::Size(width, height)); | 252 InvalidateScreen(gfx::Size(width, height)); |
| 251 | 253 |
| 252 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { | 254 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { |
| 253 VLOG(3) << "OpenGL support not available."; | 255 VLOG(3) << "OpenGL support not available."; |
| 254 return; | 256 return; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 273 CGLSetCurrentContext(cgl_context_); | 275 CGLSetCurrentContext(cgl_context_); |
| 274 | 276 |
| 275 size_t buffer_size = width * height * sizeof(uint32_t); | 277 size_t buffer_size = width * height * sizeof(uint32_t); |
| 276 pixel_buffer_object_.Init(cgl_context_, buffer_size); | 278 pixel_buffer_object_.Init(cgl_context_, buffer_size); |
| 277 } | 279 } |
| 278 | 280 |
| 279 media::VideoFrame::Format CapturerMac::pixel_format() const { | 281 media::VideoFrame::Format CapturerMac::pixel_format() const { |
| 280 return pixel_format_; | 282 return pixel_format_; |
| 281 } | 283 } |
| 282 | 284 |
| 283 void CapturerMac::ClearInvalidRects() { | 285 void CapturerMac::ClearInvalidRegion() { |
| 284 helper_.ClearInvalidRects(); | 286 helper_.ClearInvalidRegion(); |
| 285 } | 287 } |
| 286 | 288 |
| 287 void CapturerMac::InvalidateRects(const InvalidRects& inval_rects) { | 289 void CapturerMac::InvalidateRegion(const SkRegion& inval_region) { |
| 288 helper_.InvalidateRects(inval_rects); | 290 helper_.InvalidateRegion(inval_region); |
| 289 } | 291 } |
| 290 | 292 |
| 291 void CapturerMac::InvalidateScreen(const gfx::Size& size) { | 293 void CapturerMac::InvalidateScreen(const gfx::Size& size) { |
| 292 helper_.InvalidateScreen(size); | 294 helper_.InvalidateScreen(size); |
| 293 } | 295 } |
| 294 | 296 |
| 295 void CapturerMac::InvalidateFullScreen() { | 297 void CapturerMac::InvalidateFullScreen() { |
| 296 helper_.InvalidateFullScreen(); | 298 helper_.InvalidateFullScreen(); |
| 297 } | 299 } |
| 298 | 300 |
| 299 void CapturerMac::CaptureInvalidRects(CaptureCompletedCallback* callback) { | 301 void CapturerMac::CaptureInvalidRegion(CaptureCompletedCallback* callback) { |
| 300 scoped_refptr<CaptureData> data; | 302 scoped_refptr<CaptureData> data; |
| 301 if (capturing_) { | 303 if (capturing_) { |
| 302 InvalidRects rects; | 304 SkRegion region; |
| 303 helper_.SwapInvalidRects(rects); | 305 helper_.SwapInvalidRegion(region); |
| 304 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; | 306 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; |
| 305 current_buffer.Update(); | 307 current_buffer.Update(); |
| 306 | 308 |
| 307 bool flip = true; // GL capturers need flipping. | 309 bool flip = true; // GL capturers need flipping. |
| 308 if (cgl_context_) { | 310 if (cgl_context_) { |
| 309 if (pixel_buffer_object_.get() != 0) { | 311 if (pixel_buffer_object_.get() != 0) { |
| 310 GlBlitFast(current_buffer, rects); | 312 GlBlitFast(current_buffer, region); |
| 311 } else { | 313 } else { |
| 312 // See comment in scoped_pixel_buffer_object::Init about why the slow | 314 // See comment in scoped_pixel_buffer_object::Init about why the slow |
| 313 // path is always used on 10.5. | 315 // path is always used on 10.5. |
| 314 GlBlitSlow(current_buffer); | 316 GlBlitSlow(current_buffer); |
| 315 } | 317 } |
| 316 } else { | 318 } else { |
| 317 CgBlit(current_buffer, rects); | 319 CgBlit(current_buffer, region); |
| 318 flip = false; | 320 flip = false; |
| 319 } | 321 } |
| 320 | 322 |
| 321 DataPlanes planes; | 323 DataPlanes planes; |
| 322 planes.data[0] = current_buffer.ptr(); | 324 planes.data[0] = current_buffer.ptr(); |
| 323 planes.strides[0] = current_buffer.bytes_per_row(); | 325 planes.strides[0] = current_buffer.bytes_per_row(); |
| 324 if (flip) { | 326 if (flip) { |
| 325 planes.strides[0] = -planes.strides[0]; | 327 planes.strides[0] = -planes.strides[0]; |
| 326 planes.data[0] += | 328 planes.data[0] += |
| 327 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); | 329 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); |
| 328 } | 330 } |
| 329 | 331 |
| 330 data = new CaptureData(planes, gfx::Size(current_buffer.size()), | 332 data = new CaptureData(planes, gfx::Size(current_buffer.size()), |
| 331 pixel_format()); | 333 pixel_format()); |
| 332 data->mutable_dirty_rects() = rects; | 334 data->mutable_dirty_region() = region; |
| 333 | 335 |
| 334 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | 336 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; |
| 335 helper_.set_size_most_recent(data->size()); | 337 helper_.set_size_most_recent(data->size()); |
| 336 } | 338 } |
| 337 | 339 |
| 338 callback->Run(data); | 340 callback->Run(data); |
| 339 delete callback; | 341 delete callback; |
| 340 } | 342 } |
| 341 | 343 |
| 342 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, | 344 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, |
| 343 const InvalidRects& rects) { | 345 const SkRegion& region) { |
| 344 if (last_buffer_) { | 346 if (last_buffer_) { |
| 345 // We are doing double buffer for the capture data so we just need to copy | 347 // We are doing double buffer for the capture data so we just need to copy |
| 346 // invalid rects in the last capture in the current buffer. | 348 // the invalid region from the last capture in the current buffer. |
|
Wez
2011/08/08 20:49:34
Same optimization Alpha suggests for the Linux cod
dmac
2011/08/10 20:30:36
Added comment
| |
| 347 // TODO(hclam): |last_invalid_rects_| and |rects| can overlap and this | |
| 348 // causes extra copies on the overlapped region. Subtract |rects| from | |
| 349 // |last_invalid_rects_| to do a minimal amount of copy when we have proper | |
| 350 // region algorithms implemented. | |
| 351 | 349 |
| 352 // Since the image obtained from OpenGL is upside-down, need to do some | 350 // Since the image obtained from OpenGL is upside-down, need to do some |
| 353 // magic here to copy the correct rectangle. | 351 // magic here to copy the correct rectangle. |
| 354 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); | 352 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); |
| 355 for (InvalidRects::iterator i = last_invalid_rects_.begin(); | 353 for(SkRegion::Iterator i(last_invalid_region_); !i.done(); i.next()) { |
| 356 i != last_invalid_rects_.end(); | |
| 357 ++i) { | |
| 358 CopyRect(last_buffer_ + y_offset, | 354 CopyRect(last_buffer_ + y_offset, |
| 359 -buffer.bytes_per_row(), | 355 -buffer.bytes_per_row(), |
| 360 buffer.ptr() + y_offset, | 356 buffer.ptr() + y_offset, |
| 361 -buffer.bytes_per_row(), | 357 -buffer.bytes_per_row(), |
| 362 4, // Bytes for pixel for RGBA. | 358 4, // Bytes for pixel for RGBA. |
| 363 *i); | 359 i.rect()); |
| 364 } | 360 } |
| 365 } | 361 } |
| 366 last_buffer_ = buffer.ptr(); | 362 last_buffer_ = buffer.ptr(); |
| 367 last_invalid_rects_ = rects; | 363 last_invalid_region_ = region; |
| 368 | 364 |
| 369 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 365 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
| 370 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); | 366 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); |
| 371 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), | 367 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), |
| 372 GL_BGRA, GL_UNSIGNED_BYTE, 0); | 368 GL_BGRA, GL_UNSIGNED_BYTE, 0); |
| 373 GLubyte* ptr = static_cast<GLubyte*>( | 369 GLubyte* ptr = static_cast<GLubyte*>( |
| 374 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); | 370 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); |
| 375 if (ptr == NULL) { | 371 if (ptr == NULL) { |
| 376 // If the buffer can't be mapped, assume that it's no longer valid and | 372 // If the buffer can't be mapped, assume that it's no longer valid and |
| 377 // release it. | 373 // release it. |
| 378 pixel_buffer_object_.Release(); | 374 pixel_buffer_object_.Release(); |
| 379 } else { | 375 } else { |
| 380 // Copy only from the dirty rects. Since the image obtained from OpenGL is | 376 // Copy only from the dirty rects. Since the image obtained from OpenGL is |
| 381 // upside-down we need to do some magic here to copy the correct rectangle. | 377 // upside-down we need to do some magic here to copy the correct rectangle. |
| 382 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); | 378 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); |
| 383 for (InvalidRects::iterator i = rects.begin(); i != rects.end(); ++i) { | 379 for(SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 384 CopyRect(ptr + y_offset, | 380 CopyRect(ptr + y_offset, |
| 385 -buffer.bytes_per_row(), | 381 -buffer.bytes_per_row(), |
| 386 buffer.ptr() + y_offset, | 382 buffer.ptr() + y_offset, |
| 387 -buffer.bytes_per_row(), | 383 -buffer.bytes_per_row(), |
| 388 4, // Bytes for pixel for RGBA. | 384 4, // Bytes for pixel for RGBA. |
| 389 *i); | 385 i.rect()); |
| 390 } | 386 } |
| 391 } | 387 } |
| 392 if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) { | 388 if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) { |
| 393 // If glUnmapBuffer returns false, then the contents of the data store are | 389 // If glUnmapBuffer returns false, then the contents of the data store are |
| 394 // undefined. This might be because the screen mode has changed, in which | 390 // undefined. This might be because the screen mode has changed, in which |
| 395 // case it will be recreated in ScreenConfigurationChanged, but releasing | 391 // case it will be recreated in ScreenConfigurationChanged, but releasing |
| 396 // the object here is the best option. Capturing will fall back on | 392 // the object here is the best option. Capturing will fall back on |
| 397 // GlBlitSlow until such time as the pixel buffer object is recreated. | 393 // GlBlitSlow until such time as the pixel buffer object is recreated. |
| 398 pixel_buffer_object_.Release(); | 394 pixel_buffer_object_.Release(); |
| 399 } | 395 } |
| 400 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); | 396 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 401 } | 397 } |
| 402 | 398 |
| 403 void CapturerMac::GlBlitSlow(const VideoFrameBuffer& buffer) { | 399 void CapturerMac::GlBlitSlow(const VideoFrameBuffer& buffer) { |
| 404 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 400 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
| 405 glReadBuffer(GL_FRONT); | 401 glReadBuffer(GL_FRONT); |
| 406 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); | 402 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); |
| 407 glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment. | 403 glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment. |
| 408 glPixelStorei(GL_PACK_ROW_LENGTH, 0); | 404 glPixelStorei(GL_PACK_ROW_LENGTH, 0); |
| 409 glPixelStorei(GL_PACK_SKIP_ROWS, 0); | 405 glPixelStorei(GL_PACK_SKIP_ROWS, 0); |
| 410 glPixelStorei(GL_PACK_SKIP_PIXELS, 0); | 406 glPixelStorei(GL_PACK_SKIP_PIXELS, 0); |
| 411 // Read a block of pixels from the frame buffer. | 407 // Read a block of pixels from the frame buffer. |
| 412 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), | 408 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), |
| 413 GL_BGRA, GL_UNSIGNED_BYTE, buffer.ptr()); | 409 GL_BGRA, GL_UNSIGNED_BYTE, buffer.ptr()); |
| 414 glPopClientAttrib(); | 410 glPopClientAttrib(); |
| 415 } | 411 } |
| 416 | 412 |
| 417 void CapturerMac::CgBlit(const VideoFrameBuffer& buffer, | 413 void CapturerMac::CgBlit(const VideoFrameBuffer& buffer, |
| 418 const InvalidRects& rects) { | 414 const SkRegion& region) { |
| 419 if (last_buffer_) | 415 if (last_buffer_) |
| 420 memcpy(buffer.ptr(), last_buffer_, | 416 memcpy(buffer.ptr(), last_buffer_, |
| 421 buffer.bytes_per_row() * buffer.size().height()); | 417 buffer.bytes_per_row() * buffer.size().height()); |
| 422 last_buffer_ = buffer.ptr(); | 418 last_buffer_ = buffer.ptr(); |
| 423 CGDirectDisplayID main_display = CGMainDisplayID(); | 419 CGDirectDisplayID main_display = CGMainDisplayID(); |
| 424 uint8* display_base_address = | 420 uint8* display_base_address = |
| 425 reinterpret_cast<uint8*>(CGDisplayBaseAddress(main_display)); | 421 reinterpret_cast<uint8*>(CGDisplayBaseAddress(main_display)); |
| 426 int src_bytes_per_row = CGDisplayBytesPerRow(main_display); | 422 int src_bytes_per_row = CGDisplayBytesPerRow(main_display); |
| 427 int src_bytes_per_pixel = CGDisplayBitsPerPixel(main_display) / 8; | 423 int src_bytes_per_pixel = CGDisplayBitsPerPixel(main_display) / 8; |
| 428 for (InvalidRects::iterator i = rects.begin(); i != rects.end(); ++i) { | 424 for(SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 429 CopyRect(display_base_address, | 425 CopyRect(display_base_address, |
| 430 src_bytes_per_row, | 426 src_bytes_per_row, |
| 431 buffer.ptr(), | 427 buffer.ptr(), |
| 432 buffer.bytes_per_row(), | 428 buffer.bytes_per_row(), |
| 433 src_bytes_per_pixel, | 429 src_bytes_per_pixel, |
| 434 *i); | 430 i.rect()); |
| 435 } | 431 } |
| 436 } | 432 } |
| 437 | 433 |
| 438 const gfx::Size& CapturerMac::size_most_recent() const { | 434 const gfx::Size& CapturerMac::size_most_recent() const { |
| 439 return helper_.size_most_recent(); | 435 return helper_.size_most_recent(); |
| 440 } | 436 } |
| 441 | 437 |
| 442 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { | 438 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { |
| 443 InvalidRects rects; | 439 SkIRect skirect_array[count]; |
| 444 for (CGRectCount i = 0; i < count; ++i) { | 440 for (CGRectCount i = 0; i < count; ++i) { |
| 445 rects.insert(gfx::Rect(rect_array[i])); | 441 skirect_array[i] = gfx::CGRectToSkIRect(rect_array[i]); |
| 446 } | 442 } |
| 447 InvalidateRects(rects); | 443 SkRegion region; |
| 444 region.setRects(skirect_array, count); | |
| 445 InvalidateRegion(region); | |
| 448 } | 446 } |
| 449 | 447 |
| 450 void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 448 void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
| 451 size_t count, | 449 size_t count, |
| 452 const CGRect *rect_array) { | 450 const CGRect *rect_array) { |
| 453 InvalidRects rects; | 451 SkIRect skirect_old_array[count]; |
| 452 SkIRect skirect_new_array[count]; | |
| 454 for (CGRectCount i = 0; i < count; ++i) { | 453 for (CGRectCount i = 0; i < count; ++i) { |
| 455 CGRect rect = rect_array[i]; | 454 CGRect rect = rect_array[i]; |
| 456 rects.insert(gfx::Rect(rect)); | 455 skirect_old_array[i] = gfx::CGRectToSkIRect(rect); |
| 457 rect = CGRectOffset(rect, delta.dX, delta.dY); | 456 rect = CGRectOffset(rect, delta.dX, delta.dY); |
| 458 rects.insert(gfx::Rect(rect)); | 457 skirect_new_array[i] = gfx::CGRectToSkIRect(rect); |
| 459 } | 458 } |
| 460 InvalidateRects(rects); | 459 SkRegion region; |
| 460 region.setRects(skirect_old_array, count); | |
| 461 InvalidateRegion(region); | |
| 462 region.setRects(skirect_new_array, count); | |
| 463 InvalidateRegion(region); | |
|
Wez
2011/08/08 20:49:34
Do we need to invalidate the source region for the
dmac
2011/08/10 20:30:36
Good point. Done.
| |
| 461 } | 464 } |
| 462 | 465 |
| 463 void CapturerMac::ScreenRefreshCallback(CGRectCount count, | 466 void CapturerMac::ScreenRefreshCallback(CGRectCount count, |
| 464 const CGRect *rect_array, | 467 const CGRect *rect_array, |
| 465 void *user_parameter) { | 468 void *user_parameter) { |
| 466 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 469 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
| 467 capturer->ScreenRefresh(count, rect_array); | 470 capturer->ScreenRefresh(count, rect_array); |
| 468 } | 471 } |
| 469 | 472 |
| 470 void CapturerMac::ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 473 void CapturerMac::ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 491 } | 494 } |
| 492 | 495 |
| 493 } // namespace | 496 } // namespace |
| 494 | 497 |
| 495 // static | 498 // static |
| 496 Capturer* Capturer::Create() { | 499 Capturer* Capturer::Create() { |
| 497 return new CapturerMac(); | 500 return new CapturerMac(); |
| 498 } | 501 } |
| 499 | 502 |
| 500 } // namespace remoting | 503 } // namespace remoting |
| OLD | NEW |