Remove redundant data sources.
This commit is contained in:
@@ -39,18 +39,12 @@ source_set("impeller") {
|
||||
]
|
||||
|
||||
image_sources = [
|
||||
"image/DataImageSource.cc",
|
||||
"image/DataImageSource.h",
|
||||
"image/FileImageSource.cc",
|
||||
"image/FileImageSource.h",
|
||||
"image/Image.cc",
|
||||
"image/Image.h",
|
||||
"image/ImageEncoder.cc",
|
||||
"image/ImageEncoder.h",
|
||||
"image/ImageResult.cc",
|
||||
"image/ImageResult.h",
|
||||
"image/ImageSource.cc",
|
||||
"image/ImageSource.h",
|
||||
]
|
||||
|
||||
sources = geometry_sources + entity_sources + image_sources
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#include <Core/Macros.h>
|
||||
#include <Entity/Color.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/Archive.h>
|
||||
#include <Core/Macros.h>
|
||||
#include <Entity/Color.h>
|
||||
#include <Geometry/Matrix.h>
|
||||
#include <Geometry/Path.h>
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the Radar project.
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#include "DataImageSource.h"
|
||||
#include <Core/Message.h>
|
||||
|
||||
namespace rl {
|
||||
namespace image {
|
||||
|
||||
DataImageSource::DataImageSource() {}
|
||||
|
||||
DataImageSource::DataImageSource(core::Allocation allocation)
|
||||
: _allocation(std::move(allocation)) {}
|
||||
|
||||
uint8_t* DataImageSource::sourceData() const {
|
||||
return _allocation.data();
|
||||
}
|
||||
|
||||
size_t DataImageSource::sourceDataSize() const {
|
||||
return _allocation.size();
|
||||
}
|
||||
|
||||
void DataImageSource::onPrepareForUse() {
|
||||
/*
|
||||
* Nothing to do since we already have an explicit allocation.
|
||||
*/
|
||||
}
|
||||
|
||||
void DataImageSource::onDoneUsing() {
|
||||
/*
|
||||
* Nothing to do since we have an explicit allocate and we may need to be
|
||||
* prepared again.
|
||||
*/
|
||||
}
|
||||
|
||||
bool DataImageSource::serialize(core::Message& message) const {
|
||||
return message.encode(_allocation);
|
||||
}
|
||||
|
||||
bool DataImageSource::deserialize(core::Message& message, core::Namespace* ns) {
|
||||
return message.decode(_allocation, ns);
|
||||
}
|
||||
|
||||
ImageSource::Type DataImageSource::type() const {
|
||||
return ImageSource::Type::Data;
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
} // namespace rl
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the Radar project.
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/Allocation.h>
|
||||
#include <Core/Macros.h>
|
||||
#include "ImageSource.h"
|
||||
|
||||
namespace rl {
|
||||
namespace image {
|
||||
|
||||
class DataImageSource : public ImageSource {
|
||||
public:
|
||||
DataImageSource();
|
||||
|
||||
DataImageSource(core::Allocation allocation);
|
||||
|
||||
bool serialize(core::Message& message) const override;
|
||||
|
||||
bool deserialize(core::Message& message, core::Namespace* ns) override;
|
||||
|
||||
private:
|
||||
core::Allocation _allocation;
|
||||
|
||||
ImageSource::Type type() const override;
|
||||
|
||||
uint8_t* sourceData() const override;
|
||||
|
||||
size_t sourceDataSize() const override;
|
||||
|
||||
void onPrepareForUse() override;
|
||||
|
||||
void onDoneUsing() override;
|
||||
|
||||
RL_DISALLOW_COPY_AND_ASSIGN(DataImageSource);
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
} // namespace rl
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the Radar project.
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#include "FileImageSource.h"
|
||||
#include <Core/Message.h>
|
||||
#include <Core/RawAttachment.h>
|
||||
|
||||
namespace rl {
|
||||
namespace image {
|
||||
|
||||
FileImageSource::FileImageSource() {}
|
||||
|
||||
FileImageSource::FileImageSource(core::FileHandle fileHandle)
|
||||
: _handle(std::make_shared<core::FileHandle>(std::move(fileHandle))) {}
|
||||
|
||||
uint8_t* FileImageSource::sourceData() const {
|
||||
return _mapping == nullptr ? nullptr : _mapping->mapping();
|
||||
}
|
||||
|
||||
size_t FileImageSource::sourceDataSize() const {
|
||||
return _mapping == nullptr ? 0 : _mapping->size();
|
||||
}
|
||||
|
||||
void FileImageSource::onPrepareForUse() {
|
||||
if (_handle == nullptr || !_handle->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_mapping = std::make_unique<core::FileMapping>(*_handle);
|
||||
}
|
||||
|
||||
void FileImageSource::onDoneUsing() {
|
||||
_mapping = nullptr;
|
||||
}
|
||||
|
||||
bool FileImageSource::serialize(core::Message& message) const {
|
||||
return message.encode(_handle);
|
||||
}
|
||||
|
||||
bool FileImageSource::deserialize(core::Message& message, core::Namespace* ns) {
|
||||
core::RawAttachment attachment;
|
||||
|
||||
if (!message.decode(attachment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_handle = std::make_shared<core::FileHandle>(std::move(attachment));
|
||||
|
||||
/*
|
||||
* Clear our old mapping if present so we can prepare for another use.
|
||||
*/
|
||||
_mapping = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ImageSource::Type FileImageSource::type() const {
|
||||
return ImageSource::Type::File;
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
} // namespace rl
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the Radar project.
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/FileMapping.h>
|
||||
#include <Core/Macros.h>
|
||||
#include "ImageSource.h"
|
||||
|
||||
namespace rl {
|
||||
namespace image {
|
||||
|
||||
class FileImageSource : public ImageSource {
|
||||
public:
|
||||
FileImageSource();
|
||||
|
||||
FileImageSource(core::FileHandle fileHandle);
|
||||
|
||||
bool serialize(core::Message& message) const override;
|
||||
|
||||
bool deserialize(core::Message& message, core::Namespace* ns) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<core::FileHandle> _handle;
|
||||
std::unique_ptr<core::FileMapping> _mapping;
|
||||
|
||||
ImageSource::Type type() const override;
|
||||
|
||||
uint8_t* sourceData() const override;
|
||||
|
||||
size_t sourceDataSize() const override;
|
||||
|
||||
void onPrepareForUse() override;
|
||||
|
||||
void onDoneUsing() override;
|
||||
|
||||
RL_DISALLOW_COPY_AND_ASSIGN(FileImageSource);
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
} // namespace rl
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#include <Core/Message.h>
|
||||
#include <Image/Image.h>
|
||||
#include <stb_image.h>
|
||||
#include "ImageSource.h"
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/File.h>
|
||||
#include <Core/MessageSerializable.h>
|
||||
#include <Geometry/Size.h>
|
||||
#include <Image/ImageResult.h>
|
||||
|
||||
@@ -15,7 +13,7 @@ namespace image {
|
||||
|
||||
class ImageSource;
|
||||
|
||||
class Image : public core::MessageSerializable {
|
||||
class Image {
|
||||
public:
|
||||
Image();
|
||||
|
||||
@@ -27,10 +25,6 @@ class Image : public core::MessageSerializable {
|
||||
|
||||
ImageResult decode() const;
|
||||
|
||||
bool serialize(core::Message& message) const override;
|
||||
|
||||
bool deserialize(core::Message& message, core::Namespace* ns) override;
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
struct Hash {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/FileIOAdapter.h>
|
||||
#include <Core/Macros.h>
|
||||
#include <Geometry/Size.h>
|
||||
#include <Image/ImageResult.h>
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/Allocation.h>
|
||||
#include <Core/Macros.h>
|
||||
#include <Geometry/Size.h>
|
||||
|
||||
namespace rl {
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the Radar project.
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#include "ImageSource.h"
|
||||
#include "DataImageSource.h"
|
||||
#include "FileImageSource.h"
|
||||
|
||||
namespace rl {
|
||||
namespace image {
|
||||
|
||||
std::unique_ptr<ImageSource> ImageSource::Create(core::Allocation allocation) {
|
||||
return std::make_unique<DataImageSource>(std::move(allocation));
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageSource> ImageSource::Create(core::FileHandle fileHandle) {
|
||||
return std::make_unique<FileImageSource>(std::move(fileHandle));
|
||||
}
|
||||
|
||||
std::shared_ptr<ImageSource> ImageSource::ImageSourceForType(Type type) {
|
||||
switch (type) {
|
||||
case Type::File:
|
||||
return std::make_shared<FileImageSource>();
|
||||
case Type::Data:
|
||||
return std::make_shared<DataImageSource>();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ImageSource::ImageSource() = default;
|
||||
|
||||
ImageSource::~ImageSource() = default;
|
||||
|
||||
void ImageSource::prepareForUse() {
|
||||
if (_prepared) {
|
||||
return;
|
||||
}
|
||||
|
||||
onPrepareForUse();
|
||||
|
||||
_prepared = true;
|
||||
}
|
||||
|
||||
void ImageSource::doneUsing() {
|
||||
if (!_prepared) {
|
||||
return;
|
||||
}
|
||||
|
||||
onDoneUsing();
|
||||
|
||||
_prepared = false;
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
} // namespace rl
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the Radar project.
|
||||
* Licensed under the MIT License. See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/Allocation.h>
|
||||
#include <Core/File.h>
|
||||
#include <Core/Macros.h>
|
||||
|
||||
namespace rl {
|
||||
namespace image {
|
||||
|
||||
class ImageSource : public core::MessageSerializable {
|
||||
public:
|
||||
enum class Type : uint8_t {
|
||||
Unknown,
|
||||
File,
|
||||
Data,
|
||||
};
|
||||
|
||||
static std::unique_ptr<ImageSource> Create(core::Allocation allocation);
|
||||
|
||||
static std::unique_ptr<ImageSource> Create(core::FileHandle fileHandle);
|
||||
|
||||
static std::shared_ptr<ImageSource> ImageSourceForType(Type type);
|
||||
|
||||
ImageSource();
|
||||
|
||||
virtual ~ImageSource();
|
||||
|
||||
void prepareForUse();
|
||||
|
||||
void doneUsing();
|
||||
|
||||
protected:
|
||||
bool _prepared = false;
|
||||
|
||||
friend class Image;
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
virtual uint8_t* sourceData() const = 0;
|
||||
|
||||
virtual size_t sourceDataSize() const = 0;
|
||||
|
||||
virtual void onPrepareForUse() = 0;
|
||||
|
||||
virtual void onDoneUsing() = 0;
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
} // namespace rl
|
||||
Reference in New Issue
Block a user