Skip to content

Commit

Permalink
update runtime with file asset cdn information
Browse files Browse the repository at this point in the history
adding core definition bits for out of band assets
also adding a "loadInBandAssets" flag

- [x] get a test in

Diffs=
af873d55a update runtime with file asset cdn information (#6040)

Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
  • Loading branch information
mjtalbot and mjtalbot committed Sep 28, 2023
1 parent c9cc7a6 commit 6b4b5a1
Show file tree
Hide file tree
Showing 29 changed files with 341 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
382a48cf8c79664cc8d5308f2f0a4a504d33b2be
af873d55a4c80c7ba5982186eed4ceb0a0fe579f
32 changes: 31 additions & 1 deletion dev/defs/assets/file_asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@
},
"description": "Size of the asset in bytes",
"runtime": false
},
"exportTypeValue": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 358,
"string": "exporttypevalue"
},
"description": "How to export the asset: embedded, referenced or cdn",
"runtime": false
},
"cdnUuid": {
"type": "Bytes",
"encoded": true,
"key": {
"int": 359,
"string": "cdnuuid"
},
"description": "The cdn uuid if it exists",
"coop": false
},
"cdnBaseUrl": {
"type": "String",
"initialValue": "'https://public.rive.app/cdn/uuid'",
"key": {
"int": 362,
"string": "cdnbaseurl"
},
"description": "Set the base url of our cdn.",
"coop": false
}
}
}
}
18 changes: 18 additions & 0 deletions dev/defs/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
},
"extends": "container_component.json",
"properties": {
"x": {
"type": "double",
"initialValue": "0",
"key": {
"int": 396,
"string": "x"
},
"runtime": false
},
"y": {
"type": "double",
"initialValue": "0",
"key": {
"int": 397,
"string": "y"
},
"runtime": false
},
"trigger": {
"type": "callback",
"animates": true,
Expand Down
12 changes: 11 additions & 1 deletion dev/defs/text/text_value_run.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
"string": "text_value"
},
"description": "The text string value."
},
"fieldHeight": {
"type": "double",
"initialValue": "98.0",
"key": {
"int": 398,
"string": "fieldheight"
},
"runtime": false,
"coop": false
}
}
}
}
11 changes: 9 additions & 2 deletions include/rive/assets/file_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ namespace rive
class Factory;
class FileAsset : public FileAssetBase
{
private:
std::vector<uint8_t> m_cdnUuid;

public:
Span<const uint8_t> cdnUuid() const;

void decodeCdnUuid(Span<const uint8_t> value) override;
void copyCdnUuid(const FileAssetBase& object) override;
virtual bool decode(Span<const uint8_t>, Factory*) = 0;
virtual std::string fileExtension() = 0;
virtual std::string fileExtension() const = 0;
StatusCode import(ImportStack& importStack) override;

std::string uniqueFilename();
std::string uniqueFilename() const;
};
} // namespace rive

Expand Down
2 changes: 1 addition & 1 deletion include/rive/assets/font_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FontAsset : public FontAssetBase
{
public:
bool decode(Span<const uint8_t>, Factory*) override;
std::string fileExtension() override;
std::string fileExtension() const override;
const rcp<Font> font() const { return m_font; }
void font(rcp<Font> font);

Expand Down
2 changes: 1 addition & 1 deletion include/rive/assets/image_asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ImageAsset : public ImageAssetBase
std::size_t decodedByteSize = 0;
#endif
bool decode(Span<const uint8_t>, Factory*) override;
std::string fileExtension() override;
std::string fileExtension() const override;
RenderImage* renderImage() const { return m_RenderImage.get(); }
void renderImage(std::unique_ptr<RenderImage> renderImage);
};
Expand Down
12 changes: 6 additions & 6 deletions include/rive/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "rive/artboard.hpp"
#include "rive/backboard.hpp"
#include "rive/factory.hpp"
#include "rive/file_asset_resolver.hpp"
#include "rive/file_asset_loader.hpp"
#include <vector>
#include <set>

Expand Down Expand Up @@ -55,11 +55,11 @@ class File

Factory* m_Factory;

/// The helper used to resolve assets when they're not provided in-band
/// The helper used to load assets when they're not provided in-band
/// with the file.
FileAssetResolver* m_AssetResolver;
FileAssetLoader* m_AssetLoader;

File(Factory*, FileAssetResolver*);
File(Factory*, FileAssetLoader*);

public:
~File();
Expand All @@ -68,13 +68,13 @@ class File
/// Imports a Rive file from a binary buffer.
/// @param data the raw date of the file.
/// @param result is an optional status result.
/// @param assetResolver is an optional helper to resolve assets which
/// @param assetLoader is an optional helper to load assets which
/// cannot be found in-band.
/// @returns a pointer to the file, or null on failure.
static std::unique_ptr<File> import(Span<const uint8_t> data,
Factory*,
ImportResult* result = nullptr,
FileAssetResolver* assetResolver = nullptr);
FileAssetLoader* assetLoader = nullptr);

/// @returns the file's backboard. All files have exactly one backboard.
Backboard* backboard() const { return m_Backboard.get(); }
Expand Down
32 changes: 32 additions & 0 deletions include/rive/file_asset_loader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef _RIVE_FILE_ASSET_RESOLVER_HPP_
#define _RIVE_FILE_ASSET_RESOLVER_HPP_

#include <cstdint>
#include <vector>

namespace rive
{
class FileAsset;
class FileAssetLoader
{
public:
virtual ~FileAssetLoader() {}

/// The return value sets the intention for handling loading the contents
/// of the given asset. When no asset loader commits to handling the contents
/// we will load assets in band if provided.
///
/// @param asset describes the asset that Rive is looking for the
/// contents of.
virtual bool willLoadContents(FileAsset& asset) {
return true;
}

/// Load the contents of the given asset
///
/// @param asset describes the asset that Rive is looking for the
/// contents of.
virtual void loadContents(FileAsset& asset) = 0;
};
} // namespace rive
#endif
22 changes: 0 additions & 22 deletions include/rive/file_asset_resolver.hpp

This file was deleted.

31 changes: 31 additions & 0 deletions include/rive/generated/assets/file_asset_base.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef _RIVE_FILE_ASSET_BASE_HPP_
#define _RIVE_FILE_ASSET_BASE_HPP_
#include <string>
#include "rive/assets/asset.hpp"
#include "rive/core/field_types/core_bytes_type.hpp"
#include "rive/core/field_types/core_string_type.hpp"
#include "rive/core/field_types/core_uint_type.hpp"
#include "rive/span.hpp"
namespace rive
{
class FileAssetBase : public Asset
Expand Down Expand Up @@ -29,9 +33,12 @@ class FileAssetBase : public Asset
uint16_t coreType() const override { return typeKey; }

static const uint16_t assetIdPropertyKey = 204;
static const uint16_t cdnUuidPropertyKey = 359;
static const uint16_t cdnBaseUrlPropertyKey = 362;

private:
uint32_t m_AssetId = 0;
std::string m_CdnBaseUrl = "https://public.rive.app/cdn/uuid";

public:
inline uint32_t assetId() const { return m_AssetId; }
Expand All @@ -45,9 +52,25 @@ class FileAssetBase : public Asset
assetIdChanged();
}

virtual void decodeCdnUuid(Span<const uint8_t> value) = 0;
virtual void copyCdnUuid(const FileAssetBase& object) = 0;

inline const std::string& cdnBaseUrl() const { return m_CdnBaseUrl; }
void cdnBaseUrl(std::string value)
{
if (m_CdnBaseUrl == value)
{
return;
}
m_CdnBaseUrl = value;
cdnBaseUrlChanged();
}

void copy(const FileAssetBase& object)
{
m_AssetId = object.m_AssetId;
copyCdnUuid(object);
m_CdnBaseUrl = object.m_CdnBaseUrl;
Asset::copy(object);
}

Expand All @@ -58,12 +81,20 @@ class FileAssetBase : public Asset
case assetIdPropertyKey:
m_AssetId = CoreUintType::deserialize(reader);
return true;
case cdnUuidPropertyKey:
decodeCdnUuid(CoreBytesType::deserialize(reader));
return true;
case cdnBaseUrlPropertyKey:
m_CdnBaseUrl = CoreStringType::deserialize(reader);
return true;
}
return Asset::deserialize(propertyKey, reader);
}

protected:
virtual void assetIdChanged() {}
virtual void cdnUuidChanged() {}
virtual void cdnBaseUrlChanged() {}
};
} // namespace rive

Expand Down
7 changes: 7 additions & 0 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ class CoreRegistry
case AssetBase::namePropertyKey:
object->as<AssetBase>()->name(value);
break;
case FileAssetBase::cdnBaseUrlPropertyKey:
object->as<FileAssetBase>()->cdnBaseUrl(value);
break;
}
}
static void setUint(Core* object, int propertyKey, uint32_t value)
Expand Down Expand Up @@ -1179,6 +1182,8 @@ class CoreRegistry
return object->as<CustomPropertyStringBase>()->propertyValue();
case AssetBase::namePropertyKey:
return object->as<AssetBase>()->name();
case FileAssetBase::cdnBaseUrlPropertyKey:
return object->as<FileAssetBase>()->cdnBaseUrl();
}
return "";
}
Expand Down Expand Up @@ -1708,6 +1713,7 @@ class CoreRegistry
case TextValueRunBase::textPropertyKey:
case CustomPropertyStringBase::propertyValuePropertyKey:
case AssetBase::namePropertyKey:
case FileAssetBase::cdnBaseUrlPropertyKey:
return CoreStringType::id;
case ComponentBase::parentIdPropertyKey:
case DrawTargetBase::drawableIdPropertyKey:
Expand Down Expand Up @@ -1957,6 +1963,7 @@ class CoreRegistry
case GradientStopBase::colorValuePropertyKey:
return CoreColorType::id;
case MeshBase::triangleIndexBytesPropertyKey:
case FileAssetBase::cdnUuidPropertyKey:
case FileAssetContentsBase::bytesPropertyKey:
return CoreBytesType::id;
default:
Expand Down
9 changes: 4 additions & 5 deletions include/rive/importers/file_asset_importer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ namespace rive
{
class FileAsset;
class FileAssetContents;
class FileAssetResolver;
class FileAssetLoader;
class Factory;

class FileAssetImporter : public ImportStackObject
{
private:
bool m_LoadedContents = false;
FileAsset* m_FileAsset;
FileAssetResolver* m_FileAssetResolver;
FileAssetLoader* m_FileAssetLoader;
Factory* m_Factory;
// we will delete this when we go out of scope
std::unique_ptr<FileAssetContents> m_Content;

public:
FileAssetImporter(FileAsset*, FileAssetResolver*, Factory*);
void loadContents(std::unique_ptr<FileAssetContents> contents);
FileAssetImporter(FileAsset*, FileAssetLoader*, Factory*);
void onFileAssetContents(std::unique_ptr<FileAssetContents> contents);
StatusCode resolve() override;
};
} // namespace rive
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _RIVE_RELATIVE_LOCAL_ASSET_RESOLVER_HPP_
#define _RIVE_RELATIVE_LOCAL_ASSET_RESOLVER_HPP_

#include "rive/file_asset_resolver.hpp"
#include "rive/file_asset_loader.hpp"
#include "rive/assets/file_asset.hpp"
#include <cstdio>
#include <string>
Expand All @@ -11,16 +11,16 @@ namespace rive
class FileAsset;
class Factory;

/// An implementation of FileAssetResolver which finds the assets in a local
/// An implementation of FileAssetLoader which finds the assets in a local
/// path relative to the original .riv file looking for them.
class RelativeLocalAssetResolver : public FileAssetResolver
class RelativeLocalAssetLoader : public FileAssetLoader
{
private:
std::string m_Path;
Factory* m_Factory;

public:
RelativeLocalAssetResolver(std::string filename, Factory* factory) : m_Factory(factory)
RelativeLocalAssetLoader(std::string filename, Factory* factory) : m_Factory(factory)
{
std::size_t finalSlash = filename.rfind('/');

Expand Down
Loading

0 comments on commit 6b4b5a1

Please sign in to comment.