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