You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "modules/desktop_capture/differ_block.h"
  11. #include <string.h>
  12. #include "modules/desktop_capture/differ_vector_sse2.h"
  13. #include "rtc_base/system/arch.h"
  14. #include "system_wrappers/include/cpu_features_wrapper.h"
  15. namespace webrtc {
  16. namespace {
  17. bool VectorDifference_C(const uint8_t* image1, const uint8_t* image2) {
  18. return memcmp(image1, image2, kBlockSize * kBytesPerPixel) != 0;
  19. }
  20. } // namespace
  21. bool VectorDifference(const uint8_t* image1, const uint8_t* image2) {
  22. static bool (*diff_proc)(const uint8_t*, const uint8_t*) = nullptr;
  23. if (!diff_proc) {
  24. #if defined(WEBRTC_ARCH_ARM_FAMILY) || defined(WEBRTC_ARCH_MIPS_FAMILY)
  25. // For ARM and MIPS processors, always use C version.
  26. // TODO(hclam): Implement a NEON version.
  27. diff_proc = &VectorDifference_C;
  28. #else
  29. bool have_sse2 = WebRtc_GetCPUInfo(kSSE2) != 0;
  30. // For x86 processors, check if SSE2 is supported.
  31. if (have_sse2 && kBlockSize == 32) {
  32. diff_proc = &VectorDifference_SSE2_W32;
  33. } else if (have_sse2 && kBlockSize == 16) {
  34. diff_proc = &VectorDifference_SSE2_W16;
  35. } else {
  36. diff_proc = &VectorDifference_C;
  37. }
  38. #endif
  39. }
  40. return diff_proc(image1, image2);
  41. }
  42. bool BlockDifference(const uint8_t* image1,
  43. const uint8_t* image2,
  44. int height,
  45. int stride) {
  46. for (int i = 0; i < height; i++) {
  47. if (VectorDifference(image1, image2)) {
  48. return true;
  49. }
  50. image1 += stride;
  51. image2 += stride;
  52. }
  53. return false;
  54. }
  55. bool BlockDifference(const uint8_t* image1, const uint8_t* image2, int stride) {
  56. return BlockDifference(image1, image2, kBlockSize, stride);
  57. }
  58. } // namespace webrtc