diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index d6473009ac..1de0f1cfd9 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -686,18 +686,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) { // TODO: Maybe rename this to AS_UPLOAD_PICTURE ? STRACE(("ServerApp %s: Create Picture\n", Signature())); + status_t status = B_ERROR; ServerPicture *picture = CreatePicture(); - if (picture != NULL) { - int32 subPicturesCount = 0; - link.Read(&subPicturesCount); - for (int32 c = 0; c < subPicturesCount; c++) { - // TODO: Support nested pictures - } - - int32 size = 0; - link.Read(&size); - link.Read(const_cast(picture->Data()), size); - + if (picture != NULL) + status = picture->ImportData(link); + + if (status == B_OK) { fLink.StartMessage(B_OK); fLink.Attach(picture->Token()); } else diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index bcda259417..aec0b8eaee 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -15,6 +15,7 @@ #include "ViewLayer.h" #include "WindowLayer.h" +#include #include #include #include @@ -661,3 +662,27 @@ ServerPicture::Play(ViewLayer *view) PicturePlayer player(const_cast(fData.Buffer()), fData.BufferLength(), NULL); player.Play(const_cast(tableEntries), sizeof(tableEntries) / sizeof(void *), view); } + + +status_t +ServerPicture::ImportData(BPrivate::LinkReceiver &link) +{ + int32 subPicturesCount = 0; + link.Read(&subPicturesCount); + for (int32 c = 0; c < subPicturesCount; c++) { + // TODO: Support nested pictures + } + + int32 size = 0; + link.Read(&size); + if (fData.SetSize(size) != B_OK) + return B_ERROR; + + // TODO: The best way to do this would be to read the data into + // a temporary buffer, and then use the BMallocIO::Write() method, + // but this way we avoid an extra copy. Unfortunately BMallocIO::Write() + // only accepts a pointer to raw data... + link.Read(const_cast(fData.Buffer()), size); + + return B_OK; +} diff --git a/src/servers/app/ServerPicture.h b/src/servers/app/ServerPicture.h index c114cbb478..867f808fe3 100644 --- a/src/servers/app/ServerPicture.h +++ b/src/servers/app/ServerPicture.h @@ -7,6 +7,7 @@ class ServerApp; class ViewLayer; +class BPrivate::LinkReceiver; class ServerPicture : public PictureDataWriter { public: int32 Token() { return fToken; } @@ -23,6 +24,8 @@ public: const void *Data() const { return fData.Buffer(); } int32 DataLength() const { return fData.BufferLength(); } + + status_t ImportData(BPrivate::LinkReceiver &link); private: friend class ServerApp; @@ -30,7 +33,7 @@ friend class ServerApp; ServerPicture(); ServerPicture(const ServerPicture &); ~ServerPicture(); - + int32 fToken; BMallocIO fData; // DrawState *fState;