1 /* 2 * Copyright 2022 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 */ 7 8 #include "include/core/SkPath.h" 9 #include "include/core/SkRefCnt.h" 10 #include "src/gpu/piet/PietTypes.h" 11 12 #ifndef skgpu_piet_Scene_DEFINED 13 #define skgpu_piet_Scene_DEFINED 14 15 namespace skgpu::piet { 16 17 class Scene final : public SkRefCnt, public Object<PgpuScene, pgpu_scene_destroy> { 18 public: Make()19 static sk_sp<Scene> Make() { return sk_sp<Scene>(new Scene()); } 20 21 // Insert a single path with the given transform into the scene. This call can be called 22 // multiple times to populate a scene. The changes will take effect following a successful call 23 // to `finalize()`. 24 // 25 // TODO(b/241580303): This mode of usage requires the entire scene to be rebuilt before (for 26 // even incremental changes) before recording. We should provide an interface for populating the 27 // scene via scene fragments instead. 28 void addPath(const SkPath& path, const Transform& transform); 29 30 // Returns true if there were any pending changes to the scene that were finalized and the scene 31 // is now ready to render. 32 // 33 // Any subsequent calls to modify the scene will clear the scene contents first. 34 bool finalize(); 35 36 private: 37 Scene(); 38 39 class Builder final : public Object<PgpuSceneBuilder, pgpu_scene_builder_finish> { 40 public: Builder(PgpuSceneBuilder * builder)41 explicit Builder(PgpuSceneBuilder* builder) : Object(builder) {} 42 }; 43 44 void initBuilderIfNecessary(); 45 46 std::optional<Builder> fActiveBuilder; 47 }; 48 } // namespace skgpu::piet 49 50 #endif // skgpu_piet_Scene_DEFINED 51