All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
changes.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_PCP_CHANGES_H
25 #define PXR_USD_PCP_CHANGES_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/pcp/api.h"
31 #include "pxr/usd/sdf/changeList.h"
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/usd/sdf/types.h"
36 #include "pxr/base/tf/span.h"
37 
38 #include <map>
39 #include <set>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 SDF_DECLARE_HANDLES(SdfLayer);
45 
46 class PcpCache;
47 class PcpSite;
48 
54 public:
57 
60 
63 
70 
77  SdfRelocatesMap newRelocatesSourceToTarget;
78  SdfRelocatesMap newIncrementalRelocatesSourceToTarget;
79  SdfRelocatesMap newIncrementalRelocatesTargetToSource;
80  SdfPathVector newRelocatesPrimPaths;
81 
84 
86  didChangeLayers(false),
87  didChangeLayerOffsets(false),
88  didChangeRelocates(false),
90  {}
91 };
92 
98 public:
99  enum TargetType {
100  TargetTypeConnection = 1 << 0,
101  TargetTypeRelationshipTarget = 1 << 1
102  };
103 
108 
110  SdfPathSet didChangeSpecs;
111 
114  SdfPathSet didChangePrims;
115 
117  std::map<SdfPath, int, SdfPath::FastLessThan> didChangeTargets;
118 
123  std::vector<std::pair<SdfPath, SdfPath>> didChangePath;
124 
126  bool didMaybeChangeLayers = false;
127 
128 private:
129  friend class PcpCache;
130  friend class PcpChanges;
131 
132  // Must rebuild the prim/property stacks at each path due to a change
133  // that only affects the internal representation of the stack and
134  // not its contents. Because this causes no externally-observable
135  // changes in state, clients do not need to be aware of these changes.
136  SdfPathSet _didChangeSpecsInternal;
137 };
138 
141 class PcpLifeboat {
142 public:
143  PcpLifeboat();
144  ~PcpLifeboat();
145 
147  void Retain(const SdfLayerRefPtr& layer);
148 
150  void Retain(const PcpLayerStackRefPtr& layerStack);
151 
154  const std::set<PcpLayerStackRefPtr>& GetLayerStacks() const;
155 
157  void Swap(PcpLifeboat& other);
158 
159 private:
160  std::set<SdfLayerRefPtr> _layers;
161  std::set<PcpLayerStackRefPtr> _layerStacks;
162 };
163 
173 class PcpChanges {
174 public:
175  PCP_API PcpChanges();
176  PCP_API ~PcpChanges();
177 
185  PCP_API
186  void DidChange(const TfSpan<const PcpCache*> &caches,
187  const SdfLayerChangeListVec& changes);
188 
193  PCP_API
194  void DidMaybeFixSublayer(const PcpCache* cache,
195  const SdfLayerHandle& layer,
196  const std::string& assetPath);
197 
200  PCP_API
201  void DidMaybeFixAsset(const PcpCache* cache,
202  const PcpSite& site,
203  const SdfLayerHandle& srcLayer,
204  const std::string& assetPath);
205 
207  PCP_API
208  void DidMuteLayer(const PcpCache* cache, const std::string& layerId);
209 
211  PCP_API
212  void DidUnmuteLayer(const PcpCache* cache, const std::string& layerId);
213 
218  PCP_API
219  void DidChangeLayers(const PcpCache* cache);
220 
222  PCP_API
223  void DidChangeLayerOffsets(const PcpCache* cache);
224 
229  PCP_API
230  void DidChangeSignificantly(const PcpCache* cache, const SdfPath& path);
231 
237  PCP_API
238  void DidChangeSpecs(const PcpCache* cache, const SdfPath& path,
239  const SdfLayerHandle& changedLayer,
240  const SdfPath& changedPath);
241 
244  PCP_API
245  void DidChangeSpecStack(const PcpCache* cache, const SdfPath& path);
246 
249  PCP_API
250  void DidChangeTargets(const PcpCache* cache, const SdfPath& path,
251  PcpCacheChanges::TargetType targetType);
252 
255  PCP_API
256  void DidChangeRelocates(const PcpCache* cache, const SdfPath& path);
257 
263  PCP_API
264  void DidChangePaths(const PcpCache* cache,
265  const SdfPath& oldPath, const SdfPath& newPath);
266 
268  PCP_API
269  void DidDestroyCache(const PcpCache* cache);
270 
275  PCP_API
276  void DidChangeAssetResolver(const PcpCache* cache);
277 
279  PCP_API
280  void Swap(PcpChanges& other);
281 
283  PCP_API
284  bool IsEmpty() const;
285 
286  typedef std::map<PcpLayerStackPtr, PcpLayerStackChanges> LayerStackChanges;
287  typedef std::map<PcpCache*, PcpCacheChanges> CacheChanges;
288 
291  PCP_API
292  const LayerStackChanges& GetLayerStackChanges() const;
293 
295  PCP_API
296  const CacheChanges& GetCacheChanges() const;
297 
302  PCP_API
303  const PcpLifeboat& GetLifeboat() const;
304 
306  PCP_API
307  void Apply() const;
308 
309 private:
310  // Internal data types for namespace edits from Sd.
311  typedef std::map<SdfPath, SdfPath> _PathEditMap;
312  typedef std::map<PcpCache*, _PathEditMap> _RenameChanges;
313 
314  // Returns the PcpLayerStackChanges for the given cache's layer stack.
315  PcpLayerStackChanges& _GetLayerStackChanges(const PcpCache* cache);
316 
317  // Returns the PcpLayerStackChanges for the given layer stack.
318  PcpLayerStackChanges& _GetLayerStackChanges(const PcpLayerStackPtr&);
319 
320  // Returns the PcpCacheChanges for the given cache.
321  PcpCacheChanges& _GetCacheChanges(const PcpCache* cache);
322 
323  // Returns the _PathEditMap for the given cache.
324  _PathEditMap& _GetRenameChanges(const PcpCache* cache);
325 
326 
327  // Optimize the changes.
328  void _Optimize() const;
329 
330  // Optimize the changes.
331  void _Optimize();
332 
333  // Optimize the changes for a given cache.
334  void _Optimize(PcpCacheChanges*);
335 
336  // Optimize path changes.
337  void _OptimizePathChanges(const PcpCache* cache, PcpCacheChanges* changes,
338  const _PathEditMap* pathChanges);
339 
340  // Sublayer change type for _DidChangeSublayer.
341  enum _SublayerChangeType {
342  _SublayerAdded,
343  _SublayerRemoved
344  };
345 
346  // Helper function for loading a sublayer of \p layer at \p sublayerPath
347  // for processing changes described by \p sublayerChange.
348  SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
349  const SdfLayerHandle& layer,
350  const std::string& sublayerPath,
351  _SublayerChangeType changeType) const;
352 
353  // Helper function for loading a sublayer at \p sublayerPath
354  // for processing changes described by \p sublayerChange.
355  SdfLayerRefPtr _LoadSublayerForChange(const PcpCache* cache,
356  const std::string& sublayerPath,
357  _SublayerChangeType changeType) const;
358 
359  // Propagates changes to \p sublayer specified by \p sublayerChange to
360  // the dependents of that sublayer. This includes all layer stacks
361  // that include the sublayer.
362  void _DidChangeSublayerAndLayerStacks(const PcpCache* cache,
363  const PcpLayerStackPtrVector& stacks,
364  const std::string& sublayerPath,
365  const SdfLayerHandle& sublayer,
366  _SublayerChangeType sublayerChange,
367  std::string* debugSummary);
368 
369  // Propagates changes to \p sublayer specified by \p sublayerChange to
370  // the dependents of that sublayer.
371  void _DidChangeSublayer(const PcpCache* cache,
372  const PcpLayerStackPtrVector& layerStacks,
373  const std::string& sublayerPath,
374  const SdfLayerHandle& sublayer,
375  _SublayerChangeType sublayerChange,
376  std::string* debugSummary,
377  bool *significant);
378 
379  // Mark the layer stack as having changed.
380  void _DidChangeLayerStack(
381  const TfSpan<const PcpCache*>& caches,
382  const PcpLayerStackPtr& layerStack,
383  bool requiresLayerStackChange,
384  bool requiresLayerStackOffsetsChange,
385  bool requiresSignificantChange);
386 
387  // Mark the layer stack's relocations as having changed.
388  // Recompute the new relocations, storing the result in the Changes,
389  // so that change-processing can determine which other caches it
390  // needs to invalidate.
391  void _DidChangeLayerStackRelocations(
392  const TfSpan<const PcpCache*>& caches,
393  const PcpLayerStackPtr & layerStack,
394  std::string* debugSummary);
395 
396  // Register changes to any prim indexes in \p caches that are affected
397  // by a change to a layer's resolved path used by \p layerStack.
398  void _DidChangeLayerStackResolvedPath(
399  const TfSpan<const PcpCache*>& caches,
400  const PcpLayerStackPtr& layerStack,
401  std::string* debugSummary);
402 
403  // The spec stack for the prim or property index at \p path must be
404  // recomputed due to a change that affects only the internal representation
405  // of the stack and not its contents.
406  void _DidChangeSpecStackInternal(
407  const PcpCache* cache, const SdfPath& path);
408 
409 private:
410  LayerStackChanges _layerStackChanges;
411  CacheChanges _cacheChanges;
412  _RenameChanges _renameChanges;
413  mutable PcpLifeboat _lifeboat;
414 };
415 
416 PXR_NAMESPACE_CLOSE_SCOPE
417 
418 #endif // PXR_USD_PCP_CHANGES_H
std::vector< std::pair< SdfPath, SdfPath > > didChangePath
Must update the path on every namespace object at and below each given path.
Definition: changes.h:123
A unit of scene description that you combine with other units of scene description to form a shot...
Definition: layer.h:96
bool didChangeSignificantly
A significant layer stack change means the composed opinions of the layer stack may have changed in a...
Definition: changes.h:69
Standard pointer typedefs.
std::map< SdfPath, SdfPath > SdfRelocatesMap
A map of source SdfPaths to target SdfPaths for relocation.
Definition: types.h:293
Represents a stack of layers that contribute opinions to composition.
Definition: layerStack.h:65
PCP_API const LayerStackChanges & GetLayerStackChanges() const
Returns a map of all of the layer stack changes.
Describes Pcp changes.
Definition: changes.h:173
bool didChangeLayers
Must rebuild the layer tree. Implies didChangeLayerOffsets.
Definition: changes.h:56
PCP_API void DidMaybeFixAsset(const PcpCache *cache, const PcpSite &site, const SdfLayerHandle &srcLayer, const std::string &assetPath)
Tries to load the asset at assetPath.
bool didChangeLayerOffsets
Must rebuild the layer offsets.
Definition: changes.h:59
PcpCache is the context required to make requests of the Pcp composition algorithm and cache the resu...
Definition: cache.h:93
PCP_API void DidChangePaths(const PcpCache *cache, const SdfPath &oldPath, const SdfPath &newPath)
The composed object at oldPath was moved to newPath.
A site specifies a path in a layer stack of scene description.
Definition: site.h:46
PCP_API void Swap(PcpChanges &other)
Swap the contents of this and other.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
PCP_API void DidUnmuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was unmuted in cache.
Basic Sdf data types.
PCP_API void DidChangeLayers(const PcpCache *cache)
The sublayer tree changed.
SdfPathSet didChangeSpecs
Must rebuild the prim/property stacks at each path.
Definition: changes.h:110
PCP_API void DidMaybeFixSublayer(const PcpCache *cache, const SdfLayerHandle &layer, const std::string &assetPath)
Tries to load the sublayer of layer at sublayerPath.
PCP_API void DidChangeAssetResolver(const PcpCache *cache)
The asset resolver has changed, invalidating previously-resolved asset paths.
SdfPathSet didChangeSignificantly
Must rebuild the indexes at and below each path.
Definition: changes.h:107
SdfPathSet pathsAffectedByRelocationChanges
Paths that are affected by the above relocation changes.
Definition: changes.h:83
PCP_API void DidMuteLayer(const PcpCache *cache, const std::string &layerId)
The layer identified by layerId was muted in cache.
Represents a range of contiguous elements.
Definition: span.h:87
Types of changes per layer stack.
Definition: changes.h:53
std::map< SdfPath, int, SdfPath::FastLessThan > didChangeTargets
Must rebuild the connections/targets at each path.
Definition: changes.h:117
PCP_API void DidChangeSpecStack(const PcpCache *cache, const SdfPath &path)
The spec stack for the prim or property at path in cache has changed.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
Types of changes per cache.
Definition: changes.h:97
void Swap(PcpLifeboat &other)
Swap the contents of this and other.
PCP_API void DidChangeRelocates(const PcpCache *cache, const SdfPath &path)
The relocates that affect prims and properties at and below the given cache path have changed...
PCP_API void Apply() const
Applies the changes to the layer stacks and caches.
PCP_API void DidDestroyCache(const PcpCache *cache)
Remove any changes for cache.
bool didMaybeChangeLayers
Layers used in the composition may have changed.
Definition: changes.h:126
bool didChangeRelocates
Must rebuild the relocation tables.
Definition: changes.h:62
SdfRelocatesMap newRelocatesTargetToSource
New relocation maps for this layer stack.
Definition: changes.h:76
void Retain(const SdfLayerRefPtr &layer)
Ensure that layer exists until this object is destroyed.
PCP_API bool IsEmpty() const
Returns true iff there are no changes.
PCP_API void DidChangeLayerOffsets(const PcpCache *cache)
The sublayer offsets changed.
PCP_API void DidChangeSignificantly(const PcpCache *cache, const SdfPath &path)
The object at path changed significantly enough to require recomputing the entire prim or property in...
const std::set< PcpLayerStackRefPtr > & GetLayerStacks() const
Returns reference to the set of layer stacks currently being held in the lifeboat.
Structure used to temporarily retain layers and layerStacks within a code block.
Definition: changes.h:141
PCP_API void DidChange(const TfSpan< const PcpCache * > &caches, const SdfLayerChangeListVec &changes)
Breaks down changes into individual changes on the caches in caches.
PCP_API const PcpLifeboat & GetLifeboat() const
Returns the lifeboat responsible for maintaining the lifetime of layers and layer stacks during chang...
PCP_API void DidChangeSpecs(const PcpCache *cache, const SdfPath &path, const SdfLayerHandle &changedLayer, const SdfPath &changedPath)
The spec stack for the prim or property has changed, due to the addition or removal of the spec in ch...
PCP_API void DidChangeTargets(const PcpCache *cache, const SdfPath &path, PcpCacheChanges::TargetType targetType)
The connections on the attribute or targets on the relationship have changed.
PCP_API const CacheChanges & GetCacheChanges() const
Returns a map of all of the cache changes.
SdfPathSet didChangePrims
Must rebuild the prim indexes at each path.
Definition: changes.h:114