Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Side by Side Diff: media/video/capture/screen/differ_block.cc

Issue 16252006: Refactor BlockDifference() to use MediaInitializer(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android. Cleanup checks. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/video/capture/screen/differ_block.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/video/capture/screen/differ_block.h" 5 #include "media/video/capture/screen/differ_block.h"
6 6
7 #include "base/cpu.h" 7 #include "base/cpu.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "media/video/capture/screen/differ_block_sse2.h" 9 #include "media/video/capture/screen/differ_block_sse2.h"
10 10
11 namespace media { 11 namespace media {
12 typedef int (*BlockDifferenceProc)(const uint8*, const uint8*, int);
13 static BlockDifferenceProc g_block_difference_proc_ = NULL;
12 14
13 int BlockDifference_C(const uint8* image1, const uint8* image2, int stride) { 15 int BlockDifference_C(const uint8* image1, const uint8* image2, int stride) {
14 int width_bytes = kBlockSize * kBytesPerPixel; 16 int width_bytes = kBlockSize * kBytesPerPixel;
15 17
16 for (int y = 0; y < kBlockSize; y++) { 18 for (int y = 0; y < kBlockSize; y++) {
17 if (memcmp(image1, image2, width_bytes) != 0) 19 if (memcmp(image1, image2, width_bytes) != 0)
18 return 1; 20 return 1;
19 image1 += stride; 21 image1 += stride;
20 image2 += stride; 22 image2 += stride;
21 } 23 }
22 return 0; 24 return 0;
23 } 25 }
24 26
27 void InitializeCPUSpecificBlockDifference() {
28 g_block_difference_proc_ = &BlockDifference_C;
29
30 #if defined(ARCH_CPU_X86_FAMILY)
31 #if defined(__SSE2__)
32 const bool kHasSSE2 = true;
33 #else
34 const bool kHasSSE2 = base::CPU().has_sse2();
35 #endif
36
37 if (kHasSSE2) {
38 if (kBlockSize == 32) {
39 g_block_difference_proc_ = &BlockDifference_SSE2_W32;
40 } else if (kBlockSize == 16) {
41 g_block_difference_proc_ = &BlockDifference_SSE2_W16;
42 }
43 }
44 #endif
45 }
46
25 int BlockDifference(const uint8* image1, const uint8* image2, int stride) { 47 int BlockDifference(const uint8* image1, const uint8* image2, int stride) {
26 static int (*diff_proc)(const uint8*, const uint8*, int) = NULL; 48 return g_block_difference_proc_(image1, image2, stride);
27
28 if (!diff_proc) {
29 #if defined(ARCH_CPU_ARM_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY)
30 // For ARM and MIPS processors, always use C version.
31 // TODO(hclam): Implement a NEON version.
32 diff_proc = &BlockDifference_C;
33 #else
34 base::CPU cpu;
35 // For x86 processors, check if SSE2 is supported.
36 if (cpu.has_sse2() && kBlockSize == 32) {
37 diff_proc = &BlockDifference_SSE2_W32;
38 } else if (cpu.has_sse2() && kBlockSize == 16) {
39 diff_proc = &BlockDifference_SSE2_W16;
40 } else {
41 diff_proc = &BlockDifference_C;
42 }
43 #endif
44 }
45
46 return diff_proc(image1, image2, stride);
47 } 49 }
48 50
49 } // namespace media 51 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/screen/differ_block.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698