Flutter Engine
The Flutter Engine
SkShaderMaskFilterImpl.cpp
Go to the documentation of this file.
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
9
17#include "include/core/SkRect.h"
22#include "src/core/SkMask.h"
25
26#include <cstdint>
27#include <cstring>
28#include <utility>
29
30class SkMatrix;
31
32sk_sp<SkFlattenable> SkShaderMaskFilterImpl::CreateProc(SkReadBuffer& buffer) {
33 return SkShaderMaskFilter::Make(buffer.readShader());
34}
35
36void SkShaderMaskFilterImpl::flatten(SkWriteBuffer& buffer) const {
37 buffer.writeFlattenable(fShader.get());
38}
39
40static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB,
41 size_t copyBytes, int rows) {
42 for (int i = 0; i < rows; ++i) {
43 memcpy(dst, src, copyBytes);
44 dst = (char*)dst + dstRB;
45 src = (const char*)src + srcRB;
46 }
47}
48
50 SkIPoint* margin) const {
51 if (src.fFormat != SkMask::kA8_Format) {
52 return false;
53 }
54
55 if (margin) {
56 margin->set(0, 0);
57 }
58 dst->bounds() = src.fBounds;
59 dst->rowBytes() = src.fBounds.width(); // need alignment?
60 dst->format() = SkMask::kA8_Format;
61
62 if (src.fImage == nullptr) {
63 dst->image() = nullptr;
64 return true;
65 }
66 size_t size = dst->computeImageSize();
67 if (0 == size) {
68 return false; // too big to allocate, abort
69 }
70
71 // Allocate and initialize dst image with a copy of the src image
73 rect_memcpy(dst->image(), dst->fRowBytes, src.fImage, src.fRowBytes,
74 src.fBounds.width() * sizeof(uint8_t), src.fBounds.height());
75
76 // Now we have a dst-mask, just need to setup a canvas and draw into it
78 if (!bitmap.installMaskPixels(*dst)) {
79 return false;
80 }
81
83 paint.setShader(fShader);
84 // this blendmode is the trick: we only draw the shader where the mask is
85 paint.setBlendMode(SkBlendMode::kSrcIn);
86
87 SkCanvas canvas(bitmap);
88 canvas.translate(-SkIntToScalar(dst->fBounds.fLeft), -SkIntToScalar(dst->fBounds.fTop));
89 canvas.concat(ctm);
90 canvas.drawPaint(paint);
91 return true;
92}
93
95 return shader ? sk_sp<SkMaskFilter>(new SkShaderMaskFilterImpl(std::move(shader))) : nullptr;
96}
97
98void SkShaderMaskFilter::RegisterFlattenables() {
100 // Previous name
101 SkFlattenable::Register("SkShaderMF", SkShaderMaskFilterImpl::CreateProc);
102}
@ kSrcIn
r = s * da
#define SK_REGISTER_FLATTENABLE(type)
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static void rect_memcpy(void *dst, size_t dstRB, const void *src, size_t srcRB, size_t copyBytes, int rows)
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static void Register(const char name[], Factory)
bool filterMask(SkMaskBuilder *dst, const SkMask &src, const SkMatrix &, SkIPoint *margin) const override
static sk_sp< SkMaskFilter > Make(sk_sp< SkShader > shader)
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
Definition: bitmap.py:1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12
void set(int32_t x, int32_t y)
Definition: SkPoint_impl.h:65
static uint8_t * AllocImage(size_t bytes, AllocType=kUninit_Alloc)
Definition: SkMask.cpp:45
Definition: SkMask.h:25
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28