Skip to content

Commit c78adf6

Browse files
committed
Updating headers for latest trunk (1.3 stable)
1 parent f0963ff commit c78adf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3354
-2630
lines changed

AppCore/JSHelpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ class AExport JSString {
4545
/// Create from Ultralight String
4646
JSString(const String& str);
4747

48-
/// Take ownership of existing JSStringRef (will not increase ref-count)
48+
/// Create from existing JSStringRef
4949
JSString(JSStringRef str);
5050

51-
/// Copy constructor (will increase ref-count)
51+
/// Copy constructor
5252
JSString(const JSString& other);
5353

5454
/// Destructor
5555
~JSString();
5656

57-
/// Assignment operator (will increase ref-count)
57+
/// Assignment operator
5858
JSString& operator=(const JSString& other);
5959

6060
/// Cast to String

AppCore/Window.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <Ultralight/RefPtr.h>
1717
#include <Ultralight/Listener.h>
1818
#include <Ultralight/Bitmap.h>
19+
#include <Ultralight/KeyEvent.h>
20+
#include <Ultralight/MouseEvent.h>
21+
#include <Ultralight/ScrollEvent.h>
1922

2023
namespace ultralight {
2124

@@ -34,7 +37,7 @@ class WindowListener {
3437
///
3538
/// Called when the Window is closed.
3639
///
37-
virtual void OnClose(ultralight::Window* window) = 0;
40+
virtual void OnClose(ultralight::Window* window) { }
3841

3942
///
4043
/// Called when the Window is resized.
@@ -43,7 +46,34 @@ class WindowListener {
4346
///
4447
/// @param height The new height (in pixels).
4548
///
46-
virtual void OnResize(ultralight::Window* window, uint32_t width_px, uint32_t height_px) = 0;
49+
virtual void OnResize(ultralight::Window* window, uint32_t width_px, uint32_t height_px) { }
50+
51+
///
52+
/// Called when a keyboard event is fired.
53+
///
54+
/// @param evt Details for the event.
55+
///
56+
/// @return Return false to consume the event and prevent it from propagating further.
57+
///
58+
virtual bool OnKeyEvent(const ultralight::KeyEvent& evt) { return true; }
59+
60+
///
61+
/// Called when a mouse event is fired.
62+
///
63+
/// @param evt Details for the event.
64+
///
65+
/// @return Return false to consume the event and prevent it from propagating further.
66+
///
67+
virtual bool OnMouseEvent(const ultralight::MouseEvent& evt) { return true; }
68+
69+
///
70+
/// Called when a scroll event is fired.
71+
///
72+
/// @param evt Details for the event.
73+
///
74+
/// @return Return false to consume the event and prevent it from propagating further.
75+
///
76+
virtual bool OnScrollEvent(const ultralight::ScrollEvent& evt) { return true; }
4777
};
4878

4979
///

Ultralight/Bitmap.h

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
///
1010
/// Website: <http://ultralig.ht>
1111
///
12-
/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
12+
/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
1313
///
1414
#pragma once
1515
#include <Ultralight/Defines.h>
@@ -18,8 +18,6 @@
1818

1919
namespace ultralight {
2020

21-
#pragma pack(push, 1)
22-
2321
///
2422
/// The various Bitmap formats.
2523
///
@@ -48,6 +46,12 @@ enum class UExport BitmapFormat : uint8_t {
4846
///
4947
#define GetBytesPerPixel(x) (x == BitmapFormat::A8_UNORM ? 1 : 4)
5048

49+
///
50+
/// Forward declaration for the LockedPixels class.
51+
///
52+
template<typename T>
53+
class LockedPixels;
54+
5155
///
5256
/// @brief Bitmap container with basic blitting and conversion routines.
5357
///
@@ -71,6 +75,25 @@ class UExport Bitmap : public RefCounted {
7175
///
7276
static RefPtr<Bitmap> Create(uint32_t width, uint32_t height, BitmapFormat format);
7377

78+
///
79+
/// Create an aligned Bitmap with a certain configuration. Pixels will be allocated but not
80+
/// initialized. Row bytes will be padded to reach the specified alignment.
81+
///
82+
/// @param width The width in pixels.
83+
///
84+
/// @param height The height in pixels.
85+
///
86+
/// @param format The pixel format to use.
87+
///
88+
/// @param alignment The alignment (in bytes) to use. Row bytes will be padded to reach a
89+
/// multiple of this value and the underlying storage will be allocated with
90+
/// this alignment.
91+
///
92+
/// @return A ref-pointer to a new Bitmap instance.
93+
///
94+
static RefPtr<Bitmap> Create(uint32_t width, uint32_t height, BitmapFormat format,
95+
uint32_t alignment);
96+
7497
///
7598
/// Create a Bitmap with existing pixels and configuration.
7699
///
@@ -148,6 +171,14 @@ class UExport Bitmap : public RefCounted {
148171
///
149172
virtual bool owns_pixels() const = 0;
150173

174+
///
175+
/// Lock the pixel buffer for reading/writing (safe version, automatically unlocks).
176+
///
177+
/// @return A managed container that can be used to access the pixels (LockedPixels::data()).
178+
/// This container will automatically unlock the pixels when it goes out of scope.
179+
///
180+
virtual LockedPixels<RefPtr<Bitmap>> LockPixelsSafe() const = 0;
181+
151182
///
152183
/// Lock the pixel buffer for reading/writing.
153184
///
@@ -213,7 +244,7 @@ class UExport Bitmap : public RefCounted {
213244
/// edge pixels from the source bitmap.
214245
///
215246
/// @return Whether or not the operation succeeded (this can fail if the src_rect and/or
216-
/// dest_rect are invalid, or if their total dimensions do not match).
247+
/// dest_rect are invalid).
217248
///
218249
virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr<Bitmap> src, bool pad_repeat)
219250
= 0;
@@ -277,6 +308,62 @@ class UExport Bitmap : public RefCounted {
277308
void operator=(const Bitmap&);
278309
};
279310

280-
#pragma pack(pop)
311+
template <typename T>
312+
class LockedPixels {
313+
public:
314+
LockedPixels(const LockedPixels&) = delete;
315+
LockedPixels& operator=(const LockedPixels&) = delete;
316+
LockedPixels(int) = delete;
317+
explicit LockedPixels(T& lockable) : lockable_(lockable), data_(nullptr), size_(0) { lock(); }
318+
319+
~LockedPixels() {
320+
if (lockable_)
321+
lockable_->UnlockPixels();
322+
}
323+
324+
///
325+
/// Access the locked pixel data.
326+
///
327+
void* data() { return data_; }
328+
329+
///
330+
/// Access the size of the locked pixel data.
331+
///
332+
size_t size() { return size_; }
333+
334+
explicit operator bool() const { return !!lockable_; }
335+
336+
LockedPixels(LockedPixels&& other) : lockable_(other.lockable_), data_(other.data_),
337+
size_(other.size_) {
338+
other.lockable_ = nullptr;
339+
other.data_ = nullptr;
340+
other.size_ = 0;
341+
}
342+
343+
LockedPixels& operator=(LockedPixels&& other) {
344+
if (lockable_)
345+
lockable_->UnlockPixels();
346+
lockable_ = other.lockable_;
347+
data_ = other.data_;
348+
size_ = other.size_;
349+
other.lockable_ = nullptr;
350+
other.data_ = nullptr;
351+
other.size_ = 0;
352+
return *this;
353+
}
354+
355+
private:
356+
void lock() {
357+
if (lockable_) {
358+
data_ = lockable_->LockPixels();
359+
size_ = lockable_->size();
360+
}
361+
}
362+
363+
T lockable_;
364+
void* data_;
365+
size_t size_;
366+
};
367+
281368

282369
} // namespace ultralight

Ultralight/Buffer.h

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,57 @@
99
///
1010
/// Website: <http://ultralig.ht>
1111
///
12-
/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
12+
/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
1313
///
1414
#pragma once
1515
#include <Ultralight/Defines.h>
1616
#include <Ultralight/RefPtr.h>
1717

1818
namespace ultralight {
1919

20+
///
21+
/// Function signature for a user-defined destruction callback to be optionally called when Buffer
22+
/// is destroyed.
23+
///
24+
/// @param user_data Pointer to user-defined user-data (this will be the same value as what was
25+
/// passed to Buffer::Create, if any)
26+
///
27+
/// @param data Pointer to raw Buffer data.
28+
///
29+
typedef void (*DestroyBufferCallback)(void* user_data, void* data);
30+
2031
///
2132
/// A fixed-size byte container for passing data around.
2233
///
2334
class UExport Buffer : public RefCounted {
24-
public:
35+
public:
36+
///
37+
/// Create a Buffer from existing, user-owned data without any copies. An optional, user-supplied
38+
/// callback will be called to deallocate data upon destruction.
39+
///
40+
/// @param data A pointer to the data.
41+
///
42+
/// @param size Size of the data in bytes.
43+
///
44+
/// @param user_data Optional user data that will be passed to destruction_callback
45+
/// when the returned Buffer is destroyed.
46+
///
47+
/// @param destruction_callback Optional callback that will be called upon destruction. Pass a
48+
/// null pointer if you don't want to be informed of destruction.
49+
///
2550
///
26-
/// Create a Buffer, a copy of data is made.
51+
/// @return A ref-counted Buffer object that wraps the existing data.
2752
///
28-
static RefPtr<Buffer> Create(const void* data, size_t size);
53+
static RefPtr<Buffer> Create(void* data, size_t size, void* user_data,
54+
DestroyBufferCallback destruction_callback);
2955

3056
///
31-
/// Get a pointer to raw byte data.
57+
/// Create a Buffer from existing data, a deep copy of data will be made.
58+
///
59+
static RefPtr<Buffer> CreateFromCopy(const void* data, size_t size);
60+
61+
///
62+
/// Get a pointer to the raw byte data.
3263
///
3364
virtual void* data() = 0;
3465

@@ -37,11 +68,23 @@ class UExport Buffer : public RefCounted {
3768
///
3869
virtual size_t size() const = 0;
3970

40-
protected:
71+
///
72+
/// Get the user data associated with this Buffer, if any.
73+
///
74+
virtual void* user_data() = 0;
75+
76+
///
77+
/// Check whether this Buffer owns its own data (Buffer was created via CreateFromCopy).
78+
/// If this is false, Buffer will call the user-supplied destruction callback to deallocate data
79+
/// when this Buffer instance is destroyed.
80+
///
81+
virtual bool owns_data() const = 0;
82+
83+
protected:
4184
Buffer();
4285
virtual ~Buffer();
4386
Buffer(const Buffer&);
4487
void operator=(const Buffer&);
4588
};
4689

47-
} // namespace ultralight
90+
} // namespace ultralight

0 commit comments

Comments
 (0)