ServerPicture now uses a BPositionIO object as internal storage instead

of BMallocIO. Added an additional constructor to handle a file. This is 
in preparation of implementing BView::SetDiskMode().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20996 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-05-03 14:52:13 +00:00
parent 7f66887bc3
commit ff32e5158c
6 changed files with 126 additions and 24 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
SubDir HAIKU_TOP src servers app ; SubDir HAIKU_TOP src servers app ;
UseLibraryHeaders png zlib ; UseLibraryHeaders png zlib ;
UsePrivateHeaders app graphics input interface kernel shared ; UsePrivateHeaders app graphics input interface kernel shared storage ;
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing ] ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing ] ;
UseFreeTypeHeaders ; UseFreeTypeHeaders ;
+2 -6
View File
@@ -740,12 +740,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
link.Read<int32>(&token); link.Read<int32>(&token);
ServerPicture *picture = FindPicture(token); ServerPicture *picture = FindPicture(token);
if (picture != NULL) { if (picture != NULL) {
fLink.StartMessage(B_OK); picture->ExportData(fLink);
// ExportData() calls StartMessage() already
// TODO: support nested pictures (subpictures)
fLink.Attach<int32>(0); // number of subpictures
fLink.Attach<int32>(picture->DataLength());
fLink.Attach(picture->Data(), picture->DataLength());
} else } else
fLink.StartMessage(B_ERROR); fLink.StartMessage(B_ERROR);
+115 -11
View File
@@ -17,8 +17,10 @@
#include "WindowLayer.h" #include "WindowLayer.h"
#include <LinkReceiver.h> #include <LinkReceiver.h>
#include <OffsetFile.h>
#include <PicturePlayer.h> #include <PicturePlayer.h>
#include <PictureProtocol.h> #include <PictureProtocol.h>
#include <PortLink.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
#include <ShapePrivate.h> #include <ShapePrivate.h>
@@ -661,23 +663,61 @@ const void *tableEntries[] = {
// ServerPicture // ServerPicture
ServerPicture::ServerPicture() ServerPicture::ServerPicture()
:PictureDataWriter(&fData) :
PictureDataWriter(),
fData(NULL)
{ {
fToken = gTokenSpace.NewToken(kPictureToken, this); fToken = gTokenSpace.NewToken(kPictureToken, this);
fData = new (std::nothrow) BMallocIO();
PictureDataWriter::SetTo(fData);
} }
ServerPicture::ServerPicture(const ServerPicture &picture) ServerPicture::ServerPicture(const ServerPicture &picture)
:PictureDataWriter(&fData) :
PictureDataWriter(),
fData(NULL)
{ {
fToken = gTokenSpace.NewToken(kPictureToken, this); fToken = gTokenSpace.NewToken(kPictureToken, this);
fData.Write(picture.Data(), picture.DataLength()); BMallocIO *mallocIO = new (std::nothrow) BMallocIO();
if (mallocIO == NULL)
return;
fData = mallocIO;
const off_t size = picture.DataLength();
if (mallocIO->SetSize(size) < B_OK)
return;
picture.fData->ReadAt(0, const_cast<void *>(mallocIO->Buffer()), size);
PictureDataWriter::SetTo(fData);
}
ServerPicture::ServerPicture(const char *fileName, const int32 &offset)
:
PictureDataWriter(),
fData(NULL)
{
BPrivate::Storage::OffsetFile *file =
new BPrivate::Storage::OffsetFile(new BFile(fileName, B_READ_WRITE), (off_t)offset);
if (file == NULL || file->InitCheck() != B_OK)
return;
fData = file;
fToken = gTokenSpace.NewToken(kPictureToken, this);
PictureDataWriter::SetTo(fData);
} }
ServerPicture::~ServerPicture() ServerPicture::~ServerPicture()
{ {
delete fData;
gTokenSpace.RemoveToken(fToken); gTokenSpace.RemoveToken(fToken);
} }
@@ -717,11 +757,30 @@ ServerPicture::SyncState(ViewLayer *view)
void void
ServerPicture::Play(ViewLayer *view) ServerPicture::Play(ViewLayer *view)
{ {
PicturePlayer player(fData.Buffer(), fData.BufferLength(), NULL); // TODO: for now: then change PicturePlayer to accept a BPositionIO object
BMallocIO *mallocIO = dynamic_cast<BMallocIO *>(fData);
if (mallocIO == NULL)
return;
PicturePlayer player(mallocIO->Buffer(), mallocIO->BufferLength(), NULL);
player.Play(const_cast<void **>(tableEntries), sizeof(tableEntries) / sizeof(void *), view); player.Play(const_cast<void **>(tableEntries), sizeof(tableEntries) / sizeof(void *), view);
} }
off_t
ServerPicture::DataLength() const
{
if (fData == NULL)
return 0;
off_t size;
fData->GetSize(&size);
return size;
}
#define BUFFER_SIZE 4096
status_t status_t
ServerPicture::ImportData(BPrivate::LinkReceiver &link) ServerPicture::ImportData(BPrivate::LinkReceiver &link)
{ {
@@ -733,14 +792,59 @@ ServerPicture::ImportData(BPrivate::LinkReceiver &link)
int32 size = 0; int32 size = 0;
link.Read<int32>(&size); link.Read<int32>(&size);
if (fData.SetSize(size) != B_OK)
return B_ERROR;
// TODO: The best way to do this would be to read the data into off_t oldPosition = fData->Position();
// a temporary buffer, and then use the BMallocIO::Write() method, fData->Seek(0, SEEK_SET);
// but this way we avoid an extra copy. Unfortunately BMallocIO::Write()
// only accepts a pointer to raw data... ssize_t toWrite = size;
link.Read(const_cast<void *>(fData.Buffer()), size); // TODO: For some reason, this doesn't work. Bug in LinkReceiver ?
/*char buffer[BUFFER_SIZE];
while (toWrite > 0) {
ssize_t read = link.Read(buffer, toWrite > BUFFER_SIZE ? BUFFER_SIZE : toWrite);
if (read < B_OK)
return (status_t)read;
fData->Write(buffer, read);
toWrite -= read;
}*/
char buffer[toWrite];
link.Read(buffer, toWrite);
fData->Write(buffer, toWrite);
fData->Seek(oldPosition, SEEK_SET);
return B_OK;
}
status_t
ServerPicture::ExportData(BPrivate::PortLink &link)
{
link.StartMessage(B_OK);
off_t oldPosition = fData->Position();
fData->Seek(0, SEEK_SET);
int32 subPicturesCount = 0;
link.Attach<int32>(subPicturesCount);
off_t size = 0;
fData->GetSize(&size);
link.Attach<int32>((int32)size);
ssize_t toWrite = size;
char buffer[BUFFER_SIZE];
while (toWrite > 0) {
ssize_t read = fData->Read(buffer, toWrite > BUFFER_SIZE ? BUFFER_SIZE : toWrite);
if (read < B_OK)
return (status_t)read;
link.Attach(buffer, read);
toWrite -= read;
}
fData->Seek(oldPosition, SEEK_SET);
return B_OK; return B_OK;
} }
+8 -3
View File
@@ -5,6 +5,10 @@
#include <PictureDataWriter.h> #include <PictureDataWriter.h>
#include <PortLink.h>
// TODO: For some reason, the forward declaration "class BPrivate::PortLink" causes compiling errors
class ServerApp; class ServerApp;
class ViewLayer; class ViewLayer;
class BPrivate::LinkReceiver; class BPrivate::LinkReceiver;
@@ -22,20 +26,21 @@ public:
void Play(ViewLayer *view); void Play(ViewLayer *view);
const void *Data() const { return fData.Buffer(); } off_t DataLength() const;
int32 DataLength() const { return fData.BufferLength(); }
status_t ImportData(BPrivate::LinkReceiver &link); status_t ImportData(BPrivate::LinkReceiver &link);
status_t ExportData(BPrivate::PortLink &link);
private: private:
friend class ServerApp; friend class ServerApp;
ServerPicture(); ServerPicture();
ServerPicture(const ServerPicture &); ServerPicture(const ServerPicture &);
ServerPicture(const char *fileName, const int32 &offset);
~ServerPicture(); ~ServerPicture();
int32 fToken; int32 fToken;
BMallocIO fData; BPositionIO *fData;
// DrawState *fState; // DrawState *fState;
}; };
-1
View File
@@ -2783,7 +2783,6 @@ ServerWindow::HandleDirectConnection(int32 bufferState, int32 driverState)
fDirectWindowData->buffer_info->pixel_format = buffer->ColorSpace(); fDirectWindowData->buffer_info->pixel_format = buffer->ColorSpace();
fDirectWindowData->buffer_info->layout = B_BUFFER_NONINTERLEAVED; fDirectWindowData->buffer_info->layout = B_BUFFER_NONINTERLEAVED;
fDirectWindowData->buffer_info->orientation = B_BUFFER_TOP_TO_BOTTOM; // TODO fDirectWindowData->buffer_info->orientation = B_BUFFER_TOP_TO_BOTTOM; // TODO
fDirectWindowData->buffer_info->window_bounds = to_clipping_rect(fWindowLayer->Frame()); fDirectWindowData->buffer_info->window_bounds = to_clipping_rect(fWindowLayer->Frame());
// TODO: Review this // TODO: Review this
-2
View File
@@ -125,8 +125,6 @@ ViewLayer::~ViewLayer()
// if (fWindow && this == fWindow->TopLayer()) // if (fWindow && this == fWindow->TopLayer())
// fWindow->SetTopLayer(NULL); // fWindow->SetTopLayer(NULL);
//
// TODO: Don't know yet if we should also delete fPicture
if (fCursor) if (fCursor)
fCursor->Release(); fCursor->Release();