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 #include "modules/sksg/include/SkSGImage.h" 9 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkImage.h" 12 13 namespace sksg { 14 Image(sk_sp<SkImage> image)15Image::Image(sk_sp<SkImage> image) : fImage(std::move(image)) {} 16 onRender(SkCanvas * canvas,const RenderContext * ctx) const17void Image::onRender(SkCanvas* canvas, const RenderContext* ctx) const { 18 if (!fImage) { 19 return; 20 } 21 22 SkPaint paint; 23 paint.setAntiAlias(fAntiAlias); 24 paint.setFilterQuality(fQuality); 25 26 if (ctx) { 27 ctx->modulatePaint(canvas->getTotalMatrix(), &paint); 28 } 29 30 canvas->drawImage(fImage, 0, 0, &paint); 31 } 32 onNodeAt(const SkPoint & p) const33const RenderNode* Image::onNodeAt(const SkPoint& p) const { 34 SkASSERT(this->bounds().contains(p.x(), p.y())); 35 return this; 36 } 37 onRevalidate(InvalidationController *,const SkMatrix & ctm)38SkRect Image::onRevalidate(InvalidationController*, const SkMatrix& ctm) { 39 return fImage ? SkRect::Make(fImage->bounds()) : SkRect::MakeEmpty(); 40 } 41 42 } // namespace sksg 43