| 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/engine/renderer/blimp_engine_picture_cache.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 | |
| 10 namespace blimp { | |
| 11 namespace engine { | |
| 12 | |
| 13 BlimpEnginePictureCache::BlimpEnginePictureCache( | |
| 14 SkPixelSerializer* pixel_serializer) | |
| 15 : pixel_serializer_(pixel_serializer) {} | |
| 16 | |
| 17 BlimpEnginePictureCache::~BlimpEnginePictureCache() = default; | |
| 18 | |
| 19 void BlimpEnginePictureCache::MarkUsed(const SkPicture* picture) { | |
| 20 DCHECK(picture); | |
| 21 reference_tracker_.IncrementRefCount(picture->uniqueID()); | |
| 22 | |
| 23 // Do not serialize multiple times, even though the item is referred to from | |
| 24 // multiple places. | |
| 25 if (pictures_.find(picture->uniqueID()) != pictures_.end()) { | |
| 26 return; | |
| 27 } | |
| 28 | |
| 29 Put(picture); | |
| 30 } | |
| 31 | |
| 32 std::vector<cc::PictureData> | |
| 33 BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { | |
| 34 std::vector<uint32_t> added; | |
| 35 std::vector<uint32_t> removed; | |
| 36 reference_tracker_.CommitRefCounts(&added, &removed); | |
| 37 | |
| 38 // Create cache update consisting of new pictures. | |
| 39 std::vector<cc::PictureData> update; | |
| 40 for (const uint32_t item : added) { | |
| 41 auto entry = pictures_.find(item); | |
| 42 DCHECK(entry != pictures_.end()); | |
| 43 update.push_back(entry->second); | |
| 44 } | |
| 45 | |
| 46 // All new items will be sent to the client, so clear everything. | |
| 47 pictures_.clear(); | |
| 48 reference_tracker_.ClearRefCounts(); | |
| 49 | |
| 50 return update; | |
| 51 } | |
| 52 | |
| 53 void BlimpEnginePictureCache::Put(const SkPicture* picture) { | |
| 54 sk_sp<SkData> data = picture->serialize(pixel_serializer_); | |
| 55 DCHECK_GE(data->size(), 0u); | |
| 56 | |
| 57 // Store the picture data until it is sent to the client. | |
| 58 pictures_.insert( | |
| 59 std::make_pair(picture->uniqueID(), | |
| 60 cc::PictureData(picture->uniqueID(), std::move(data)))); | |
| 61 } | |
| 62 | |
| 63 } // namespace engine | |
| 64 } // namespace blimp | |
| OLD | NEW |