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

Side by Side Diff: src/core/SkImageFilter.cpp

Issue 376183004: Slim Skia down to just one murmur3 implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix types Created 6 years, 5 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
« no previous file with comments | « src/core/SkChecksum.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 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkImageFilter.h" 8 #include "SkImageFilter.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkChecksum.h"
11 #include "SkDevice.h" 12 #include "SkDevice.h"
12 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h" 14 #include "SkWriteBuffer.h"
14 #include "SkRect.h" 15 #include "SkRect.h"
15 #include "SkTDynamicHash.h" 16 #include "SkTDynamicHash.h"
16 #include "SkValidationUtils.h" 17 #include "SkValidationUtils.h"
17 #if SK_SUPPORT_GPU 18 #if SK_SUPPORT_GPU
18 #include "GrContext.h" 19 #include "GrContext.h"
19 #include "SkGrPixelRef.h" 20 #include "SkGrPixelRef.h"
20 #include "SkGr.h" 21 #include "SkGr.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 GrUnlockAndUnrefCachedBitmapTexture(resultTex); 328 GrUnlockAndUnrefCachedBitmapTexture(resultTex);
328 } 329 }
329 return true; 330 return true;
330 } else { 331 } else {
331 return false; 332 return false;
332 } 333 }
333 } 334 }
334 } 335 }
335 #endif 336 #endif
336 337
337 static uint32_t compute_hash(const uint32_t* data, int count) {
338 uint32_t hash = 0;
339
340 for (int i = 0; i < count; ++i) {
341 uint32_t k = data[i];
342 k *= 0xcc9e2d51;
343 k = (k << 15) | (k >> 17);
344 k *= 0x1b873593;
345
346 hash ^= k;
347 hash = (hash << 13) | (hash >> 19);
348 hash *= 5;
349 hash += 0xe6546b64;
350 }
351
352 // hash ^= size;
353 hash ^= hash >> 16;
354 hash *= 0x85ebca6b;
355 hash ^= hash >> 13;
356 hash *= 0xc2b2ae35;
357 hash ^= hash >> 16;
358
359 return hash;
360 }
361
362 class CacheImpl : public SkImageFilter::Cache { 338 class CacheImpl : public SkImageFilter::Cache {
363 public: 339 public:
364 explicit CacheImpl(int minChildren) : fMinChildren(minChildren) { 340 explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {
365 SkASSERT(fMinChildren <= 2); 341 SkASSERT(fMinChildren <= 2);
366 } 342 }
367 343
368 virtual ~CacheImpl(); 344 virtual ~CacheImpl();
369 bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OV ERRIDE; 345 bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OV ERRIDE;
370 void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& o ffset) SK_OVERRIDE; 346 void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& o ffset) SK_OVERRIDE;
371 void remove(const SkImageFilter* key) SK_OVERRIDE; 347 void remove(const SkImageFilter* key) SK_OVERRIDE;
372 private: 348 private:
373 typedef const SkImageFilter* Key; 349 typedef const SkImageFilter* Key;
374 struct Value { 350 struct Value {
375 Value(Key key, const SkBitmap& bitmap, const SkIPoint& offset) 351 Value(Key key, const SkBitmap& bitmap, const SkIPoint& offset)
376 : fKey(key), fBitmap(bitmap), fOffset(offset) {} 352 : fKey(key), fBitmap(bitmap), fOffset(offset) {}
377 Key fKey; 353 Key fKey;
378 SkBitmap fBitmap; 354 SkBitmap fBitmap;
379 SkIPoint fOffset; 355 SkIPoint fOffset;
380 static const Key& GetKey(const Value& v) { 356 static const Key& GetKey(const Value& v) {
381 return v.fKey; 357 return v.fKey;
382 } 358 }
383 static uint32_t Hash(Key key) { 359 static uint32_t Hash(Key key) {
384 return compute_hash(reinterpret_cast<const uint32_t*>(&key), sizeof( Key) / sizeof(uint32_t)); 360 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
385 } 361 }
386 }; 362 };
387 SkTDynamicHash<Value, Key> fData; 363 SkTDynamicHash<Value, Key> fData;
388 int fMinChildren; 364 int fMinChildren;
389 }; 365 };
390 366
391 bool CacheImpl::get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset ) { 367 bool CacheImpl::get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset ) {
392 Value* v = fData.find(key); 368 Value* v = fData.find(key);
393 if (v) { 369 if (v) {
394 *result = v->fBitmap; 370 *result = v->fBitmap;
(...skipping 26 matching lines...) Expand all
421 397
422 CacheImpl::~CacheImpl() { 398 CacheImpl::~CacheImpl() {
423 SkTDynamicHash<Value, Key>::Iter iter(&fData); 399 SkTDynamicHash<Value, Key>::Iter iter(&fData);
424 400
425 while (!iter.done()) { 401 while (!iter.done()) {
426 Value* v = &*iter; 402 Value* v = &*iter;
427 ++iter; 403 ++iter;
428 delete v; 404 delete v;
429 } 405 }
430 } 406 }
OLDNEW
« no previous file with comments | « src/core/SkChecksum.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698