tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

differ_block.cc (2152B)


      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 
     11 #include "modules/desktop_capture/differ_block.h"
     12 
     13 #include <cstdint>
     14 #include <cstring>
     15 
     16 #include "rtc_base/cpu_info.h"
     17 
     18 // Defines WEBRTC_ARCH_X86_FAMILY, used below.
     19 #include "rtc_base/system/arch.h"
     20 #if defined(WEBRTC_ARCH_X86_FAMILY)
     21 #include "modules/desktop_capture/differ_vector_sse2.h"
     22 #endif
     23 
     24 namespace webrtc {
     25 
     26 namespace {
     27 
     28 bool VectorDifference_C(const uint8_t* image1, const uint8_t* image2) {
     29  return memcmp(image1, image2, kBlockSize * kBytesPerPixel) != 0;
     30 }
     31 
     32 }  // namespace
     33 
     34 bool VectorDifference(const uint8_t* image1, const uint8_t* image2) {
     35  static bool (*diff_proc)(const uint8_t*, const uint8_t*) = nullptr;
     36 
     37  if (!diff_proc) {
     38 #if defined(WEBRTC_ARCH_X86_FAMILY)
     39    bool have_sse2 = cpu_info::Supports(cpu_info::ISA::kSSE2);
     40    // For x86 processors, check if SSE2 is supported.
     41    if (have_sse2 && kBlockSize == 32) {
     42      diff_proc = &VectorDifference_SSE2_W32;
     43    } else if (have_sse2 && kBlockSize == 16) {
     44      diff_proc = &VectorDifference_SSE2_W16;
     45    } else {
     46      diff_proc = &VectorDifference_C;
     47    }
     48 #else
     49    // For other processors, always use C version.
     50    // TODO(hclam): Implement a NEON version.
     51    diff_proc = &VectorDifference_C;
     52 #endif
     53  }
     54 
     55  return diff_proc(image1, image2);
     56 }
     57 
     58 bool BlockDifference(const uint8_t* image1,
     59                     const uint8_t* image2,
     60                     int height,
     61                     int stride) {
     62  for (int i = 0; i < height; i++) {
     63    if (VectorDifference(image1, image2)) {
     64      return true;
     65    }
     66    image1 += stride;
     67    image2 += stride;
     68  }
     69  return false;
     70 }
     71 
     72 bool BlockDifference(const uint8_t* image1, const uint8_t* image2, int stride) {
     73  return BlockDifference(image1, image2, kBlockSize, stride);
     74 }
     75 
     76 }  // namespace webrtc