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

Side by Side Diff: cc/test/picture_cache_model.cc

Issue 2343993002: use SkData oriented picture serialize api (Closed)
Patch Set: doh -- use 0u for template bad guesses Created 4 years, 3 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/blimp/picture_data_conversions_unittest.cc ('k') | skia/config/SkUserConfig.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/test/picture_cache_model.h" 5 #include "cc/test/picture_cache_model.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkData.h" 8 #include "third_party/skia/include/core/SkData.h"
9 #include "third_party/skia/include/core/SkPicture.h" 9 #include "third_party/skia/include/core/SkPicture.h"
10 #include "third_party/skia/include/core/SkRefCnt.h" 10 #include "third_party/skia/include/core/SkRefCnt.h"
11 #include "third_party/skia/include/core/SkStream.h"
12 11
13 class SkPixelSerializer; 12 class SkPixelSerializer;
14 13
15 namespace cc { 14 namespace cc {
16 namespace { 15 namespace {
17 16
18 sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) { 17 sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) {
19 SkDynamicMemoryWStream write_stream; 18 sk_sp<SkData> data = picture->serialize();
20 picture->serialize(&write_stream, nullptr); 19 DCHECK_GT(data->size(), 0u);
21 DCHECK_GT(write_stream.bytesWritten(), 0u); 20 return SkPicture::MakeFromData(data.get());
22
23 sk_sp<SkData> data(write_stream.copyToData());
24
25 SkMemoryStream read_stream(data);
26 return SkPicture::MakeFromStream(&read_stream, nullptr);
27 } 21 }
28 22
29 } // namespace 23 } // namespace
30 24
31 PictureCacheModel::PictureCacheModel() = default; 25 PictureCacheModel::PictureCacheModel() = default;
32 26
33 PictureCacheModel::~PictureCacheModel() = default; 27 PictureCacheModel::~PictureCacheModel() = default;
34 28
35 void PictureCacheModel::AddPicture(const SkPicture* picture) { 29 void PictureCacheModel::AddPicture(const SkPicture* picture) {
36 sk_sp<SkPicture> picture_copy = CopySkPicture(picture); 30 sk_sp<SkPicture> picture_copy = CopySkPicture(picture);
37 pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy)); 31 pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy));
38 } 32 }
39 33
40 sk_sp<const SkPicture> PictureCacheModel::GetPicture(uint32_t unique_id) { 34 sk_sp<const SkPicture> PictureCacheModel::GetPicture(uint32_t unique_id) {
41 if (pictures_.find(unique_id) == pictures_.end()) 35 if (pictures_.find(unique_id) == pictures_.end())
42 return nullptr; 36 return nullptr;
43 37
44 return pictures_.find(unique_id)->second; 38 return pictures_.find(unique_id)->second;
45 } 39 }
46 40
47 } // namespace cc 41 } // namespace cc
OLDNEW
« no previous file with comments | « cc/blimp/picture_data_conversions_unittest.cc ('k') | skia/config/SkUserConfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698