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

Unified Diff: cc/test/picture_cache_model.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
« no previous file with comments | « cc/test/picture_cache_model.h ('k') | cc/test/skia_common.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/picture_cache_model.cc
diff --git a/cc/test/picture_cache_model.cc b/cc/test/picture_cache_model.cc
new file mode 100644
index 0000000000000000000000000000000000000000..54ed06b53558a5c2459bad69b224f0cd4c63864d
--- /dev/null
+++ b/cc/test/picture_cache_model.cc
@@ -0,0 +1,47 @@
+// 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 "cc/test/picture_cache_model.h"
+
+#include "base/logging.h"
+#include "third_party/skia/include/core/SkData.h"
+#include "third_party/skia/include/core/SkPicture.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
+#include "third_party/skia/include/core/SkStream.h"
+
+class SkPixelSerializer;
+
+namespace cc {
+namespace {
+
+sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) {
+ SkDynamicMemoryWStream write_stream;
+ picture->serialize(&write_stream, nullptr);
+ DCHECK_GT(write_stream.bytesWritten(), 0u);
+
+ sk_sp<SkData> data(write_stream.copyToData());
+
+ SkMemoryStream read_stream(data);
+ return SkPicture::MakeFromStream(&read_stream, nullptr);
+}
+
+} // namespace
+
+PictureCacheModel::PictureCacheModel() = default;
+
+PictureCacheModel::~PictureCacheModel() = default;
+
+void PictureCacheModel::AddPicture(const SkPicture* picture) {
+ sk_sp<SkPicture> picture_copy = CopySkPicture(picture);
+ pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy));
+}
+
+sk_sp<const SkPicture> PictureCacheModel::GetPicture(uint32_t unique_id) {
+ if (pictures_.find(unique_id) == pictures_.end())
+ return nullptr;
+
+ return pictures_.find(unique_id)->second;
+}
+
+} // namespace cc
« no previous file with comments | « cc/test/picture_cache_model.h ('k') | cc/test/skia_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698