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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/video/capture/screen/differ_block.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/capture/screen/differ_block.cc
diff --git a/media/video/capture/screen/differ_block.cc b/media/video/capture/screen/differ_block.cc
index d263ac4312ad5e2ddbd9b5cea9dcd85e180b6def..5c3c93a93d7dbf8745dac54d78733db4e4d5ead6 100644
--- a/media/video/capture/screen/differ_block.cc
+++ b/media/video/capture/screen/differ_block.cc
@@ -9,6 +9,8 @@
#include "media/video/capture/screen/differ_block_sse2.h"
namespace media {
+typedef int (*BlockDifferenceProc)(const uint8*, const uint8*, int);
+static BlockDifferenceProc g_block_difference_proc_ = NULL;
int BlockDifference_C(const uint8* image1, const uint8* image2, int stride) {
int width_bytes = kBlockSize * kBytesPerPixel;
@@ -22,28 +24,28 @@ int BlockDifference_C(const uint8* image1, const uint8* image2, int stride) {
return 0;
}
-int BlockDifference(const uint8* image1, const uint8* image2, int stride) {
- static int (*diff_proc)(const uint8*, const uint8*, int) = NULL;
+void InitializeCPUSpecificBlockDifference() {
+ g_block_difference_proc_ = &BlockDifference_C;
- if (!diff_proc) {
-#if defined(ARCH_CPU_ARM_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY)
- // For ARM and MIPS processors, always use C version.
- // TODO(hclam): Implement a NEON version.
- diff_proc = &BlockDifference_C;
+#if defined(ARCH_CPU_X86_FAMILY)
+#if defined(__SSE2__)
+ const bool kHasSSE2 = true;
#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;
- }
+ const bool kHasSSE2 = base::CPU().has_sse2();
#endif
+
+ if (kHasSSE2) {
+ if (kBlockSize == 32) {
+ g_block_difference_proc_ = &BlockDifference_SSE2_W32;
+ } else if (kBlockSize == 16) {
+ g_block_difference_proc_ = &BlockDifference_SSE2_W16;
+ }
}
+#endif
+}
- return diff_proc(image1, image2, stride);
+int BlockDifference(const uint8* image1, const uint8* image2, int stride) {
+ return g_block_difference_proc_(image1, image2, stride);
}
} // namespace media
« 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