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/base/encoder_vp8.h" | 5 #include "remoting/base/encoder_vp8.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/base/callback.h" | 8 #include "media/base/callback.h" |
9 #include "media/base/yuv_convert.h" | 9 #include "media/base/yuv_convert.h" |
10 #include "remoting/base/capture_data.h" | 10 #include "remoting/base/capture_data.h" |
11 #include "remoting/base/util.h" | 11 #include "remoting/base/util.h" |
12 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
| 13 #include "third_party/skia/include/core/SkRegion.h" |
13 | 14 |
14 extern "C" { | 15 extern "C" { |
15 #define VPX_CODEC_DISABLE_COMPAT 1 | 16 #define VPX_CODEC_DISABLE_COMPAT 1 |
16 #include "third_party/libvpx/libvpx.h" | 17 #include "third_party/libvpx/libvpx.h" |
17 } | 18 } |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Defines the dimension of a macro block. This is used to compute the active | 22 // Defines the dimension of a macro block. This is used to compute the active |
22 // map for the encoder. | 23 // map for the encoder. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 142 } |
142 | 143 |
143 bool EncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, | 144 bool EncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, |
144 std::vector<gfx::Rect>* updated_rects) { | 145 std::vector<gfx::Rect>* updated_rects) { |
145 // Perform RGB->YUV conversion. | 146 // Perform RGB->YUV conversion. |
146 if (capture_data->pixel_format() != media::VideoFrame::RGB32) { | 147 if (capture_data->pixel_format() != media::VideoFrame::RGB32) { |
147 LOG(ERROR) << "Only RGB32 is supported"; | 148 LOG(ERROR) << "Only RGB32 is supported"; |
148 return false; | 149 return false; |
149 } | 150 } |
150 | 151 |
151 const InvalidRects& rects = capture_data->dirty_rects(); | 152 const SkRegion& region = capture_data->dirty_region(); |
152 const uint8* in = capture_data->data_planes().data[0]; | 153 const uint8* in = capture_data->data_planes().data[0]; |
153 const int in_stride = capture_data->data_planes().strides[0]; | 154 const int in_stride = capture_data->data_planes().strides[0]; |
154 const int plane_size = | 155 const int plane_size = |
155 capture_data->size().width() * capture_data->size().height(); | 156 capture_data->size().width() * capture_data->size().height(); |
156 uint8* y_out = yuv_image_.get(); | 157 uint8* y_out = yuv_image_.get(); |
157 uint8* u_out = yuv_image_.get() + plane_size; | 158 uint8* u_out = yuv_image_.get() + plane_size; |
158 uint8* v_out = yuv_image_.get() + plane_size + plane_size / 4; | 159 uint8* v_out = yuv_image_.get() + plane_size + plane_size / 4; |
159 const int y_stride = image_->stride[0]; | 160 const int y_stride = image_->stride[0]; |
160 const int uv_stride = image_->stride[1]; | 161 const int uv_stride = image_->stride[1]; |
161 | 162 |
162 DCHECK(updated_rects->empty()); | 163 DCHECK(updated_rects->empty()); |
163 for (InvalidRects::const_iterator r = rects.begin(); r != rects.end(); ++r) { | 164 for (SkRegion::Iterator r(region); !r.done(); r.next()) { |
164 // Align the rectangle, report it as updated. | 165 // Align the rectangle, report it as updated. |
165 gfx::Rect rect = AlignAndClipRect(*r, image_->w, image_->h); | 166 SkIRect skRect = r.rect(); |
| 167 gfx::Rect rect(skRect.fLeft, skRect.fTop, skRect.width(), skRect.height()); |
| 168 rect = AlignAndClipRect(rect, image_->w, image_->h); |
166 if (!rect.IsEmpty()) | 169 if (!rect.IsEmpty()) |
167 updated_rects->push_back(rect); | 170 updated_rects->push_back(rect); |
168 | 171 |
169 ConvertRGB32ToYUVWithRect(in, | 172 ConvertRGB32ToYUVWithRect(in, |
170 y_out, | 173 y_out, |
171 u_out, | 174 u_out, |
172 v_out, | 175 v_out, |
173 rect.x(), | 176 rect.x(), |
174 rect.y(), | 177 rect.y(), |
175 rect.width(), | 178 rect.width(), |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 rect->set_y(updated_rects[i].y()); | 287 rect->set_y(updated_rects[i].y()); |
285 rect->set_width(updated_rects[i].width()); | 288 rect->set_width(updated_rects[i].width()); |
286 rect->set_height(updated_rects[i].height()); | 289 rect->set_height(updated_rects[i].height()); |
287 } | 290 } |
288 | 291 |
289 data_available_callback->Run(message); | 292 data_available_callback->Run(message); |
290 delete data_available_callback; | 293 delete data_available_callback; |
291 } | 294 } |
292 | 295 |
293 } // namespace remoting | 296 } // namespace remoting |
OLD | NEW |