Skip to content

Commit e2f3e09

Browse files
Zardshardpulkomandy
authored andcommitted
Make ShareableBitmapHaiku not depend on SharedMemoryHaiku
This lets us use UNIX's or Haiku's implementation of shared memory. SharedMemoryHaiku is not fully implemented at present and this allows us to avoid using it. Unfortunately, we lose the method of uniquely identifying bitmaps that we used previously, since the previous method relies on Haiku's implementation of shared memory to store the id. This will have to be implemented in some way in the future.
1 parent e9ecc18 commit e2f3e09

File tree

3 files changed

+36
-48
lines changed

3 files changed

+36
-48
lines changed

Source/WebCore/platform/graphics/haiku/HaikuUtilities.cpp

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,16 @@
2828

2929
#if PLATFORM(HAIKU)
3030

31-
#include "Logging.h"
32-
33-
#include <Bitmap.h>
34-
#include <optional>
35-
#include <OS.h>
36-
#include <wtf/persistence/PersistentDecoder.h>
37-
#include <wtf/text/Base64.h>
38-
#include <wtf/text/WTFString.h>
31+
#include "NotImplemented.h"
3932

4033
namespace WebCore{
4134

4235
uintptr_t getBitmapUniqueID(BBitmap* bitmap)
4336
{
4437
// Gets a unique identifier to a bitmap that is same across processes.
45-
// This version gets the id from the id attached to the image's area's name
46-
// by SharedMemory::allocate
47-
48-
area_id area = bitmap->Area();
49-
50-
area_info info;
51-
status_t status = get_area_info(area, &info);
52-
53-
std::optional<uint64_t> decodedID;
54-
if (status == B_OK) {
55-
auto base64Data = WTF::String::fromLatin1(&info.name[7]);
56-
auto data = WTF::base64Decode(base64Data);
57-
WTF::Persistence::Decoder decoder({ data->data(), data->size() });
58-
decoder >> decodedID;
59-
}
60-
61-
if (decodedID) {
62-
// FIXME: This code is untested. This can be remove once tested.
63-
LOG(Compositing, "Found image ID %ld", *decodedID);
64-
return *decodedID;
65-
} else {
66-
LOG(Compositing, "Failed to find image id for BBitmap. Falling back to 0");
67-
return 0;
68-
}
38+
debugger("getBitmapUniqueID needs to be implemented");
39+
notImplemented();
40+
return 0;
6941
}
7042

7143
} // namespace WebCore

Source/WebCore/platform/graphics/haiku/ShareableBitmapHaiku.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,37 @@ void ShareableBitmap::paint(GraphicsContext& context, float scaleFactor, const I
7171

7272
WebCore::PlatformImagePtr ShareableBitmap::createPlatformImage(WebCore::BackingStoreCopy, WebCore::ShouldInterpolate)
7373
{
74-
// FIXME: This doesn't work with UNIX's implementation of shared memory atm.
75-
// Or should we use Haiku's implementation of shared memory instead?
76-
// NOTE: getBitmapUniqueID depends on bitmaps always being at offset 0 in
77-
// their area.
78-
// return WebCore::PlatformImagePtr(new BitmapRef(m_sharedMemory->area(), 0, bounds(), 0, /*m_configuration.platformColorSpace()*/ B_RGBA32, bytesPerRow()));
79-
80-
debugger("ShareableBitmap::createPlatformImage is unimplemented");
81-
return nullptr;
74+
// Creates a BBitmap (actually BitmapRef) that reads image data from the
75+
// address given by data(). This address is in shared memory. The idea is
76+
// that multiple processes can point to the same underlying bitmap data.
77+
// One can draw, and the other can display.
78+
79+
status_t status;
80+
81+
// Get area id of shared memory
82+
void* address = data();
83+
area_id area = area_for(address);
84+
ASSERT(area >= B_OK);
85+
86+
// Get offset in area to put our BBitmap
87+
area_info areaInfo;
88+
status = get_area_info(area, &areaInfo);
89+
ASSERT(status == B_OK);
90+
ptrdiff_t offset = (ptrdiff_t)address - (ptrdiff_t)areaInfo.address;
91+
92+
#if USE(UNIX_DOMAIN_SOCKETS)
93+
// We are on UNIX's implementation of shared memory. UNIX's shared memory
94+
// doesn't have B_CLONEABLE_AREA by default. We need it enabled so that the
95+
// app server can clone it and manipulate the bitmap.
96+
status = set_area_protection(area, B_READ_AREA | B_WRITE_AREA | B_CLONEABLE_AREA);
97+
ASSERT(status == B_OK);
98+
#endif
99+
100+
// Create the BBitmap
101+
WebCore::PlatformImagePtr image = adoptRef(new BitmapRef(
102+
area, offset, bounds(), B_BITMAP_ACCEPTS_VIEWS, /*m_configuration.platformColorSpace()*/ B_RGBA32, bytesPerRow()));
103+
104+
return image;
82105
}
83106

84107
RefPtr<Image> ShareableBitmap::createImage()

Source/WebCore/platform/haiku/SharedMemoryHaiku.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,9 @@ namespace WebCore {
4242

4343
RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
4444
{
45-
// Make the area's name include a randomnly generated id so that
46-
// identifying whether two areas point to the same memory across processes
47-
// is easier. Do not change the format of this string without changing all
48-
// of the places that depend on this format. (Hint: check all usages of
49-
// get_area_info to see if they use the name)
50-
uint64_t id = ((uint64_t) weakRandomNumber<uint32_t>() << 32) | weakRandomNumber<uint32_t>();
51-
auto name = makeString("WebKit-", base64Encoded(&id, sizeof(id)));
5245
void* baseAddress;
5346

54-
area_id sharedArea = create_area(name.ascii().data(), &baseAddress,
47+
area_id sharedArea = create_area("WebKit shared memory", &baseAddress,
5548
B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA | B_CLONEABLE_AREA);
5649

5750
if (sharedArea < 0)

0 commit comments

Comments
 (0)