blob: 64bfd3398fc6c5c123f9efb79ed80862ea06612d [file] [log] [blame]
Florin Malita49328072018-01-08 12:51:12 -05001/*
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 "SkSGImage.h"
9
10#include "SkCanvas.h"
11#include "SkImage.h"
12
13namespace sksg {
14
15Image::Image(sk_sp<SkImage> image) : fImage(std::move(image)) {}
16
Florin Malitac0132ff2018-08-09 07:40:01 -040017void Image::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
Florin Malita62c6bd92018-10-03 14:39:56 -040018 if (!fImage) {
19 return;
20 }
21
Florin Malita49328072018-01-08 12:51:12 -050022 SkPaint paint;
23 paint.setAntiAlias(fAntiAlias);
24 paint.setFilterQuality(fQuality);
25
Florin Malitac0132ff2018-08-09 07:40:01 -040026 if (ctx) {
27 ctx->modulatePaint(&paint);
28 }
29
Florin Malitaf2dd96f2018-07-30 11:16:41 -040030 canvas->drawImage(fImage, 0, 0, &paint);
Florin Malita49328072018-01-08 12:51:12 -050031}
32
Florin Malitaeb46bd82019-02-12 09:33:21 -050033const RenderNode* Image::onNodeAt(const SkPoint& p) const {
34 SkASSERT(this->bounds().contains(p.x(), p.y()));
35 return this;
36}
37
Florin Malita49328072018-01-08 12:51:12 -050038SkRect Image::onRevalidate(InvalidationController*, const SkMatrix& ctm) {
Florin Malita62c6bd92018-10-03 14:39:56 -040039 return fImage ? SkRect::Make(fImage->bounds()) : SkRect::MakeEmpty();
Florin Malita49328072018-01-08 12:51:12 -050040}
41
42} // namespace sksg