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/engine/renderer/blimp_engine_picture_cache.h" | |
| 6 | |
| 7 #include <sstream> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "third_party/skia/include/core/SkStream.h" | |
| 12 | |
| 13 namespace blimp { | |
| 14 namespace engine { | |
| 15 | |
| 16 BlimpEnginePictureCache::BlimpEnginePictureCache( | |
| 17 SkPixelSerializer* pixel_serializer) | |
| 18 : pixel_serializer_(pixel_serializer) {} | |
| 19 | |
| 20 BlimpEnginePictureCache::~BlimpEnginePictureCache() = default; | |
| 21 | |
| 22 void BlimpEnginePictureCache::MarkPictureForUnregistration( | |
| 23 const SkPicture* picture) { | |
| 24 DCHECK(picture); | |
| 25 reference_tracker_.DecrementRefCount(picture->uniqueID()); | |
| 26 } | |
| 27 | |
| 28 void BlimpEnginePictureCache::MarkPictureForRegistration( | |
| 29 const SkPicture* picture) { | |
| 30 DCHECK(picture); | |
| 31 reference_tracker_.IncrementRefCount(picture->uniqueID()); | |
| 32 | |
| 33 // Do not serialize multiple times, even though the item is referred to from | |
| 34 // multiple places. | |
| 35 if (CacheContainsPicture(picture)) { | |
| 36 return; | |
| 37 } | |
| 38 | |
| 39 SerializePictureAndAddToCache(picture); | |
| 40 } | |
| 41 | |
| 42 cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { | |
| 43 std::vector<uint32_t> added; | |
| 44 std::vector<uint32_t> removed; | |
| 45 reference_tracker_.CommitRefCounts(&added, &removed); | |
| 46 | |
| 47 // Create cache update consisting of new pictures. | |
| 48 cc::PictureCacheUpdate update; | |
| 49 for (const uint32_t item : added) { | |
| 50 auto entry = pictures_.find(item); | |
| 51 DCHECK(entry != pictures_.end()); | |
| 52 update.push_back(entry->second); | |
| 53 } | |
| 54 | |
| 55 // All new items will be sent to the client, so clear everything. | |
| 56 pictures_.clear(); | |
| 57 | |
| 58 return update; | |
| 59 } | |
| 60 | |
| 61 bool BlimpEnginePictureCache::CacheContainsPicture( | |
| 62 const SkPicture* picture) const { | |
| 63 return pictures_.find(picture->uniqueID()) != pictures_.end(); | |
|
vmpstr
2016/06/16 22:09:58
inline this wherever it's used
nyquist
2016/06/24 11:11:14
Done.
| |
| 64 } | |
| 65 | |
| 66 void BlimpEnginePictureCache::SerializePictureAndAddToCache( | |
| 67 const SkPicture* picture) { | |
| 68 SkDynamicMemoryWStream stream; | |
| 69 picture->serialize(&stream, pixel_serializer_); | |
| 70 DCHECK_GE(stream.bytesWritten(), 0u); | |
| 71 | |
| 72 // Store the picture data until it is sent to the client. | |
| 73 cc::PictureData picture_data; | |
|
vmpstr
2016/06/16 22:09:58
Can this have a constructor that takes two paramet
nyquist
2016/06/24 11:11:14
Done.
| |
| 74 picture_data.unique_id = picture->uniqueID(); | |
| 75 picture_data.data.reset(stream.copyToData()); | |
| 76 pictures_[picture_data.unique_id] = picture_data; | |
| 77 } | |
| 78 | |
| 79 } // namespace engine | |
| 80 } // namespace blimp | |
| OLD | NEW |