OLD | NEW |
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" | |
12 #include "SkDevice.h" | 11 #include "SkDevice.h" |
13 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
14 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
15 #include "SkRect.h" | 14 #include "SkRect.h" |
16 #include "SkTDynamicHash.h" | 15 #include "SkTDynamicHash.h" |
17 #include "SkValidationUtils.h" | 16 #include "SkValidationUtils.h" |
18 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
19 #include "GrContext.h" | 18 #include "GrContext.h" |
20 #include "SkGrPixelRef.h" | 19 #include "SkGrPixelRef.h" |
21 #include "SkGr.h" | 20 #include "SkGr.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 GrUnlockAndUnrefCachedBitmapTexture(resultTex); | 327 GrUnlockAndUnrefCachedBitmapTexture(resultTex); |
329 } | 328 } |
330 return true; | 329 return true; |
331 } else { | 330 } else { |
332 return false; | 331 return false; |
333 } | 332 } |
334 } | 333 } |
335 } | 334 } |
336 #endif | 335 #endif |
337 | 336 |
| 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 |
338 class CacheImpl : public SkImageFilter::Cache { | 362 class CacheImpl : public SkImageFilter::Cache { |
339 public: | 363 public: |
340 explicit CacheImpl(int minChildren) : fMinChildren(minChildren) { | 364 explicit CacheImpl(int minChildren) : fMinChildren(minChildren) { |
341 SkASSERT(fMinChildren <= 2); | 365 SkASSERT(fMinChildren <= 2); |
342 } | 366 } |
343 | 367 |
344 virtual ~CacheImpl(); | 368 virtual ~CacheImpl(); |
345 bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OV
ERRIDE; | 369 bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OV
ERRIDE; |
346 void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& o
ffset) SK_OVERRIDE; | 370 void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& o
ffset) SK_OVERRIDE; |
347 void remove(const SkImageFilter* key) SK_OVERRIDE; | 371 void remove(const SkImageFilter* key) SK_OVERRIDE; |
348 private: | 372 private: |
349 typedef const SkImageFilter* Key; | 373 typedef const SkImageFilter* Key; |
350 struct Value { | 374 struct Value { |
351 Value(Key key, const SkBitmap& bitmap, const SkIPoint& offset) | 375 Value(Key key, const SkBitmap& bitmap, const SkIPoint& offset) |
352 : fKey(key), fBitmap(bitmap), fOffset(offset) {} | 376 : fKey(key), fBitmap(bitmap), fOffset(offset) {} |
353 Key fKey; | 377 Key fKey; |
354 SkBitmap fBitmap; | 378 SkBitmap fBitmap; |
355 SkIPoint fOffset; | 379 SkIPoint fOffset; |
356 static const Key& GetKey(const Value& v) { | 380 static const Key& GetKey(const Value& v) { |
357 return v.fKey; | 381 return v.fKey; |
358 } | 382 } |
359 static uint32_t Hash(Key key) { | 383 static uint32_t Hash(Key key) { |
360 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key),
sizeof(Key)); | 384 return compute_hash(reinterpret_cast<const uint32_t*>(&key), sizeof(
Key) / sizeof(uint32_t)); |
361 } | 385 } |
362 }; | 386 }; |
363 SkTDynamicHash<Value, Key> fData; | 387 SkTDynamicHash<Value, Key> fData; |
364 int fMinChildren; | 388 int fMinChildren; |
365 }; | 389 }; |
366 | 390 |
367 bool CacheImpl::get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset
) { | 391 bool CacheImpl::get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset
) { |
368 Value* v = fData.find(key); | 392 Value* v = fData.find(key); |
369 if (v) { | 393 if (v) { |
370 *result = v->fBitmap; | 394 *result = v->fBitmap; |
(...skipping 26 matching lines...) Expand all Loading... |
397 | 421 |
398 CacheImpl::~CacheImpl() { | 422 CacheImpl::~CacheImpl() { |
399 SkTDynamicHash<Value, Key>::Iter iter(&fData); | 423 SkTDynamicHash<Value, Key>::Iter iter(&fData); |
400 | 424 |
401 while (!iter.done()) { | 425 while (!iter.done()) { |
402 Value* v = &*iter; | 426 Value* v = &*iter; |
403 ++iter; | 427 ++iter; |
404 delete v; | 428 delete v; |
405 } | 429 } |
406 } | 430 } |
OLD | NEW |