Skip to content

Commit

Permalink
Updating headers for current trunk (1.3 beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjs committed Jan 6, 2022
1 parent a221b7f commit f0963ff
Show file tree
Hide file tree
Showing 29 changed files with 665 additions and 814 deletions.
4 changes: 2 additions & 2 deletions AppCore/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AExport App : public RefCounted {
/// @note Certain Config options may be overridden during App creation,
/// most commonly Config::face_winding and Config::device_scale_hint.
///
static Ref<App> Create(Settings settings = Settings(), Config config = Config());
static RefPtr<App> Create(Settings settings = Settings(), Config config = Config());

///
/// Get the App singleton.
Expand Down Expand Up @@ -146,7 +146,7 @@ class AExport App : public RefCounted {
///
/// Get the underlying Renderer instance.
///
virtual Ref<Renderer> renderer() = 0;
virtual RefPtr<Renderer> renderer() = 0;

///
/// Run the main loop.
Expand Down
16 changes: 10 additions & 6 deletions AppCore/CAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

#include <Ultralight/CAPI.h>

#if defined(__WIN32__) || defined(_WIN32)
# if defined(APPCORE_IMPLEMENTATION)
# define ACExport __declspec(dllexport)
#if defined(ULTRALIGHT_STATIC_BUILD)
# define ACExport
#else
# if defined(__WIN32__) || defined(_WIN32)
# if defined(APPCORE_IMPLEMENTATION)
# define ACExport __declspec(dllexport)
# else
# define ACExport __declspec(dllimport)
# endif
# else
# define ACExport __declspec(dllimport)
# define ACExport __attribute__((visibility("default")))
# endif
#else
# define ACExport __attribute__((visibility("default")))
#endif

#ifdef __cplusplus
Expand Down
27 changes: 13 additions & 14 deletions AppCore/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,27 @@
# error This project can only be compiled with a compiler that supports C++11
#endif


#if defined(__WIN32__) || defined(_WIN32)
# if defined(ULTRALIGHT_STATIC_BUILD)
# define AExport
# else
#if defined(ULTRALIGHT_STATIC_BUILD)
# define AExport
#else
# if defined(__WIN32__) || defined(_WIN32)
# if defined(APPCORE_IMPLEMENTATION)
# define AExport __declspec(dllexport)
# else
# define AExport __declspec(dllimport)
# endif
# endif
#define _thread_local __declspec(thread)
#ifndef _NATIVE_WCHAR_T_DEFINED
#define DISABLE_NATIVE_WCHAR_T
#endif
#else
# if defined(ULTRALIGHT_STATIC_BUILD)
# define AExport
# else
# define AExport __attribute__((visibility("default")))
# endif
#define _thread_local __thread
#endif

#if defined(__WIN32__) || defined(_WIN32)
# define _thread_local __declspec(thread)
# ifndef _NATIVE_WCHAR_T_DEFINED
# define DISABLE_NATIVE_WCHAR_T
# endif
#else
# define _thread_local __thread
#endif

#endif
6 changes: 3 additions & 3 deletions AppCore/Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AExport Overlay : public RefCounted {
/// @param y The y-position (offset from the top of the Window), in
/// pixels.
///
static Ref<Overlay> Create(Ref<Window> window, uint32_t width,
static RefPtr<Overlay> Create(RefPtr<Window> window, uint32_t width,
uint32_t height, int x, int y);

///
Expand All @@ -56,12 +56,12 @@ class AExport Overlay : public RefCounted {
/// @param y The y-position (offset from the top of the Window), in
/// pixels.
///
static Ref<Overlay> Create(Ref<Window> window, Ref<View> view, int x, int y);
static RefPtr<Overlay> Create(RefPtr<Window> window, RefPtr<View> view, int x, int y);

///
/// Get the underlying View.
///
virtual ultralight::Ref<ultralight::View> view() = 0;
virtual ultralight::RefPtr<ultralight::View> view() = 0;

///
/// Get the width (in pixels).
Expand Down
2 changes: 1 addition & 1 deletion AppCore/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AExport Window : public RefCounted {
/// @note Screen coordinates are device-scale-independent and have the following relationship
/// to pixel coordinates: pixel_coordinate = round(screen_coordinate * scale)
///
static Ref<Window> Create(Monitor* monitor, uint32_t width, uint32_t height,
static RefPtr<Window> Create(Monitor* monitor, uint32_t width, uint32_t height,
bool fullscreen, unsigned int window_flags);

///
Expand Down
167 changes: 85 additions & 82 deletions Ultralight/Bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,30 @@ namespace ultralight {
///
/// The various Bitmap formats.
///
enum UExport BitmapFormat {
/**
* Alpha channel only, 8-bits per pixel.
*
* Encoding: 8-bits per channel, unsigned normalized.
*
* Color-space: Linear (no gamma), alpha-coverage only.
*/
kBitmapFormat_A8_UNORM,

/**
* Blue Green Red Alpha channels, 32-bits per pixel.
*
* Encoding: 8-bits per channel, unsigned normalized.
*
* Color-space: sRGB gamma with premultiplied linear alpha channel.
*
* NOTE: Alpha is premultiplied with BGR channels _before_ sRGB gamma is
* applied so we can use sRGB conversion hardware and perform all
* blending in linear space on GPU.
*/
kBitmapFormat_BGRA8_UNORM_SRGB,
enum class UExport BitmapFormat : uint8_t {
///
/// Alpha channel only, 8-bits per pixel.
///
/// Encoding: 8-bits per channel, unsigned normalized.
///
/// Color-space: Linear (no gamma), alpha-coverage only.
///
A8_UNORM,

///
/// Blue Green Red Alpha channels, 32-bits per pixel.
///
/// Encoding: 8-bits per channel, unsigned normalized.
///
/// Color-space: sRGB gamma with premultiplied linear alpha channel.
///
BGRA8_UNORM_SRGB,
};

///
/// Macro to get the bytes per pixel from a BitmapFormat
///
#define GetBytesPerPixel(x) (x == kBitmapFormat_A8_UNORM? 1 : 4)
#define GetBytesPerPixel(x) (x == BitmapFormat::A8_UNORM ? 1 : 4)

///
/// @brief Bitmap container with basic blitting and conversion routines.
Expand All @@ -60,11 +56,10 @@ class UExport Bitmap : public RefCounted {
///
/// Create an empty Bitmap. No pixels will be allocated.
///
static Ref<Bitmap> Create();
static RefPtr<Bitmap> Create();

///
/// Create a Bitmap with a certain configuration. Pixels will be allocated
/// but not initialized.
/// Create a Bitmap with a certain configuration. Pixels will be allocated but not initialized.
///
/// @param width The width in pixels.
///
Expand All @@ -74,8 +69,7 @@ class UExport Bitmap : public RefCounted {
///
/// @return A ref-pointer to a new Bitmap instance.
///
static Ref<Bitmap> Create(uint32_t width, uint32_t height,
BitmapFormat format);
static RefPtr<Bitmap> Create(uint32_t width, uint32_t height, BitmapFormat format);

///
/// Create a Bitmap with existing pixels and configuration.
Expand All @@ -86,37 +80,27 @@ class UExport Bitmap : public RefCounted {
///
/// @param format The pixel format to use.
///
/// @param row_bytes The number of bytes between each row (note that this
/// value should be >= width * bytes_per_pixel).
/// @param row_bytes The number of bytes between each row (note that this value should be >=
/// width * bytes_per_pixel).
///
/// @param pixels Pointer to raw pixel buffer.
///
/// @param size Size of the raw pixel buffer.
///
/// @param should_copy Whether or not a copy should be made of the pixels.
/// If this is false, the returned Bitmap will use the
/// raw pixels passed in as its own, but you are still
/// responsible for destroying your buffer afterwards.
///
/// @param fixup_gamma Whether or not we should reinterpret the source
/// as an sRGB bitmap with premultiplied alpha applied
/// after the gamma function (typical of PNGs). We
/// expect all premultiplication to be applied before
/// the gamma function so we can blend properly in
/// linear space. Only valid for
/// kBitmapFormat_BGRA8_UNORM_SRGB.
/// @param should_copy Whether or not a copy should be made of the pixels. If this is false
/// the returned Bitmap will use the raw pixels passed in as its own, but
/// you are still responsible for destroying your buffer afterwards.
///
/// @return A ref-pointer to a new Bitmap instance.
///
static Ref<Bitmap> Create(uint32_t width, uint32_t height,
BitmapFormat format, uint32_t row_bytes,
const void* pixels, size_t size,
bool should_copy = true, bool fixup_gamma = false);
static RefPtr<Bitmap> Create(uint32_t width, uint32_t height, BitmapFormat format,
uint32_t row_bytes, const void* pixels, size_t size,
bool should_copy = true);

///
/// Create a bitmap from a deep copy of another Bitmap.
///
static Ref<Bitmap> Create(const Bitmap& bitmap);
static RefPtr<Bitmap> Create(const Bitmap& bitmap);

///
/// Get the width in pixels.
Expand Down Expand Up @@ -146,8 +130,8 @@ class UExport Bitmap : public RefCounted {
///
/// Get the number of bytes between each row of pixels.
///
/// @note This value is usually calculated as width * bytes_per_pixel (bpp)
/// but it may be larger due to alignment rules in the allocator.
/// @note This value is usually calculated as width * bytes_per_pixel (bpp) but it may be larger
/// due to alignment rules in the allocator.
///
virtual uint32_t row_bytes() const = 0;

Expand All @@ -159,13 +143,13 @@ class UExport Bitmap : public RefCounted {
virtual size_t size() const = 0;

///
/// Whether or not this Bitmap owns the pixel buffer and will destroy it
/// at the end of its lifetime.
/// Whether or not this Bitmap owns the pixel buffer and will destroy it at the end of its
/// lifetime.
///
virtual bool owns_pixels() const = 0;

///
/// Lock the pixel buffer for reading/writing.
/// Lock the pixel buffer for reading/writing.
///
/// @return A pointer to the pixel buffer.
///
Expand Down Expand Up @@ -210,64 +194,83 @@ class UExport Bitmap : public RefCounted {
///
/// @param bitmap The bitmap to copy from.
///
virtual void Set(Ref<Bitmap> bitmap) = 0;
virtual void Set(RefPtr<Bitmap> bitmap) = 0;

///
/// Draw another bitmap to this bitmap.
///
/// @note Formats do not need to match. Bitmap formats will be converted
/// to one another automatically. Note that when converting from
/// BGRA8 to A8, only the Blue channel will be used.
/// @note Formats do not need to match. Bitmap formats will be converted to one another
/// automatically. Note that when converting from BGRA8 to A8, only the Blue channel will
/// be used.
///
/// @param src_rect The source rectangle, relative to src bitmap.
///
/// @param dest_rect The destination rectangle, relative to this bitmap.
///
///
/// @param src The source bitmap.
///
/// @param pad_repeat Whether or not we should pad the drawn bitmap by one
/// pixel of repeated edge pixels from the source bitmap.
///
/// @return Whether or not the operation succeeded (this can fail if the
/// src_rect and/or dest_rect are invalid, or if their total
/// dimensions do not match).
/// @param pad_repeat Whether or not we should pad the drawn bitmap by one pixel of repeated
/// edge pixels from the source bitmap.
///
/// @return Whether or not the operation succeeded (this can fail if the src_rect and/or
/// dest_rect are invalid, or if their total dimensions do not match).
///
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect,
Ref<Bitmap> src, bool pad_repeat) = 0;
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr<Bitmap> src, bool pad_repeat)
= 0;

///
/// Write this Bitmap out to a PNG image. (mainly used for Debug)
/// Write this Bitmap out to a PNG image.
///
/// @param path The filepath to write to (opened with fopen())
///
/// @param convert_to_rgba The PNG format expects RGBA format but our bitmap is stored as BGRA,
/// set this to true to perform the conversion automatically.
///
/// @param convert_to_straight_alpha The PNG format expects semi-transparent values to be
/// stored as straight alpha instead of premultiplied alpha,
/// set this to true to perform the conversion automatically.
///
/// @return Whether or not the operation succeeded.
///
virtual bool WritePNG(const char* path) = 0;
virtual bool WritePNG(const char* path, bool convert_to_rgba = true,
bool convert_to_straight_alpha = true) const = 0;

///
/// Make a resized copy of this bitmap by writing to a pre-allocated
/// destination bitmap.
/// Make a resized copy of this bitmap by writing to a pre-allocated destination bitmap.
///
/// @param destination The bitmap to store the result in, the width and
/// height of the destination will be used.
/// @param destination The bitmap to store the result in, the width and height of the
/// destination will be used.
///
/// @param high_quality Whether or not a high quality resampling will be
/// used during the resize. (Otherwise, just uses fast
/// nearest-neighbor sampling)
/// @param high_quality Whether or not a high quality resampling will be used during the
/// resize. (Otherwise, just uses fast nearest-neighbor sampling)
///
/// @return Whether or not the operation succeeded. This operation is only
/// valid if both formats are kBitmapFormat_BGRA8_UNORM_SRGB and
/// both the source and destination are non-empty.
/// @return Whether or not the operation succeeded. This operation is only valid if both formats
/// are BitmapFormat::BGRA8_UNORM_SRGB and the source and destination are non-empty.
///
virtual bool Resample(Ref<Bitmap> destination, bool high_quality) = 0;
virtual bool Resample(RefPtr<Bitmap> destination, bool high_quality) = 0;

///
/// This converts a BGRA bitmap to RGBA bitmap and vice-versa by swapping
/// the red and blue channels.
/// Convert a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels.
///
/// @note Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB
///
virtual void SwapRedBlueChannels() = 0;

protected:
///
/// Convert a BGRA bitmap from premultiplied alpha (the default) to straight alpha.
///
/// @note Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB
///
virtual void ConvertToStraightAlpha() = 0;

///
/// Convert a BGRA bitmap from straight alpha to premultiplied alpha.
///
/// @note Only valid if the format is BitmapFormat::BGRA8_UNORM_SRGB
///
virtual void ConvertToPremultipliedAlpha() = 0;

protected:
Bitmap();
virtual ~Bitmap();
Bitmap(const Bitmap&);
Expand All @@ -276,4 +279,4 @@ class UExport Bitmap : public RefCounted {

#pragma pack(pop)

} // namespace ultralight
} // namespace ultralight
2 changes: 1 addition & 1 deletion Ultralight/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UExport Buffer : public RefCounted {
///
/// Create a Buffer, a copy of data is made.
///
static Ref<Buffer> Create(const void* data, size_t size);
static RefPtr<Buffer> Create(const void* data, size_t size);

///
/// Get a pointer to raw byte data.
Expand Down
Loading

0 comments on commit f0963ff

Please sign in to comment.