| OLD | NEW |
| (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 | |
| 12 class SkPixelSerializer; | |
| 13 | |
| 14 namespace cc { | |
| 15 namespace { | |
| 16 | |
| 17 sk_sp<SkPicture> CopySkPicture(const SkPicture* picture) { | |
| 18 sk_sp<SkData> data = picture->serialize(); | |
| 19 DCHECK_GT(data->size(), 0u); | |
| 20 return SkPicture::MakeFromData(data.get()); | |
| 21 } | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 PictureCacheModel::PictureCacheModel() = default; | |
| 26 | |
| 27 PictureCacheModel::~PictureCacheModel() = default; | |
| 28 | |
| 29 void PictureCacheModel::AddPicture(const SkPicture* picture) { | |
| 30 sk_sp<SkPicture> picture_copy = CopySkPicture(picture); | |
| 31 pictures_.insert(std::make_pair(picture->uniqueID(), picture_copy)); | |
| 32 } | |
| 33 | |
| 34 sk_sp<const SkPicture> PictureCacheModel::GetPicture(uint32_t unique_id) { | |
| 35 if (pictures_.find(unique_id) == pictures_.end()) | |
| 36 return nullptr; | |
| 37 | |
| 38 return pictures_.find(unique_id)->second; | |
| 39 } | |
| 40 | |
| 41 } // namespace cc | |
| OLD | NEW |