1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkSGImage_DEFINED 9 #define SkSGImage_DEFINED 10 11 #include "include/core/SkImage.h" 12 #include "include/core/SkRect.h" 13 #include "include/core/SkRefCnt.h" 14 #include "include/core/SkSamplingOptions.h" 15 #include "modules/sksg/include/SkSGNode.h" 16 #include "modules/sksg/include/SkSGRenderNode.h" 17 18 #include <utility> 19 20 class SkCanvas; 21 class SkMatrix; 22 struct SkPoint; 23 24 namespace sksg { 25 class InvalidationController; 26 27 /** 28 * Concrete rendering node, wrapping an SkImage. 29 * 30 */ 31 class Image final : public RenderNode { 32 public: Make(sk_sp<SkImage> image)33 static sk_sp<Image> Make(sk_sp<SkImage> image) { 34 return sk_sp<Image>(new Image(std::move(image))); 35 } 36 37 SG_ATTRIBUTE(Image , sk_sp<SkImage> , fImage ) 38 SG_ATTRIBUTE(SamplingOptions, SkSamplingOptions, fSamplingOptions) 39 SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias ) 40 41 protected: 42 explicit Image(sk_sp<SkImage>); 43 44 void onRender(SkCanvas*, const RenderContext*) const override; 45 const RenderNode* onNodeAt(const SkPoint&) const override; 46 47 SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; 48 49 private: 50 SkSamplingOptions fSamplingOptions; 51 sk_sp<SkImage> fImage; 52 bool fAntiAlias = true; 53 54 using INHERITED = RenderNode; 55 }; 56 57 } // namespace sksg 58 59 #endif // SkSGImage_DEFINED 60