| Index: skia/ext/SkFutureDrawable.cc
|
| diff --git a/skia/ext/SkFutureDrawable.cc b/skia/ext/SkFutureDrawable.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f42107d96401d7667e24890c6de77491d16a00d8
|
| --- /dev/null
|
| +++ b/skia/ext/SkFutureDrawable.cc
|
| @@ -0,0 +1,60 @@
|
| +/*
|
| + * Copyright 2017 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +#include "skia/ext/SkFutureDrawable.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkPictureRecorder.h"
|
| +#include "third_party/skia/include/core/SkScalar.h"
|
| +#include "third_party/skia/include/core/SkWriteBuffer.h"
|
| +#include "third_party/skia/src/core/SkReadBuffer.h"
|
| +
|
| +const char SkFutureDrawable::kTypeName[] = "SkFutureDrawable";
|
| +
|
| +std::unordered_map<int, std::unique_ptr<SkDrawable>>
|
| + SkFutureDrawable::fDrawableRefMap = {};
|
| +
|
| +void SkFutureDrawable::flatten(SkWriteBuffer& buffer) const {
|
| + // Write the bounds.
|
| + buffer.writeRect(fBounds);
|
| + // Write the unique id.
|
| + buffer.writeInt(id);
|
| +}
|
| +
|
| +// static
|
| +sk_sp<SkFlattenable> SkFutureDrawable::CreateProc(SkReadBuffer& buffer) {
|
| + // Read the bounds.
|
| + SkRect bounds;
|
| + buffer.readRect(&bounds);
|
| +
|
| + // Read the unique id.
|
| + int id = buffer.readInt();
|
| + sk_sp<SkFutureDrawable> drawable = sk_make_sp<SkFutureDrawable>(bounds, id);
|
| +
|
| + // Check whether the drawable reference is there
|
| + const auto ptr = fDrawableRefMap.find(id);
|
| + if (ptr != fDrawableRefMap.end())
|
| + drawable->setDrawableRef(ptr->second.get());
|
| +
|
| + return drawable;
|
| +}
|
| +
|
| +void SkFutureDrawable::onDraw(SkCanvas* canvas) {
|
| + if (!fDrawableRef)
|
| + return;
|
| + fDrawableRef->draw(canvas);
|
| +}
|
| +
|
| +SkPicture* SkFutureDrawable::onNewPictureSnapshot() {
|
| + SkPictureRecorder recorder;
|
| +
|
| + SkCanvas* canvas = recorder.beginRecording(fBounds, nullptr, 0);
|
| + canvas->translate(fBounds.x(), fBounds.y());
|
| + draw(canvas);
|
| + return recorder.finishRecordingAsPicture().release();
|
| +}
|
|
|