Index: cc/test/fake_picture_cache.cc |
diff --git a/cc/test/fake_picture_cache.cc b/cc/test/fake_picture_cache.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0e2ac8cbecf948d685a868506bb34f17ab5463a4 |
--- /dev/null |
+++ b/cc/test/fake_picture_cache.cc |
@@ -0,0 +1,91 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/test/fake_picture_cache.h" |
+ |
+#include <map> |
+#include <memory> |
+ |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "cc/proto/picture_cache.h" |
+#include "third_party/skia/include/core/SkData.h" |
+#include "third_party/skia/include/core/SkPicture.h" |
+#include "third_party/skia/include/core/SkRefCnt.h" |
+#include "third_party/skia/include/core/SkStream.h" |
+ |
+namespace cc { |
+namespace { |
+ |
+sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) { |
+ SkDynamicMemoryWStream write_stream; |
+ picture->serialize(&write_stream, nullptr); |
+ DCHECK_GT(write_stream.bytesWritten(), 0u); |
+ |
+ sk_sp<SkData> data(write_stream.copyToData()); |
+ |
+ SkMemoryStream read_stream(data); |
+ return SkPicture::MakeFromStream(&read_stream, nullptr); |
+} |
+ |
+} // namespace |
+ |
+FakePictureCacheModel::FakePictureCacheModel() {} |
+ |
+FakePictureCacheModel::~FakePictureCacheModel() {} |
+ |
+void FakePictureCacheModel::AddPicture(const SkPicture* picture) { |
+ sk_sp<SkPicture> picture_copy = CopySkPicture(picture); |
+ pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy)); |
+} |
+ |
+sk_sp<const SkPicture> FakePictureCacheModel::GetPicture(uint32_t unique_id) { |
+ if (pictures_.find(unique_id) == pictures_.end()) |
+ return nullptr; |
+ |
+ return pictures_.find(unique_id)->second; |
+} |
+ |
+FakeEnginePictureCache::FakeEnginePictureCache(FakePictureCacheModel* model) |
+ : model_(model) {} |
+ |
+FakeEnginePictureCache::~FakeEnginePictureCache() {} |
+ |
+void FakeEnginePictureCache::MarkPictureForUnregistration( |
+ const SkPicture* picture) {} |
+ |
+void FakeEnginePictureCache::MarkPictureForRegistration( |
+ const SkPicture* picture) { |
+ if (model_) |
+ model_->AddPicture(picture); |
+} |
+ |
+PictureCacheUpdate FakeEnginePictureCache::CalculateCacheUpdateAndFlush() { |
+ return PictureCacheUpdate(); |
+} |
+ |
+FakeClientPictureCache::FakeClientPictureCache(FakePictureCacheModel* model) |
+ : model_(model) {} |
+ |
+FakeClientPictureCache::~FakeClientPictureCache() {} |
+ |
+sk_sp<const SkPicture> FakeClientPictureCache::GetPicture(uint32_t unique_id) { |
+ if (!model_) |
+ return nullptr; |
+ |
+ return model_->GetPicture(unique_id); |
+} |
+ |
+void FakeClientPictureCache::ApplyCacheUpdate( |
+ const PictureCacheUpdate& cache_update) {} |
+ |
+void FakeClientPictureCache::Flush() {} |
+ |
+void FakeClientPictureCache::MarkPictureForUnregistration( |
+ uint32_t engine_picture_id) {} |
+ |
+void FakeClientPictureCache::MarkPictureForRegistration( |
+ uint32_t engine_picture_id) {} |
+ |
+} // namespace cc |