Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkMipmapDrawDownSampler.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
9
10#ifdef SK_USE_DRAWING_MIPMAP_DOWNSAMPLER
11
19#include "src/core/SkDraw.h"
20#include "src/core/SkMipmap.h"
22#include <memory>
23
24namespace {
25
26struct DrawDownSampler : SkMipmapDownSampler {
27 SkPaint fPaint;
28
29 DrawDownSampler() {
30 // For efficiency, we want to be in src mode when building levels
31 // to avoid any extra trying to "blend".
33 }
34
35 void buildLevel(const SkPixmap& dst, const SkPixmap& src) override;
36};
37
38static SkSamplingOptions choose_options(const SkPixmap& dst, const SkPixmap& src) {
39 // if we're a perfect 2x2 downscale, just use bilerp
40 if (dst.width() * 2 == src.width() && dst.height() * 2 == src.height()) {
42 }
43 // general case -- might experiment with different cubic parameter values
45 return SkSamplingOptions(cubic);
46}
47
48void DrawDownSampler::buildLevel(const SkPixmap& dst, const SkPixmap& src) {
49 const SkRasterClip rclip(dst.bounds());
50 const SkMatrix mx = SkMatrix::Scale(SkIntToScalar(dst.width()) / src.width(),
51 SkIntToScalar(dst.height()) / src.height());
52 const auto sampling = choose_options(dst, src);
53
55 draw.fDst = dst;
56 draw.fCTM = &mx;
57 draw.fRC = &rclip;
58
60 bitmap.installPixels(src.info(), const_cast<void*>(src.addr()), src.rowBytes());
61
62 draw.drawBitmap(bitmap, SkMatrix::I(), nullptr, sampling, fPaint);
63}
64
65} // namespace
66
67std::unique_ptr<SkMipmapDownSampler> SkMipmap::MakeDownSampler(const SkPixmap& root) {
68 return std::make_unique<DrawDownSampler>();
69}
70
71#endif
#define SkIntToScalar(x)
Definition SkScalar.h:57
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
SkPixmap fDst
Definition SkDrawBase.h:151
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static const SkMatrix & I()
static std::unique_ptr< SkMipmapDownSampler > MakeDownSampler(const SkPixmap &)
void setBlendMode(SkBlendMode mode)
Definition SkPaint.cpp:151
SkSamplingOptions sampling
Definition SkRecords.h:337
dst
Definition cp.py:12
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
static constexpr SkCubicResampler CatmullRom()
virtual void buildLevel(const SkPixmap &dst, const SkPixmap &src)=0