Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Unified Diff: blimp/engine/renderer/blimp_engine_picture_cache.cc

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from vmpstr, including adding //cc/blimp Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bb67345dca71558cfd387a4c98b5b97dc20c0399
--- /dev/null
+++ b/blimp/engine/renderer/blimp_engine_picture_cache.cc
@@ -0,0 +1,67 @@
+// 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 "base/logging.h"
+#include "base/memory/ptr_util.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::MarkUsed(const SkPicture* picture) {
+ DCHECK(picture);
+ reference_tracker_.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;
+ }
+
+ Put(picture);
+}
+
+std::vector<cc::PictureData>
+BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() {
+ std::vector<uint32_t> added;
+ std::vector<uint32_t> removed;
+ reference_tracker_.CommitRefCounts(&added, &removed);
+
+ // Create cache update consisting of new pictures.
+ std::vector<cc::PictureData> update;
+ for (const uint32_t item : added) {
+ auto entry = pictures_.find(item);
+ DCHECK(entry != pictures_.end());
+ update.push_back(entry->second);
+ }
+
+ // All new items will be sent to the client, so clear everything.
+ pictures_.clear();
+ reference_tracker_.ClearRefCounts();
+
+ return update;
+}
+
+void BlimpEnginePictureCache::Put(const SkPicture* picture) {
+ SkDynamicMemoryWStream stream;
+ picture->serialize(&stream, pixel_serializer_);
+ DCHECK_GE(stream.bytesWritten(), 0u);
+
+ // Store the picture data until it is sent to the client.
+ pictures_.insert(
+ std::make_pair(picture->uniqueID(),
+ cc::PictureData(picture->uniqueID(),
+ sk_sp<SkData>(stream.copyToData()))));
+}
+
+} // namespace engine
+} // namespace blimp
« no previous file with comments | « blimp/engine/renderer/blimp_engine_picture_cache.h ('k') | blimp/engine/renderer/blimp_engine_picture_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698