Chromium Code Reviews| Index: webrtc/modules/desktop_capture/test_utils.cc |
| diff --git a/webrtc/modules/desktop_capture/test_utils.cc b/webrtc/modules/desktop_capture/test_utils.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f9a45814d281290f21f08bbfcc4b96641397df71 |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/test_utils.cc |
| @@ -0,0 +1,64 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/desktop_capture/test_utils.h" |
| + |
| +#include <string.h> |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace webrtc { |
| + |
| +void PaintDesktopFrame(DesktopFrame* frame, |
| + DesktopVector pos, |
| + RgbaColor color) { |
| + RTC_DCHECK(frame); |
| + RTC_DCHECK(DesktopRect::MakeSize(frame->size()).Contains(pos)); |
| + *reinterpret_cast<uint32_t*>(frame->GetFrameDataAtPos(pos)) = |
| + color.ToUInt32(); |
| +} |
| + |
| +void ClearDesktopFrame(DesktopFrame* frame) { |
| + RTC_DCHECK(frame); |
| + memset(frame->data(), 0, frame->stride() * frame->size().height()); |
| +} |
| + |
| +bool DesktopFrameDataEquals(const DesktopFrame& left, |
| + const DesktopFrame& right) { |
| + if (!left.size().equals(right.size())) { |
| + return false; |
| + } |
| + if (left.stride() == right.stride() && |
| + left.stride() == DesktopFrame::kBytesPerPixel * left.size().width()) { |
| + return memcmp(left.data(), right.data(), |
| + left.stride() * left.size().height()) == 0; |
| + } |
| + |
| + const uint8_t* my_array = left.data(); |
| + const uint8_t* right_array = right.data(); |
| + for (int i = 0; i < left.size().height(); i++) { |
| + const uint8_t* my_this_line = my_array; |
| + const uint8_t* right_this_line = right_array; |
| + for (int j = 0; j < left.size().width(); j++) { |
| + if (memcmp(my_this_line, right_this_line, DesktopFrame::kBytesPerPixel) != |
|
Sergey Ulanov
2016/11/15 20:50:23
Why not compare the whole line, instead of compari
Hzj_jie
2016/11/16 01:18:33
Done.
|
| + 0) { |
| + return false; |
| + } |
| + my_this_line += DesktopFrame::kBytesPerPixel; |
| + right_this_line += DesktopFrame::kBytesPerPixel; |
| + } |
| + my_array += left.stride(); |
| + right_array += right.stride(); |
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace webrtc |