Flutter Engine
The Flutter Engine
SkRuntimeBlender.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
10#include "include/core/SkData.h"
23
24#include <string>
25
26using namespace skia_private;
27
28#if defined(SK_BUILD_FOR_DEBUGGER)
29 constexpr bool kLenientSkSLDeserialization = true;
30#else
31 constexpr bool kLenientSkSLDeserialization = false;
32#endif
33
34sk_sp<SkFlattenable> SkRuntimeBlender::CreateProc(SkReadBuffer& buffer) {
35 if (!buffer.validate(buffer.allowSkSL())) {
36 return nullptr;
37 }
38
39 SkString sksl;
40 buffer.readString(&sksl);
41 sk_sp<SkData> uniforms = buffer.readByteArrayAsData();
42
44 if constexpr (!kLenientSkSLDeserialization) {
45 if (!buffer.validate(effect != nullptr)) {
46 return nullptr;
47 }
48 }
49
52 return nullptr;
53 }
54
55 if constexpr (kLenientSkSLDeserialization) {
56 if (!effect) {
57 SkDebugf("Serialized SkSL failed to compile. Ignoring/dropping SkSL blender.\n");
58 return nullptr;
59 }
60 }
61
62 return effect->makeBlender(std::move(uniforms), SkSpan(children));
63}
64
67 // SkRP has support for many parts of #version 300 already, but for now, we restrict its
68 // usage in runtime effects to just #version 100.
69 return false;
70 }
71 if (const SkSL::RP::Program* program = fEffect->getRPProgram(/*debugTrace=*/nullptr)) {
73 fEffect->uniforms(),
74 fUniforms,
75 /*alwaysCopyIntoAlloc=*/false,
76 rec.fDstCS,
77 rec.fAlloc);
79 matrix.markCTMApplied();
80 RuntimeEffectRPCallbacks callbacks(rec, matrix, fChildren, fEffect->fSampleUsages);
81 bool success = program->appendStages(rec.fPipeline, rec.fAlloc, &callbacks, uniforms);
82 return success;
83 }
84 return false;
85}
86
88 buffer.writeString(fEffect->source().c_str());
89 buffer.writeDataAsByteArray(fUniforms.get());
91}
92
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
constexpr bool kLenientSkSLDeserialization
sk_sp< SkRuntimeEffect > SkMakeCachedRuntimeEffect(SkRuntimeEffect::Result(*make)(SkString sksl, const SkRuntimeEffect::Options &), SkString sksl)
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
static sk_sp< const SkCapabilities > RasterBackend()
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
sk_sp< SkRuntimeEffect > effect() const
bool onAppendStages(const SkStageRec &rec) const override
void flatten(SkWriteBuffer &buffer) const override
SkSpan< const SkRuntimeEffect::ChildPtr > children() const
sk_sp< const SkData > uniforms() const
static bool ReadChildEffects(SkReadBuffer &buffer, const SkRuntimeEffect *effect, skia_private::TArray< SkRuntimeEffect::ChildPtr > *children)
static SkSpan< const float > UniformsAsSpan(SkSpan< const SkRuntimeEffect::Uniform > uniforms, sk_sp< const SkData > originalData, bool alwaysCopyIntoAlloc, const SkColorSpace *destColorSpace, SkArenaAlloc *alloc)
static bool CanDraw(const SkCapabilities *, const SkSL::Program *)
static void WriteChildEffects(SkWriteBuffer &buffer, SkSpan< const SkRuntimeEffect::ChildPtr > children)
sk_sp< SkBlender > makeBlender(sk_sp< const SkData > uniforms, SkSpan< const ChildPtr > children={}) const
SkSpan< const Uniform > uniforms() const
static Result MakeForBlender(SkString sksl, const Options &)
const std::string & source() const
T * get() const
Definition: SkRefCnt.h:303
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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
const myers::Point & get(const myers::Segment &)
SkRasterPipeline * fPipeline
Definition: SkEffectPriv.h:21
SkColorSpace * fDstCS
Definition: SkEffectPriv.h:24
SkArenaAlloc * fAlloc
Definition: SkEffectPriv.h:22