Index: blimp/engine/renderer/blimp_engine_picture_cache.cc |
diff --git a/blimp/engine/renderer/blimp_engine_picture_cache.cc b/blimp/engine/renderer/blimp_engine_picture_cache.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1462a9233dfb06ba7258a582db53092b0842191c |
--- /dev/null |
+++ b/blimp/engine/renderer/blimp_engine_picture_cache.cc |
@@ -0,0 +1,78 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "blimp/engine/renderer/blimp_engine_picture_cache.h" |
+ |
+#include <memory> |
+#include <sstream> |
+#include <unordered_map> |
+#include <vector> |
+ |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "blimp/common/compositor/blimp_picture_cache_registry.h" |
+#include "cc/proto/picture_cache.h" |
+#include "third_party/skia/include/core/SkPicture.h" |
+#include "third_party/skia/include/core/SkStream.h" |
+ |
+namespace blimp { |
+namespace engine { |
+ |
+BlimpEnginePictureCache::BlimpEnginePictureCache( |
+ SkPixelSerializer* pixel_serializer) |
+ : pixel_serializer_(pixel_serializer) {} |
+ |
+BlimpEnginePictureCache::~BlimpEnginePictureCache() = default; |
+ |
+void BlimpEnginePictureCache::MarkPictureForUnregistration( |
+ const SkPicture* picture) { |
+ registry_.DecrementRefCount(picture->uniqueID()); |
+} |
+ |
+void BlimpEnginePictureCache::MarkPictureForRegistration( |
+ const SkPicture* picture) { |
+ registry_.IncrementRefCount(picture->uniqueID()); |
+ |
+ // Do not serialize multiple times, even though the item is referred to from |
+ // multiple places. |
+ if (pictures_.find(picture->uniqueID()) != pictures_.end()) { |
+ return; |
+ } |
+ |
+ // 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
|
+ SkDynamicMemoryWStream stream; |
+ picture->serialize(&stream, pixel_serializer_); |
+ DCHECK_GE(stream.bytesWritten(), 0u); |
+ |
+ // Store the picture data until it is sent to the client. |
+ cc::PictureData picture_data; |
+ picture_data.unique_id = picture->uniqueID(); |
+ picture_data.data.reset(stream.copyToData()); |
+ pictures_[picture_data.unique_id] = picture_data; |
+} |
+ |
+cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { |
+ std::vector<uint32_t> added; |
+ std::vector<uint32_t> removed; |
+ registry_.Commit(&added, &removed); |
+ |
+ // Create cache update consisting of new pictures. |
+ cc::PictureCacheUpdate update; |
+ 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.
|
+ auto entry = pictures_.find(it); |
+ if (entry == pictures_.end()) { |
+ 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!
|
+ continue; |
+ } |
+ update.push_back(entry->second); |
+ } |
+ |
+ // All new items will be sent to client, so clear everything. |
+ pictures_.clear(); |
+ |
+ return update; |
+} |
+ |
+} // namespace engine |
+} // namespace blimp |