Chromium Code Reviews| 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..c6655a3ceb1643ab31126d0ea58bdc20f1f230e4 |
| --- /dev/null |
| +++ b/blimp/engine/renderer/blimp_engine_picture_cache.cc |
| @@ -0,0 +1,83 @@ |
| +// 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 <map> |
| +#include <memory> |
| +#include <sstream> |
| +#include <vector> |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "blimp/common/compositor/blimp_picture_cache_registry.h" |
| +#include "cc/proto/picture_cache.h" |
| +#include "third_party/skia/include/core/SkPicture.h" |
| +#include "third_party/skia/include/core/SkStream.h" |
| + |
| +namespace blimp { |
| +namespace engine { |
| + |
| +BlimpEnginePictureCache::BlimpEnginePictureCache( |
| + SkPixelSerializer* pixel_serializer) |
| + : pixel_serializer_(pixel_serializer) {} |
| + |
| +BlimpEnginePictureCache::~BlimpEnginePictureCache() {} |
|
vmpstr
2016/06/01 00:10:56
= default
nyquist
2016/06/04 00:24:57
Done.
|
| + |
| +void BlimpEnginePictureCache::MarkPictureForUnregistration( |
| + const SkPicture* picture) { |
| + registry_.DecrementRefCount(picture->uniqueID()); |
| +} |
| + |
| +void BlimpEnginePictureCache::MarkPictureForRegistration( |
| + const SkPicture* picture) { |
| + registry_.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()) { |
|
vmpstr
2016/06/01 00:10:56
nit: braces optional
nyquist
2016/06/04 00:24:57
Yes, but we use them in //blimp, which is why my C
|
| + return; |
| + } |
| + |
| + // Use skia's serialize() method for now. |
| + SkDynamicMemoryWStream stream; |
| + picture->serialize(&stream, pixel_serializer_); |
| + if (stream.bytesWritten() <= 0) { |
|
vmpstr
2016/06/01 00:10:56
Can you add a comment on when this can fail?
nyquist
2016/06/04 00:24:57
From reading the serialization code, it seems that
|
| + DVLOG(1) << "Unable to serialize SkPicture with unique ID " |
| + << picture->uniqueID(); |
| + return; |
| + } |
| + |
| + // Store the picture data until it is sent to the client. |
| + cc::PictureData picture_data; |
| + picture_data.unique_id = picture->uniqueID(); |
| + sk_sp<SkData> data(stream.copyToData()); |
| + picture_data.data = data; |
|
vmpstr
2016/06/01 00:10:56
the last two lines could be one line?
picture_dat
nyquist
2016/06/04 00:24:57
Done.
|
| + pictures_[picture_data.unique_id] = picture_data; |
| +} |
| + |
| +cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() { |
| + std::vector<uint32_t> added; |
| + std::vector<uint32_t> removed; |
| + registry_.Commit(&added, &removed); |
| + |
| + // Create cache update consisting of new pictures. |
| + cc::PictureCacheUpdate update; |
| + for (const auto it : added) { |
| + auto entry = pictures_.find(it); |
| + if (entry == pictures_.end()) { |
| + NOTREACHED() << "PictureMap does not contain entry " << it; |
| + continue; |
| + } |
| + update.push_back(entry->second); |
| + } |
| + |
| + // All new items will be sent to client, so clear everything. |
| + pictures_.clear(); |
| + |
| + return update; |
| +} |
| + |
| +} // namespace engine |
| +} // namespace blimp |