OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/test/fake_picture_cache.h" |
| 6 |
| 7 #include <map> |
| 8 #include <memory> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "cc/proto/picture_cache.h" |
| 13 #include "third_party/skia/include/core/SkData.h" |
| 14 #include "third_party/skia/include/core/SkPicture.h" |
| 15 #include "third_party/skia/include/core/SkRefCnt.h" |
| 16 #include "third_party/skia/include/core/SkStream.h" |
| 17 |
| 18 namespace cc { |
| 19 namespace { |
| 20 |
| 21 sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) { |
| 22 SkDynamicMemoryWStream write_stream; |
| 23 picture->serialize(&write_stream, nullptr); |
| 24 if (write_stream.bytesWritten() <= 0) |
| 25 return nullptr; |
| 26 |
| 27 sk_sp<SkData> data(write_stream.copyToData()); |
| 28 |
| 29 SkMemoryStream read_stream(data); |
| 30 return SkPicture::MakeFromStream(&read_stream, nullptr); |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 35 FakePictureCacheModel::FakePictureCacheModel() {} |
| 36 |
| 37 FakePictureCacheModel::~FakePictureCacheModel() {} |
| 38 |
| 39 void FakePictureCacheModel::AddPicture(const SkPicture* picture) { |
| 40 sk_sp<SkPicture> picture_copy = CopySkPicture(picture); |
| 41 pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy)); |
| 42 } |
| 43 |
| 44 sk_sp<const SkPicture> FakePictureCacheModel::GetPicture(uint32_t unique_id) { |
| 45 if (pictures_.find(unique_id) == pictures_.end()) |
| 46 return nullptr; |
| 47 |
| 48 return pictures_.find(unique_id)->second; |
| 49 } |
| 50 |
| 51 FakeEnginePictureCache::FakeEnginePictureCache(FakePictureCacheModel* model) |
| 52 : model_(model) {} |
| 53 |
| 54 FakeEnginePictureCache::~FakeEnginePictureCache() {} |
| 55 |
| 56 void FakeEnginePictureCache::MarkPictureForUnregistration( |
| 57 const SkPicture* picture) {} |
| 58 |
| 59 void FakeEnginePictureCache::MarkPictureForRegistration( |
| 60 const SkPicture* picture) { |
| 61 if (model_) |
| 62 model_->AddPicture(picture); |
| 63 } |
| 64 |
| 65 PictureCacheUpdate FakeEnginePictureCache::CalculateCacheUpdateAndFlush() { |
| 66 return PictureCacheUpdate(); |
| 67 } |
| 68 |
| 69 FakeClientPictureCache::FakeClientPictureCache(FakePictureCacheModel* model) |
| 70 : model_(model) {} |
| 71 |
| 72 FakeClientPictureCache::~FakeClientPictureCache() {} |
| 73 |
| 74 sk_sp<const SkPicture> FakeClientPictureCache::GetPicture(uint32_t unique_id) { |
| 75 if (!model_) |
| 76 return nullptr; |
| 77 |
| 78 return model_->GetPicture(unique_id); |
| 79 } |
| 80 |
| 81 void FakeClientPictureCache::ApplyCacheUpdate( |
| 82 const PictureCacheUpdate& cache_update) {} |
| 83 |
| 84 void FakeClientPictureCache::Flush() {} |
| 85 |
| 86 void FakeClientPictureCache::MarkPictureForUnregistration( |
| 87 uint32_t engine_picture_id) {} |
| 88 |
| 89 void FakeClientPictureCache::MarkPictureForRegistration( |
| 90 uint32_t engine_picture_id) {} |
| 91 |
| 92 } // namespace cc |
OLD | NEW |