| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 #ifndef SKIA_EXT_SK_FUTURE_DRAWABLE_H_ |
| 6 #define SKIA_EXT_SK_FUTURE_DRAWABLE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <unordered_map> |
| 10 |
| 11 #include "third_party/skia/include/core/SkDrawable.h" |
| 12 #include "third_party/skia/include/core/SkPicture.h" |
| 13 #include "third_party/skia/include/core/SkScalar.h" |
| 14 |
| 15 class SK_API SkFutureDrawable : public SkDrawable { |
| 16 public: |
| 17 static const char kTypeName[]; |
| 18 |
| 19 SkFutureDrawable(const SkRect& bounds) |
| 20 : fBounds(bounds), fDrawableRef(nullptr) {} |
| 21 SkFutureDrawable(const SkRect& bounds, int id) |
| 22 : fBounds(bounds), id(id), fDrawableRef(nullptr) {} |
| 23 |
| 24 void flatten(SkWriteBuffer& buffer) const override; |
| 25 |
| 26 Factory getFactory() const override { return CreateProc; } |
| 27 |
| 28 int Id() const { return id; } |
| 29 |
| 30 void setDrawableRef(SkDrawable* ref) { fDrawableRef = ref; } |
| 31 |
| 32 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer); |
| 33 |
| 34 static void addDrawableRef(int id, std::unique_ptr<SkDrawable> ref) { |
| 35 fDrawableRefMap[id] = std::move(ref); |
| 36 } |
| 37 |
| 38 static void resetDrawableRef() { fDrawableRefMap.clear(); } |
| 39 |
| 40 protected: |
| 41 SkRect onGetBounds() override { return fBounds; } |
| 42 |
| 43 void onDraw(SkCanvas* canvas) override; |
| 44 |
| 45 SkPicture* onNewPictureSnapshot() override; |
| 46 |
| 47 const char* getTypeName() const override { return kTypeName; } |
| 48 |
| 49 private: |
| 50 const SkRect fBounds; |
| 51 int id; |
| 52 SkDrawable* fDrawableRef; |
| 53 |
| 54 static std::unordered_map<int, std::unique_ptr<SkDrawable>> fDrawableRefMap; |
| 55 }; |
| 56 |
| 57 #endif // SKIA_EXT_SK_FUTURE_DRAWABLE_H_ |
| OLD | NEW |