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 <map> | |
| 8 #include <memory> | |
| 9 #include <sstream> | |
| 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() {} | |
|
vmpstr
2016/06/01 00:10:56
= default
nyquist
2016/06/04 00:24:57
Done.
| |
| 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()) { | |
|
vmpstr
2016/06/01 00:10:56
nit: braces optional
nyquist
2016/06/04 00:24:57
Yes, but we use them in //blimp, which is why my C
| |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 // Use skia's serialize() method for now. | |
| 44 SkDynamicMemoryWStream stream; | |
| 45 picture->serialize(&stream, pixel_serializer_); | |
| 46 if (stream.bytesWritten() <= 0) { | |
|
vmpstr
2016/06/01 00:10:56
Can you add a comment on when this can fail?
nyquist
2016/06/04 00:24:57
From reading the serialization code, it seems that
| |
| 47 DVLOG(1) << "Unable to serialize SkPicture with unique ID " | |
| 48 << picture->uniqueID(); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 // Store the picture data until it is sent to the client. | |
| 53 cc::PictureData picture_data; | |
| 54 picture_data.unique_id = picture->uniqueID(); | |
| 55 sk_sp<SkData> data(stream.copyToData()); | |
| 56 picture_data.data = data; | |
|
vmpstr
2016/06/01 00:10:56
the last two lines could be one line?
picture_dat
nyquist
2016/06/04 00:24:57
Done.
| |
| 57 pictures_[picture_data.unique_id] = picture_data; | |
| 58 } | |
| 59 | |
| 60 cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { | |
| 61 std::vector<uint32_t> added; | |
| 62 std::vector<uint32_t> removed; | |
| 63 registry_.Commit(&added, &removed); | |
| 64 | |
| 65 // Create cache update consisting of new pictures. | |
| 66 cc::PictureCacheUpdate update; | |
| 67 for (const auto it : added) { | |
| 68 auto entry = pictures_.find(it); | |
| 69 if (entry == pictures_.end()) { | |
| 70 NOTREACHED() << "PictureMap does not contain entry " << it; | |
| 71 continue; | |
| 72 } | |
| 73 update.push_back(entry->second); | |
| 74 } | |
| 75 | |
| 76 // All new items will be sent to client, so clear everything. | |
| 77 pictures_.clear(); | |
| 78 | |
| 79 return update; | |
| 80 } | |
| 81 | |
| 82 } // namespace engine | |
| 83 } // namespace blimp | |
| OLD | NEW |