| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/codec/video_decoder_verbatim.h" | 5 #include "remoting/codec/video_decoder_verbatim.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "remoting/base/util.h" | 8 #include "remoting/base/util.h" |
| 9 | 9 |
| 10 namespace remoting { | 10 namespace remoting { |
| 11 | 11 |
| 12 VideoDecoderVerbatim::VideoDecoderVerbatim() | 12 VideoDecoderVerbatim::VideoDecoderVerbatim() {} |
| 13 : screen_size_(SkISize::Make(0, 0)) {} | |
| 14 | 13 |
| 15 VideoDecoderVerbatim::~VideoDecoderVerbatim() {} | 14 VideoDecoderVerbatim::~VideoDecoderVerbatim() {} |
| 16 | 15 |
| 17 void VideoDecoderVerbatim::Initialize(const SkISize& screen_size) { | 16 void VideoDecoderVerbatim::Initialize(const webrtc::DesktopSize& screen_size) { |
| 18 updated_region_.setEmpty(); | 17 updated_region_.Clear(); |
| 19 screen_buffer_.reset(); | 18 screen_buffer_.reset(); |
| 20 | 19 |
| 21 screen_size_ = screen_size; | 20 screen_size_ = screen_size; |
| 22 // Allocate the screen buffer, if necessary. | 21 // Allocate the screen buffer, if necessary. |
| 23 if (!screen_size_.isEmpty()) { | 22 if (!screen_size_.is_empty()) { |
| 24 screen_buffer_.reset( | 23 screen_buffer_.reset( |
| 25 new uint8[screen_size_.width() * screen_size_.height() * | 24 new uint8[screen_size_.width() * screen_size_.height() * |
| 26 kBytesPerPixel]); | 25 kBytesPerPixel]); |
| 27 } | 26 } |
| 28 } | 27 } |
| 29 | 28 |
| 30 bool VideoDecoderVerbatim::DecodePacket(const VideoPacket& packet) { | 29 bool VideoDecoderVerbatim::DecodePacket(const VideoPacket& packet) { |
| 31 SkRegion region; | 30 webrtc::DesktopRegion region; |
| 32 | 31 |
| 33 const char* in = packet.data().data(); | 32 const char* in = packet.data().data(); |
| 34 int stride = kBytesPerPixel * screen_size_.width(); | 33 int stride = kBytesPerPixel * screen_size_.width(); |
| 35 for (int i = 0; i < packet.dirty_rects_size(); ++i) { | 34 for (int i = 0; i < packet.dirty_rects_size(); ++i) { |
| 36 Rect proto_rect = packet.dirty_rects(i); | 35 Rect proto_rect = packet.dirty_rects(i); |
| 37 SkIRect rect = SkIRect::MakeXYWH(proto_rect.x(), | 36 webrtc::DesktopRect rect = |
| 38 proto_rect.y(), | 37 webrtc::DesktopRect::MakeXYWH(proto_rect.x(), |
| 39 proto_rect.width(), | 38 proto_rect.y(), |
| 40 proto_rect.height()); | 39 proto_rect.width(), |
| 41 region.op(rect, SkRegion::kUnion_Op); | 40 proto_rect.height()); |
| 41 region.AddRect(rect); |
| 42 | 42 |
| 43 if (!SkIRect::MakeSize(screen_size_).contains(rect)) { | 43 if (!DoesRectContain(webrtc::DesktopRect::MakeSize(screen_size_), rect)) { |
| 44 LOG(ERROR) << "Invalid packet received"; | 44 LOG(ERROR) << "Invalid packet received"; |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 int rect_row_size = kBytesPerPixel * rect.width(); | 48 int rect_row_size = kBytesPerPixel * rect.width(); |
| 49 uint8_t* out = screen_buffer_.get() + rect.y() * stride + | 49 uint8_t* out = screen_buffer_.get() + rect.top() * stride + |
| 50 rect.x() * kBytesPerPixel; | 50 rect.left() * kBytesPerPixel; |
| 51 for (int y = rect.y(); y < rect.y() + rect.height(); ++y) { | 51 for (int y = rect.top(); y < rect.top() + rect.height(); ++y) { |
| 52 if (in + rect_row_size > packet.data().data() + packet.data().size()) { | 52 if (in + rect_row_size > packet.data().data() + packet.data().size()) { |
| 53 LOG(ERROR) << "Invalid packet received"; | 53 LOG(ERROR) << "Invalid packet received"; |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 memcpy(out, in, rect_row_size); | 56 memcpy(out, in, rect_row_size); |
| 57 in += rect_row_size; | 57 in += rect_row_size; |
| 58 out += stride; | 58 out += stride; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 if (in != packet.data().data() + packet.data().size()) { | 62 if (in != packet.data().data() + packet.data().size()) { |
| 63 LOG(ERROR) << "Invalid packet received"; | 63 LOG(ERROR) << "Invalid packet received"; |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 | 66 |
| 67 updated_region_.op(region, SkRegion::kUnion_Op); | 67 updated_region_.AddRegion(region); |
| 68 | 68 |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void VideoDecoderVerbatim::Invalidate(const SkISize& view_size, | 72 void VideoDecoderVerbatim::Invalidate(const webrtc::DesktopSize& view_size, |
| 73 const SkRegion& region) { | 73 const webrtc::DesktopRegion& region) { |
| 74 updated_region_.op(region, SkRegion::kUnion_Op); | 74 updated_region_.AddRegion(region); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void VideoDecoderVerbatim::RenderFrame(const SkISize& view_size, | 77 void VideoDecoderVerbatim::RenderFrame(const webrtc::DesktopSize& view_size, |
| 78 const SkIRect& clip_area, | 78 const webrtc::DesktopRect& clip_area, |
| 79 uint8* image_buffer, | 79 uint8* image_buffer, |
| 80 int image_stride, | 80 int image_stride, |
| 81 SkRegion* output_region) { | 81 webrtc::DesktopRegion* output_region) { |
| 82 output_region->setEmpty(); | 82 output_region->Clear(); |
| 83 | 83 |
| 84 // TODO(alexeypa): scaling is not implemented. | 84 // TODO(alexeypa): scaling is not implemented. |
| 85 SkIRect clip_rect = SkIRect::MakeSize(screen_size_); | 85 webrtc::DesktopRect clip_rect = webrtc::DesktopRect::MakeSize(screen_size_); |
| 86 if (!clip_rect.intersect(clip_area)) | 86 clip_rect.IntersectWith(clip_area); |
| 87 if (clip_rect.is_empty()) |
| 87 return; | 88 return; |
| 88 | 89 |
| 89 int screen_stride = screen_size_.width() * kBytesPerPixel; | 90 int screen_stride = screen_size_.width() * kBytesPerPixel; |
| 90 | 91 |
| 91 for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) { | 92 for (webrtc::DesktopRegion::Iterator i(updated_region_); |
| 92 SkIRect rect(i.rect()); | 93 !i.IsAtEnd(); i.Advance()) { |
| 93 if (!rect.intersect(clip_rect)) | 94 webrtc::DesktopRect rect(i.rect()); |
| 95 rect.IntersectWith(clip_rect); |
| 96 if (rect.is_empty()) |
| 94 continue; | 97 continue; |
| 95 | 98 |
| 96 CopyRGB32Rect(screen_buffer_.get(), screen_stride, | 99 CopyRGB32Rect(screen_buffer_.get(), screen_stride, |
| 97 clip_rect, | 100 clip_rect, |
| 98 image_buffer, image_stride, | 101 image_buffer, image_stride, |
| 99 clip_area, | 102 clip_area, |
| 100 rect); | 103 rect); |
| 101 output_region->op(rect, SkRegion::kUnion_Op); | 104 output_region->AddRect(rect); |
| 102 } | 105 } |
| 103 | 106 |
| 104 updated_region_.setEmpty(); | 107 updated_region_.Clear(); |
| 105 } | 108 } |
| 106 | 109 |
| 107 const SkRegion* VideoDecoderVerbatim::GetImageShape() { | 110 const webrtc::DesktopRegion* VideoDecoderVerbatim::GetImageShape() { |
| 108 return NULL; | 111 return NULL; |
| 109 } | 112 } |
| 110 | 113 |
| 111 } // namespace remoting | 114 } // namespace remoting |
| OLD | NEW |