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 DCHECK_GT(write_stream.bytesWritten(), 0u); |
| 25 |
| 26 sk_sp<SkData> data(write_stream.copyToData()); |
| 27 |
| 28 SkMemoryStream read_stream(data); |
| 29 return SkPicture::MakeFromStream(&read_stream, nullptr); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
| 34 FakePictureCacheModel::FakePictureCacheModel() {} |
| 35 |
| 36 FakePictureCacheModel::~FakePictureCacheModel() {} |
| 37 |
| 38 void FakePictureCacheModel::AddPicture(const SkPicture* picture) { |
| 39 sk_sp<SkPicture> picture_copy = CopySkPicture(picture); |
| 40 pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy)); |
| 41 } |
| 42 |
| 43 sk_sp<const SkPicture> FakePictureCacheModel::GetPicture(uint32_t unique_id) { |
| 44 if (pictures_.find(unique_id) == pictures_.end()) |
| 45 return nullptr; |
| 46 |
| 47 return pictures_.find(unique_id)->second; |
| 48 } |
| 49 |
| 50 FakeEnginePictureCache::FakeEnginePictureCache(FakePictureCacheModel* model) |
| 51 : model_(model) {} |
| 52 |
| 53 FakeEnginePictureCache::~FakeEnginePictureCache() {} |
| 54 |
| 55 void FakeEnginePictureCache::MarkPictureForUnregistration( |
| 56 const SkPicture* picture) {} |
| 57 |
| 58 void FakeEnginePictureCache::MarkPictureForRegistration( |
| 59 const SkPicture* picture) { |
| 60 if (model_) |
| 61 model_->AddPicture(picture); |
| 62 } |
| 63 |
| 64 PictureCacheUpdate FakeEnginePictureCache::CalculateCacheUpdateAndFlush() { |
| 65 return PictureCacheUpdate(); |
| 66 } |
| 67 |
| 68 FakeClientPictureCache::FakeClientPictureCache(FakePictureCacheModel* model) |
| 69 : model_(model) {} |
| 70 |
| 71 FakeClientPictureCache::~FakeClientPictureCache() {} |
| 72 |
| 73 sk_sp<const SkPicture> FakeClientPictureCache::GetPicture(uint32_t unique_id) { |
| 74 if (!model_) |
| 75 return nullptr; |
| 76 |
| 77 return model_->GetPicture(unique_id); |
| 78 } |
| 79 |
| 80 void FakeClientPictureCache::ApplyCacheUpdate( |
| 81 const PictureCacheUpdate& cache_update) {} |
| 82 |
| 83 void FakeClientPictureCache::Flush() {} |
| 84 |
| 85 void FakeClientPictureCache::MarkPictureForUnregistration( |
| 86 uint32_t engine_picture_id) {} |
| 87 |
| 88 void FakeClientPictureCache::MarkPictureForRegistration( |
| 89 uint32_t engine_picture_id) {} |
| 90 |
| 91 } // namespace cc |
OLD | NEW |