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 <memory> | |
| 8 #include <sstream> | |
| 9 #include <unordered_map> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/logging.h" | |
| 13 #include "base/memory/ptr_util.h" | |
| 14 #include "blimp/common/compositor/blimp_picture_cache_registry.h" | |
| 15 #include "cc/proto/picture_cache.h" | |
| 16 #include "third_party/skia/include/core/SkPicture.h" | |
| 17 #include "third_party/skia/include/core/SkStream.h" | |
| 18 | |
| 19 namespace blimp { | |
| 20 namespace engine { | |
| 21 | |
| 22 BlimpEnginePictureCache::BlimpEnginePictureCache( | |
| 23 SkPixelSerializer* pixel_serializer) | |
| 24 : pixel_serializer_(pixel_serializer) {} | |
| 25 | |
| 26 BlimpEnginePictureCache::~BlimpEnginePictureCache() = default; | |
| 27 | |
| 28 void BlimpEnginePictureCache::MarkPictureForUnregistration( | |
| 29 const SkPicture* picture) { | |
| 30 registry_.DecrementRefCount(picture->uniqueID()); | |
| 31 } | |
| 32 | |
| 33 void BlimpEnginePictureCache::MarkPictureForRegistration( | |
| 34 const SkPicture* picture) { | |
| 35 registry_.IncrementRefCount(picture->uniqueID()); | |
| 36 | |
| 37 // Do not serialize multiple times, even though the item is referred to from | |
| 38 // multiple places. | |
| 39 if (pictures_.find(picture->uniqueID()) != pictures_.end()) { | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 // Use skia's serialize() method for now. | |
|
Kevin M
2016/06/06 23:33:59
For now... until what? Got more detail or a bug?
nyquist
2016/06/10 22:02:24
Well, we have in fact kind of settled for this unt
| |
| 44 SkDynamicMemoryWStream stream; | |
| 45 picture->serialize(&stream, pixel_serializer_); | |
| 46 DCHECK_GE(stream.bytesWritten(), 0u); | |
| 47 | |
| 48 // Store the picture data until it is sent to the client. | |
| 49 cc::PictureData picture_data; | |
| 50 picture_data.unique_id = picture->uniqueID(); | |
| 51 picture_data.data.reset(stream.copyToData()); | |
| 52 pictures_[picture_data.unique_id] = picture_data; | |
| 53 } | |
| 54 | |
| 55 cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { | |
| 56 std::vector<uint32_t> added; | |
| 57 std::vector<uint32_t> removed; | |
| 58 registry_.Commit(&added, &removed); | |
| 59 | |
| 60 // Create cache update consisting of new pictures. | |
| 61 cc::PictureCacheUpdate update; | |
| 62 for (const auto it : added) { | |
|
Kevin M
2016/06/06 23:33:59
"it" - good name for an iterator, not so good for
nyquist
2016/06/10 22:02:24
Done.
| |
| 63 auto entry = pictures_.find(it); | |
| 64 if (entry == pictures_.end()) { | |
| 65 NOTREACHED() << "Picture map does not contain entry " << it; | |
|
Kevin M
2016/06/06 23:33:59
This is more like a DLOG(ERROR). NOTREACHED() mean
nyquist
2016/06/10 22:02:24
Done. Thanks for the clarification!
| |
| 66 continue; | |
| 67 } | |
| 68 update.push_back(entry->second); | |
| 69 } | |
| 70 | |
| 71 // All new items will be sent to client, so clear everything. | |
| 72 pictures_.clear(); | |
| 73 | |
| 74 return update; | |
| 75 } | |
| 76 | |
| 77 } // namespace engine | |
| 78 } // namespace blimp | |
| OLD | NEW |