Chromium Code Reviews| Index: blimp/client/feature/compositor/blimp_client_picture_cache.cc |
| diff --git a/blimp/client/feature/compositor/blimp_client_picture_cache.cc b/blimp/client/feature/compositor/blimp_client_picture_cache.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a117e39955da5a11d79bcba17f10a060991b68d2 |
| --- /dev/null |
| +++ b/blimp/client/feature/compositor/blimp_client_picture_cache.cc |
| @@ -0,0 +1,84 @@ |
| +// 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 "blimp/client/feature/compositor/blimp_client_picture_cache.h" |
| + |
| +#include <stdint.h> |
| +#include <map> |
| +#include <memory> |
| + |
| +#include "base/logging.h" |
| +#include "blimp/common/compositor/blimp_picture_cache_registry.h" |
| +#include "cc/proto/picture_cache.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 blimp { |
| +namespace client { |
| + |
| +BlimpClientPictureCache::BlimpClientPictureCache( |
| + SkPicture::InstallPixelRefProc pixel_deserializer) |
| + : pixel_deserializer_(pixel_deserializer) {} |
| + |
| +BlimpClientPictureCache::~BlimpClientPictureCache() {} |
| + |
| +sk_sp<const SkPicture> BlimpClientPictureCache::GetPicture( |
| + uint32_t engine_picture_id) { |
| + if (pictures_.find(engine_picture_id) == pictures_.end()) { |
| + NOTREACHED() << "Failed to find picture with id = " << engine_picture_id; |
|
vmpstr
2016/05/25 01:54:05
Remind me what the policy on error handling is? In
nyquist
2016/05/26 01:08:09
Done.
|
| + return nullptr; |
| + } |
| + |
| + return pictures_.find(engine_picture_id)->second; |
| +} |
| + |
| +void BlimpClientPictureCache::ApplyCacheUpdate( |
| + const cc::PictureCacheUpdate& cache_update) { |
| + for (const cc::PictureData& picture_data : cache_update) { |
| + sk_sp<SkPicture> deserialized_picture = DeserializePicture(picture_data); |
| + DCHECK(pictures_.find(picture_data.unique_id) == pictures_.end()); |
| + pictures_.insert( |
| + std::make_pair(picture_data.unique_id, deserialized_picture)); |
|
vmpstr
2016/05/25 01:54:05
How does unique_id related to SkPicture::uniqueID(
nyquist
2016/05/26 01:08:09
It's the SkPicture::uniqueID() that the engine use
|
| + last_added_.insert(picture_data.unique_id); |
| + } |
| +} |
| + |
| +void BlimpClientPictureCache::Flush() { |
| + std::set<uint32_t> added; |
| + std::set<uint32_t> removed; |
| + registry_.Commit(&added, &removed); |
| + |
| + // Verify that the incoming cache update matches the new items. |
| + DCHECK(added == last_added_); |
| + last_added_.clear(); |
| + |
| + for (const auto& it : removed) { |
| + auto entry = pictures_.find(it); |
| + if (entry == pictures_.end()) { |
| + NOTREACHED() << "PictureMap does not contain entry " << it; |
| + continue; |
| + } |
| + pictures_.erase(entry); |
| + } |
| +} |
| + |
| +sk_sp<SkPicture> BlimpClientPictureCache::DeserializePicture( |
| + const cc::PictureData& picture_data) { |
| + SkMemoryStream stream(picture_data.data); |
| + return SkPicture::MakeFromStream(&stream, pixel_deserializer_); |
| +} |
| + |
| +void BlimpClientPictureCache::MarkPictureForUnregistration( |
| + uint32_t engine_picture_id) { |
| + registry_.Unstage(engine_picture_id); |
|
vmpstr
2016/05/25 01:54:05
Technically this is stage for removal, not unstage
nyquist
2016/05/26 01:08:09
Done.
|
| +} |
| + |
| +void BlimpClientPictureCache::MarkPictureForRegistration( |
| + uint32_t engine_picture_id) { |
| + registry_.Stage(engine_picture_id); |
| +} |
| + |
| +} // namespace client |
| +} // namespace blimp |