| 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..26eb378d2c5a80f698697fb6d9a735a1be24ed62
|
| --- /dev/null
|
| +++ b/cc/test/fake_picture_cache.cc
|
| @@ -0,0 +1,92 @@
|
| +// 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);
|
| + if (write_stream.bytesWritten() <= 0)
|
| + return nullptr;
|
| +
|
| + 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
|
|
|