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

Side by Side 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, 5 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "cc/test/picture_cache_model.h"
6
7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkData.h"
9 #include "third_party/skia/include/core/SkPicture.h"
10 #include "third_party/skia/include/core/SkRefCnt.h"
11 #include "third_party/skia/include/core/SkStream.h"
12
13 class SkPixelSerializer;
14
15 namespace cc {
16 namespace {
17
18 sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) {
19 SkDynamicMemoryWStream write_stream;
20 picture->serialize(&write_stream, nullptr);
21 DCHECK_GT(write_stream.bytesWritten(), 0u);
22
23 sk_sp<SkData> data(write_stream.copyToData());
24
25 SkMemoryStream read_stream(data);
26 return SkPicture::MakeFromStream(&read_stream, nullptr);
27 }
28
29 } // namespace
30
31 PictureCacheModel::PictureCacheModel() = default;
32
33 PictureCacheModel::~PictureCacheModel() = default;
34
35 void PictureCacheModel::AddPicture(const SkPicture* picture) {
36 sk_sp<SkPicture> picture_copy = CopySkPicture(picture);
37 pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy));
38 }
39
40 sk_sp<const SkPicture> PictureCacheModel::GetPicture(uint32_t unique_id) {
41 if (pictures_.find(unique_id) == pictures_.end())
42 return nullptr;
43
44 return pictures_.find(unique_id)->second;
45 }
46
47 } // namespace cc
OLDNEW
« 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