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& invalid_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. |
Wez
2011/08/10 22:05:43
nit: "last"->"previous"
| |
184 InvalidRects last_invalid_rects_; | 186 SkRegion last_invalid_region_; |
Wez
2011/08/10 22:05:43
nit: |previous...|
| |
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 helper_.ClearInvalidRegion(); |
244 helper_.SwapInvalidRects(rects); | |
245 last_buffer_ = NULL; | 246 last_buffer_ = NULL; |
246 | 247 |
247 CGDirectDisplayID mainDevice = CGMainDisplayID(); | 248 CGDirectDisplayID mainDevice = CGMainDisplayID(); |
248 int width = CGDisplayPixelsWide(mainDevice); | 249 int width = CGDisplayPixelsWide(mainDevice); |
249 int height = CGDisplayPixelsHigh(mainDevice); | 250 int height = CGDisplayPixelsHigh(mainDevice); |
250 InvalidateScreen(gfx::Size(width, height)); | 251 InvalidateScreen(gfx::Size(width, height)); |
251 | 252 |
252 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { | 253 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { |
253 VLOG(3) << "OpenGL support not available."; | 254 VLOG(3) << "OpenGL support not available."; |
254 return; | 255 return; |
(...skipping 18 matching lines...) Expand all Loading... | |
273 CGLSetCurrentContext(cgl_context_); | 274 CGLSetCurrentContext(cgl_context_); |
274 | 275 |
275 size_t buffer_size = width * height * sizeof(uint32_t); | 276 size_t buffer_size = width * height * sizeof(uint32_t); |
276 pixel_buffer_object_.Init(cgl_context_, buffer_size); | 277 pixel_buffer_object_.Init(cgl_context_, buffer_size); |
277 } | 278 } |
278 | 279 |
279 media::VideoFrame::Format CapturerMac::pixel_format() const { | 280 media::VideoFrame::Format CapturerMac::pixel_format() const { |
280 return pixel_format_; | 281 return pixel_format_; |
281 } | 282 } |
282 | 283 |
283 void CapturerMac::ClearInvalidRects() { | 284 void CapturerMac::ClearInvalidRegion() { |
284 helper_.ClearInvalidRects(); | 285 helper_.ClearInvalidRegion(); |
285 } | 286 } |
286 | 287 |
287 void CapturerMac::InvalidateRects(const InvalidRects& inval_rects) { | 288 void CapturerMac::InvalidateRegion(const SkRegion& invalid_region) { |
288 helper_.InvalidateRects(inval_rects); | 289 helper_.InvalidateRegion(invalid_region); |
289 } | 290 } |
290 | 291 |
291 void CapturerMac::InvalidateScreen(const gfx::Size& size) { | 292 void CapturerMac::InvalidateScreen(const gfx::Size& size) { |
292 helper_.InvalidateScreen(size); | 293 helper_.InvalidateScreen(size); |
293 } | 294 } |
294 | 295 |
295 void CapturerMac::InvalidateFullScreen() { | 296 void CapturerMac::InvalidateFullScreen() { |
296 helper_.InvalidateFullScreen(); | 297 helper_.InvalidateFullScreen(); |
297 } | 298 } |
298 | 299 |
299 void CapturerMac::CaptureInvalidRects(CaptureCompletedCallback* callback) { | 300 void CapturerMac::CaptureInvalidRegion(CaptureCompletedCallback* callback) { |
300 scoped_refptr<CaptureData> data; | 301 scoped_refptr<CaptureData> data; |
301 if (capturing_) { | 302 if (capturing_) { |
302 InvalidRects rects; | 303 SkRegion region; |
303 helper_.SwapInvalidRects(rects); | 304 helper_.SwapInvalidRegion(®ion); |
304 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; | 305 VideoFrameBuffer& current_buffer = buffers_[current_buffer_]; |
305 current_buffer.Update(); | 306 current_buffer.Update(); |
306 | 307 |
307 bool flip = true; // GL capturers need flipping. | 308 bool flip = true; // GL capturers need flipping. |
308 if (cgl_context_) { | 309 if (cgl_context_) { |
309 if (pixel_buffer_object_.get() != 0) { | 310 if (pixel_buffer_object_.get() != 0) { |
310 GlBlitFast(current_buffer, rects); | 311 GlBlitFast(current_buffer, region); |
311 } else { | 312 } else { |
312 // See comment in scoped_pixel_buffer_object::Init about why the slow | 313 // See comment in scoped_pixel_buffer_object::Init about why the slow |
313 // path is always used on 10.5. | 314 // path is always used on 10.5. |
314 GlBlitSlow(current_buffer); | 315 GlBlitSlow(current_buffer); |
315 } | 316 } |
316 } else { | 317 } else { |
317 CgBlit(current_buffer, rects); | 318 CgBlit(current_buffer, region); |
318 flip = false; | 319 flip = false; |
319 } | 320 } |
320 | 321 |
321 DataPlanes planes; | 322 DataPlanes planes; |
322 planes.data[0] = current_buffer.ptr(); | 323 planes.data[0] = current_buffer.ptr(); |
323 planes.strides[0] = current_buffer.bytes_per_row(); | 324 planes.strides[0] = current_buffer.bytes_per_row(); |
324 if (flip) { | 325 if (flip) { |
325 planes.strides[0] = -planes.strides[0]; | 326 planes.strides[0] = -planes.strides[0]; |
326 planes.data[0] += | 327 planes.data[0] += |
327 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); | 328 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); |
328 } | 329 } |
329 | 330 |
330 data = new CaptureData(planes, gfx::Size(current_buffer.size()), | 331 data = new CaptureData(planes, gfx::Size(current_buffer.size()), |
331 pixel_format()); | 332 pixel_format()); |
332 data->mutable_dirty_rects() = rects; | 333 data->mutable_dirty_region() = region; |
333 | 334 |
334 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | 335 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; |
335 helper_.set_size_most_recent(data->size()); | 336 helper_.set_size_most_recent(data->size()); |
336 } | 337 } |
337 | 338 |
338 callback->Run(data); | 339 callback->Run(data); |
339 delete callback; | 340 delete callback; |
340 } | 341 } |
341 | 342 |
342 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, | 343 void CapturerMac::GlBlitFast(const VideoFrameBuffer& buffer, |
343 const InvalidRects& rects) { | 344 const SkRegion& region) { |
344 if (last_buffer_) { | 345 if (last_buffer_) { |
345 // We are doing double buffer for the capture data so we just need to copy | 346 // 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. | 347 // the invalid region from the last capture in the current buffer. |
Wez
2011/08/10 22:05:43
nit: previous.
| |
347 // TODO(hclam): |last_invalid_rects_| and |rects| can overlap and this | 348 // TODO(hclam): We can reduce the amount of copying here by subtracting |
348 // causes extra copies on the overlapped region. Subtract |rects| from | 349 // |capturer_helper_|s region from |last_invalid_region_|. |
349 // |last_invalid_rects_| to do a minimal amount of copy when we have proper | 350 // http://crbug.com/92354 |
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 (InvalidRects::iterator i = last_invalid_rects_.begin(); | 355 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, | 356 CopyRect(last_buffer_ + y_offset, |
359 -buffer.bytes_per_row(), | 357 -buffer.bytes_per_row(), |
360 buffer.ptr() + y_offset, | 358 buffer.ptr() + y_offset, |
361 -buffer.bytes_per_row(), | 359 -buffer.bytes_per_row(), |
362 4, // Bytes for pixel for RGBA. | 360 4, // Bytes for pixel for RGBA. |
363 *i); | 361 i.rect()); |
364 } | 362 } |
365 } | 363 } |
366 last_buffer_ = buffer.ptr(); | 364 last_buffer_ = buffer.ptr(); |
367 last_invalid_rects_ = rects; | 365 last_invalid_region_ = region; |
368 | 366 |
369 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 367 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
370 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); | 368 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pixel_buffer_object_.get()); |
371 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), | 369 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), |
372 GL_BGRA, GL_UNSIGNED_BYTE, 0); | 370 GL_BGRA, GL_UNSIGNED_BYTE, 0); |
373 GLubyte* ptr = static_cast<GLubyte*>( | 371 GLubyte* ptr = static_cast<GLubyte*>( |
374 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); | 372 glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)); |
375 if (ptr == NULL) { | 373 if (ptr == NULL) { |
376 // 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 |
377 // release it. | 375 // release it. |
378 pixel_buffer_object_.Release(); | 376 pixel_buffer_object_.Release(); |
379 } else { | 377 } else { |
380 // 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 |
381 // 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. |
382 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); | 380 const int y_offset = (buffer.size().height() - 1) * buffer.bytes_per_row(); |
383 for (InvalidRects::iterator i = rects.begin(); i != rects.end(); ++i) { | 381 for(SkRegion::Iterator i(region); !i.done(); i.next()) { |
384 CopyRect(ptr + y_offset, | 382 CopyRect(ptr + y_offset, |
385 -buffer.bytes_per_row(), | 383 -buffer.bytes_per_row(), |
386 buffer.ptr() + y_offset, | 384 buffer.ptr() + y_offset, |
387 -buffer.bytes_per_row(), | 385 -buffer.bytes_per_row(), |
388 4, // Bytes for pixel for RGBA. | 386 4, // Bytes for pixel for RGBA. |
389 *i); | 387 i.rect()); |
390 } | 388 } |
391 } | 389 } |
392 if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) { | 390 if (!glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB)) { |
393 // If glUnmapBuffer returns false, then the contents of the data store are | 391 // 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 | 392 // undefined. This might be because the screen mode has changed, in which |
395 // case it will be recreated in ScreenConfigurationChanged, but releasing | 393 // case it will be recreated in ScreenConfigurationChanged, but releasing |
396 // the object here is the best option. Capturing will fall back on | 394 // the object here is the best option. Capturing will fall back on |
397 // GlBlitSlow until such time as the pixel buffer object is recreated. | 395 // GlBlitSlow until such time as the pixel buffer object is recreated. |
398 pixel_buffer_object_.Release(); | 396 pixel_buffer_object_.Release(); |
399 } | 397 } |
400 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); | 398 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); |
401 } | 399 } |
402 | 400 |
403 void CapturerMac::GlBlitSlow(const VideoFrameBuffer& buffer) { | 401 void CapturerMac::GlBlitSlow(const VideoFrameBuffer& buffer) { |
404 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; | 402 CGLContextObj CGL_MACRO_CONTEXT = cgl_context_; |
405 glReadBuffer(GL_FRONT); | 403 glReadBuffer(GL_FRONT); |
406 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); | 404 glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); |
407 glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment. | 405 glPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment. |
408 glPixelStorei(GL_PACK_ROW_LENGTH, 0); | 406 glPixelStorei(GL_PACK_ROW_LENGTH, 0); |
409 glPixelStorei(GL_PACK_SKIP_ROWS, 0); | 407 glPixelStorei(GL_PACK_SKIP_ROWS, 0); |
410 glPixelStorei(GL_PACK_SKIP_PIXELS, 0); | 408 glPixelStorei(GL_PACK_SKIP_PIXELS, 0); |
411 // Read a block of pixels from the frame buffer. | 409 // Read a block of pixels from the frame buffer. |
412 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), | 410 glReadPixels(0, 0, buffer.size().width(), buffer.size().height(), |
413 GL_BGRA, GL_UNSIGNED_BYTE, buffer.ptr()); | 411 GL_BGRA, GL_UNSIGNED_BYTE, buffer.ptr()); |
414 glPopClientAttrib(); | 412 glPopClientAttrib(); |
415 } | 413 } |
416 | 414 |
417 void CapturerMac::CgBlit(const VideoFrameBuffer& buffer, | 415 void CapturerMac::CgBlit(const VideoFrameBuffer& buffer, |
418 const InvalidRects& rects) { | 416 const SkRegion& region) { |
419 if (last_buffer_) | 417 if (last_buffer_) |
420 memcpy(buffer.ptr(), last_buffer_, | 418 memcpy(buffer.ptr(), last_buffer_, |
421 buffer.bytes_per_row() * buffer.size().height()); | 419 buffer.bytes_per_row() * buffer.size().height()); |
422 last_buffer_ = buffer.ptr(); | 420 last_buffer_ = buffer.ptr(); |
423 CGDirectDisplayID main_display = CGMainDisplayID(); | 421 CGDirectDisplayID main_display = CGMainDisplayID(); |
424 uint8* display_base_address = | 422 uint8* display_base_address = |
425 reinterpret_cast<uint8*>(CGDisplayBaseAddress(main_display)); | 423 reinterpret_cast<uint8*>(CGDisplayBaseAddress(main_display)); |
426 int src_bytes_per_row = CGDisplayBytesPerRow(main_display); | 424 int src_bytes_per_row = CGDisplayBytesPerRow(main_display); |
427 int src_bytes_per_pixel = CGDisplayBitsPerPixel(main_display) / 8; | 425 int src_bytes_per_pixel = CGDisplayBitsPerPixel(main_display) / 8; |
428 for (InvalidRects::iterator i = rects.begin(); i != rects.end(); ++i) { | 426 // TODO(hclam): We can reduce the amount of copying here by subtracting |
427 // |capturer_helper_|s region from |last_invalid_region_|. | |
428 // http://crbug.com/92354 | |
429 for(SkRegion::Iterator i(region); !i.done(); i.next()) { | |
429 CopyRect(display_base_address, | 430 CopyRect(display_base_address, |
430 src_bytes_per_row, | 431 src_bytes_per_row, |
431 buffer.ptr(), | 432 buffer.ptr(), |
432 buffer.bytes_per_row(), | 433 buffer.bytes_per_row(), |
433 src_bytes_per_pixel, | 434 src_bytes_per_pixel, |
434 *i); | 435 i.rect()); |
435 } | 436 } |
436 } | 437 } |
437 | 438 |
438 const gfx::Size& CapturerMac::size_most_recent() const { | 439 const gfx::Size& CapturerMac::size_most_recent() const { |
439 return helper_.size_most_recent(); | 440 return helper_.size_most_recent(); |
440 } | 441 } |
441 | 442 |
442 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { | 443 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { |
443 InvalidRects rects; | 444 SkIRect skirect_array[count]; |
444 for (CGRectCount i = 0; i < count; ++i) { | 445 for (CGRectCount i = 0; i < count; ++i) { |
445 rects.insert(gfx::Rect(rect_array[i])); | 446 skirect_array[i] = gfx::CGRectToSkIRect(rect_array[i]); |
446 } | 447 } |
447 InvalidateRects(rects); | 448 SkRegion region; |
449 region.setRects(skirect_array, count); | |
450 InvalidateRegion(region); | |
448 } | 451 } |
449 | 452 |
450 void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 453 void CapturerMac::ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
451 size_t count, | 454 size_t count, |
452 const CGRect *rect_array) { | 455 const CGRect *rect_array) { |
453 InvalidRects rects; | 456 SkIRect skirect_new_array[count]; |
454 for (CGRectCount i = 0; i < count; ++i) { | 457 for (CGRectCount i = 0; i < count; ++i) { |
455 CGRect rect = rect_array[i]; | 458 CGRect rect = rect_array[i]; |
456 rects.insert(gfx::Rect(rect)); | |
457 rect = CGRectOffset(rect, delta.dX, delta.dY); | 459 rect = CGRectOffset(rect, delta.dX, delta.dY); |
458 rects.insert(gfx::Rect(rect)); | 460 skirect_new_array[i] = gfx::CGRectToSkIRect(rect); |
459 } | 461 } |
460 InvalidateRects(rects); | 462 SkRegion region; |
463 region.setRects(skirect_new_array, count); | |
464 InvalidateRegion(region); | |
461 } | 465 } |
462 | 466 |
463 void CapturerMac::ScreenRefreshCallback(CGRectCount count, | 467 void CapturerMac::ScreenRefreshCallback(CGRectCount count, |
464 const CGRect *rect_array, | 468 const CGRect *rect_array, |
465 void *user_parameter) { | 469 void *user_parameter) { |
466 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); | 470 CapturerMac *capturer = reinterpret_cast<CapturerMac *>(user_parameter); |
467 capturer->ScreenRefresh(count, rect_array); | 471 capturer->ScreenRefresh(count, rect_array); |
468 } | 472 } |
469 | 473 |
470 void CapturerMac::ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 474 void CapturerMac::ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
(...skipping 20 matching lines...) Expand all Loading... | |
491 } | 495 } |
492 | 496 |
493 } // namespace | 497 } // namespace |
494 | 498 |
495 // static | 499 // static |
496 Capturer* Capturer::Create() { | 500 Capturer* Capturer::Create() { |
497 return new CapturerMac(); | 501 return new CapturerMac(); |
498 } | 502 } |
499 | 503 |
500 } // namespace remoting | 504 } // namespace remoting |
OLD | NEW |