summaryrefslogtreecommitdiffstats
path: root/media/video/capture/screen/differ_block.cc
blob: 4a1b44d8e8df013c05bdfa2564674eaf91e90801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/video/capture/screen/differ_block.h"

#include "base/cpu.h"
#include "build/build_config.h"
#include "media/video/capture/screen/differ_block_sse2.h"

namespace media {

int BlockDifference_C(const uint8* image1, const uint8* image2, int stride) {
  int width_bytes = kBlockSize * kBytesPerPixel;

  for (int y = 0; y < kBlockSize; y++) {
    if (memcmp(image1, image2, width_bytes) != 0)
      return 1;
    image1 += stride;
    image2 += stride;
  }
  return 0;
}

int BlockDifference(const uint8* image1, const uint8* image2, int stride) {
  static int (*diff_proc)(const uint8*, const uint8*, int) = NULL;

  if (!diff_proc) {
#if defined(ARCH_CPU_ARM_FAMILY)
    // For ARM processors, always use C version.
    // TODO(hclam): Implement a NEON version.
    diff_proc = &BlockDifference_C;
#else
    base::CPU cpu;
    // For x86 processors, check if SSE2 is supported.
    if (cpu.has_sse2() && kBlockSize == 32) {
      diff_proc = &BlockDifference_SSE2_W32;
    } else if (cpu.has_sse2() && kBlockSize == 16) {
      diff_proc = &BlockDifference_SSE2_W16;
    } else {
      diff_proc = &BlockDifference_C;
    }
#endif
  }

  return diff_proc(image1, image2, stride);
}

}  // namespace media