Chromium Code Reviews| 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 "blimp/client/feature/compositor/blimp_client_picture_cache.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "blimp/common/compositor/blimp_picture_cache_registry.h" | |
| 13 #include "cc/proto/picture_cache.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 blimp { | |
| 19 namespace client { | |
| 20 | |
| 21 BlimpClientPictureCache::BlimpClientPictureCache( | |
| 22 SkPicture::InstallPixelRefProc pixel_deserializer) | |
| 23 : pixel_deserializer_(pixel_deserializer) {} | |
| 24 | |
| 25 BlimpClientPictureCache::~BlimpClientPictureCache() {} | |
| 26 | |
| 27 sk_sp<const SkPicture> BlimpClientPictureCache::GetPicture( | |
| 28 uint32_t engine_picture_id) { | |
| 29 if (pictures_.find(engine_picture_id) == pictures_.end()) { | |
| 30 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.
| |
| 31 return nullptr; | |
| 32 } | |
| 33 | |
| 34 return pictures_.find(engine_picture_id)->second; | |
| 35 } | |
| 36 | |
| 37 void BlimpClientPictureCache::ApplyCacheUpdate( | |
| 38 const cc::PictureCacheUpdate& cache_update) { | |
| 39 for (const cc::PictureData& picture_data : cache_update) { | |
| 40 sk_sp<SkPicture> deserialized_picture = DeserializePicture(picture_data); | |
| 41 DCHECK(pictures_.find(picture_data.unique_id) == pictures_.end()); | |
| 42 pictures_.insert( | |
| 43 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
| |
| 44 last_added_.insert(picture_data.unique_id); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 void BlimpClientPictureCache::Flush() { | |
| 49 std::set<uint32_t> added; | |
| 50 std::set<uint32_t> removed; | |
| 51 registry_.Commit(&added, &removed); | |
| 52 | |
| 53 // Verify that the incoming cache update matches the new items. | |
| 54 DCHECK(added == last_added_); | |
| 55 last_added_.clear(); | |
| 56 | |
| 57 for (const auto& it : removed) { | |
| 58 auto entry = pictures_.find(it); | |
| 59 if (entry == pictures_.end()) { | |
| 60 NOTREACHED() << "PictureMap does not contain entry " << it; | |
| 61 continue; | |
| 62 } | |
| 63 pictures_.erase(entry); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 sk_sp<SkPicture> BlimpClientPictureCache::DeserializePicture( | |
| 68 const cc::PictureData& picture_data) { | |
| 69 SkMemoryStream stream(picture_data.data); | |
| 70 return SkPicture::MakeFromStream(&stream, pixel_deserializer_); | |
| 71 } | |
| 72 | |
| 73 void BlimpClientPictureCache::MarkPictureForUnregistration( | |
| 74 uint32_t engine_picture_id) { | |
| 75 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.
| |
| 76 } | |
| 77 | |
| 78 void BlimpClientPictureCache::MarkPictureForRegistration( | |
| 79 uint32_t engine_picture_id) { | |
| 80 registry_.Stage(engine_picture_id); | |
| 81 } | |
| 82 | |
| 83 } // namespace client | |
| 84 } // namespace blimp | |
| OLD | NEW |