| 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..1e6c972d98e1d428ec3b39bea404e5161e663402
|
| --- /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() {}
|
| +
|
| +void BlimpEnginePictureCache::MarkPictureForUnregistration(
|
| + const SkPicture* picture) {
|
| + registry_.Unstage(picture->uniqueID());
|
| +}
|
| +
|
| +void BlimpEnginePictureCache::MarkPictureForRegistration(
|
| + const SkPicture* picture) {
|
| + registry_.Stage(picture->uniqueID());
|
| +
|
| + // Do not serialize multiple times, even though the item is referred to from
|
| + // multiple places.
|
| + if (pictures_.find(picture->uniqueID()) != pictures_.end()) {
|
| + return;
|
| + }
|
| +
|
| + // Use skia's serialize() method for now.
|
| + SkDynamicMemoryWStream stream;
|
| + picture->serialize(&stream, pixel_serializer_);
|
| + if (stream.bytesWritten() <= 0) {
|
| + 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;
|
| + pictures_[picture_data.unique_id] = picture_data;
|
| +}
|
| +
|
| +cc::PictureCacheUpdate BlimpEnginePictureCache::CalculateCacheUpdateAndFlush() {
|
| + std::set<uint32_t> added;
|
| + std::set<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
|
|
|