Added a _BPictureExtent_::Flatten(), moved some code from BPicture::Flatten()
into it. Renamed ImportData() to Unflatten(). Some code shuffling. No functional change. Some style cleanup needed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31842 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,29 +1,8 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright 2001-2009, Haiku.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
*/
|
||||||
// to deal in the Software without restriction, including without limitation
|
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: Picture.h
|
|
||||||
// Author: Marc Flerackers ([email protected])
|
|
||||||
// Description: BPicture records a series of drawing instructions that can
|
|
||||||
// be "replayed" later.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _PICTURE_H
|
#ifndef _PICTURE_H
|
||||||
#define _PICTURE_H
|
#define _PICTURE_H
|
||||||
@@ -71,7 +50,6 @@ virtual void _ReservedPicture3();
|
|||||||
void _InitData();
|
void _InitData();
|
||||||
void _DisposeData();
|
void _DisposeData();
|
||||||
|
|
||||||
void _ImportData(const void *data, int32 size, BPicture **subs, int32 subCount);
|
|
||||||
void _ImportOldData(const void *data, int32 size);
|
void _ImportOldData(const void *data, int32 size);
|
||||||
|
|
||||||
void SetToken(int32 token);
|
void SetToken(int32 token);
|
||||||
|
|||||||
@@ -30,33 +30,44 @@ struct _BPictureExtent_ {
|
|||||||
_BPictureExtent_(const int32 &size = 0);
|
_BPictureExtent_(const int32 &size = 0);
|
||||||
~_BPictureExtent_();
|
~_BPictureExtent_();
|
||||||
|
|
||||||
const void *Data() const { return fNewData; }
|
const void* Data() const { return fNewData; }
|
||||||
status_t ImportData(const void *data, const int32 &size);
|
status_t ImportData(const void *data,
|
||||||
status_t ImportData(BDataIO *stream);
|
const int32 &size);
|
||||||
|
|
||||||
|
status_t Flatten(BDataIO *stream);
|
||||||
|
status_t Unflatten(BDataIO *stream);
|
||||||
|
|
||||||
int32 Size() const { return fNewSize; }
|
int32 Size() const { return fNewSize; }
|
||||||
status_t SetSize(const int32 &size);
|
status_t SetSize(const int32 &size);
|
||||||
|
|
||||||
bool AddPicture(BPicture *picture) { return fPictures.AddItem(picture); }
|
bool AddPicture(BPicture *picture)
|
||||||
|
{ return fPictures.AddItem(picture); }
|
||||||
void DeletePicture(const int32 &index)
|
void DeletePicture(const int32 &index)
|
||||||
{ delete static_cast<BPicture *>(fPictures.RemoveItem(index)); }
|
{ delete static_cast<BPicture *>
|
||||||
BPicture *PictureAt(const int32 &index)
|
(fPictures.RemoveItem(index)); }
|
||||||
{ return static_cast<BPicture *>(fPictures.ItemAt(index)); }
|
|
||||||
|
BList* Pictures() { return &fPictures; }
|
||||||
|
BPicture* PictureAt(const int32 &index)
|
||||||
|
{ return static_cast<BPicture *>
|
||||||
|
(fPictures.ItemAt(index)); }
|
||||||
|
|
||||||
|
int32 CountPictures() const
|
||||||
|
{ return fPictures.CountItems(); }
|
||||||
|
|
||||||
int32 CountPictures() const { return fPictures.CountItems(); }
|
|
||||||
BList *Pictures() { return &fPictures; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *fNewData;
|
void* fNewData;
|
||||||
int32 fNewSize;
|
int32 fNewSize;
|
||||||
|
|
||||||
BList fPictures; // In R5 this is a BArray<BPicture*> which is completely inline.
|
BList fPictures;
|
||||||
|
// In R5 this is a BArray<BPicture*>
|
||||||
|
// which is completely inline.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct picture_header {
|
struct picture_header {
|
||||||
int32 magic1; // ?
|
int32 magic1; // version ?
|
||||||
int32 magic2; // ?
|
int32 magic2; // endianess ?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -229,7 +240,10 @@ BPicture::Archive(BMessage *archive, bool deep) const
|
|||||||
for (int32 i = 0; i < fExtent->CountPictures(); i++) {
|
for (int32 i = 0; i < fExtent->CountPictures(); i++) {
|
||||||
BMessage picMsg;
|
BMessage picMsg;
|
||||||
|
|
||||||
fExtent->PictureAt(i)->Archive(&picMsg, deep);
|
err = fExtent->PictureAt(i)->Archive(&picMsg, deep);
|
||||||
|
if (err != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
err = archive->AddMessage("piclib", &picMsg);
|
err = archive->AddMessage("piclib", &picMsg);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
break;
|
break;
|
||||||
@@ -273,33 +287,7 @@ BPicture::Flatten(BDataIO *stream)
|
|||||||
if (bytesWritten != (ssize_t)sizeof(header))
|
if (bytesWritten != (ssize_t)sizeof(header))
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
|
|
||||||
int32 count = fExtent->CountPictures();
|
return fExtent->Flatten(stream);
|
||||||
bytesWritten = stream->Write(&count, sizeof(count));
|
|
||||||
if (bytesWritten < B_OK)
|
|
||||||
return bytesWritten;
|
|
||||||
if (bytesWritten != (ssize_t)sizeof(count))
|
|
||||||
return B_IO_ERROR;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
status_t status = fExtent->PictureAt(i)->Flatten(stream);
|
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32 size = fExtent->Size();
|
|
||||||
bytesWritten = stream->Write(&size, sizeof(size));
|
|
||||||
if (bytesWritten < B_OK)
|
|
||||||
return bytesWritten;
|
|
||||||
if (bytesWritten != (ssize_t)sizeof(size))
|
|
||||||
return B_IO_ERROR;
|
|
||||||
|
|
||||||
bytesWritten = stream->Write(fExtent->Data(), size);
|
|
||||||
if (bytesWritten < B_OK)
|
|
||||||
return bytesWritten;
|
|
||||||
if (bytesWritten != size)
|
|
||||||
return B_IO_ERROR;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -316,23 +304,7 @@ BPicture::Unflatten(BDataIO *stream)
|
|||||||
|| header.magic1 != 2 || header.magic2 != 0)
|
|| header.magic1 != 2 || header.magic2 != 0)
|
||||||
return B_BAD_TYPE;
|
return B_BAD_TYPE;
|
||||||
|
|
||||||
int32 count = 0;
|
status_t status = fExtent->Unflatten(stream);
|
||||||
bytesRead = stream->Read(&count, sizeof(count));
|
|
||||||
if (bytesRead < B_OK)
|
|
||||||
return bytesRead;
|
|
||||||
if (bytesRead != (ssize_t)sizeof(count))
|
|
||||||
return B_BAD_DATA;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
BPicture* picture = new BPicture;
|
|
||||||
status_t status = picture->Unflatten(stream);
|
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
fExtent->AddPicture(picture);
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t status = fExtent->ImportData(stream);
|
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -349,33 +321,6 @@ BPicture::Unflatten(BDataIO *stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BPicture::_ImportData(const void *data, int32 size, BPicture **subs,
|
|
||||||
int32 subCount)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
if (data == NULL || size == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BPrivate::AppServerLink link;
|
|
||||||
|
|
||||||
link.StartMessage(AS_CREATE_PICTURE);
|
|
||||||
link.Attach<int32>(subCount);
|
|
||||||
|
|
||||||
for (int32 i = 0; i < subCount; i++)
|
|
||||||
link.Attach<int32>(subs[i]->fToken);
|
|
||||||
|
|
||||||
link.Attach<int32>(size);
|
|
||||||
link.Attach(data, size);
|
|
||||||
|
|
||||||
status_t status = B_ERROR;
|
|
||||||
if (link.FlushWithReply(status) == B_OK
|
|
||||||
&& status == B_OK)
|
|
||||||
link.Read<int32>(&fToken);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPicture::_ImportOldData(const void *data, int32 size)
|
BPicture::_ImportOldData(const void *data, int32 size)
|
||||||
{
|
{
|
||||||
@@ -428,8 +373,10 @@ BPicture::_AssertServerCopy()
|
|||||||
if (fExtent->Data() == NULL)
|
if (fExtent->Data() == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int32 i = 0; i < fExtent->CountPictures(); i++)
|
for (int32 i = 0; i < fExtent->CountPictures(); i++) {
|
||||||
fExtent->PictureAt(i)->_AssertServerCopy();
|
if (!fExtent->PictureAt(i)->_AssertServerCopy())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _Upload() == B_OK;
|
return _Upload() == B_OK;
|
||||||
}
|
}
|
||||||
@@ -438,8 +385,8 @@ BPicture::_AssertServerCopy()
|
|||||||
status_t
|
status_t
|
||||||
BPicture::_Upload()
|
BPicture::_Upload()
|
||||||
{
|
{
|
||||||
ASSERT((fToken == -1));
|
ASSERT(fToken == -1);
|
||||||
ASSERT((fExtent->Data() != NULL));
|
ASSERT(fExtent->Data() != NULL);
|
||||||
|
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
|
|
||||||
@@ -466,8 +413,8 @@ BPicture::_Upload()
|
|||||||
status_t
|
status_t
|
||||||
BPicture::_Download()
|
BPicture::_Download()
|
||||||
{
|
{
|
||||||
ASSERT((fExtent->Data() == NULL));
|
ASSERT(fExtent->Data() == NULL);
|
||||||
ASSERT((fToken != -1));
|
ASSERT(fToken != -1);
|
||||||
|
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
|
|
||||||
@@ -588,13 +535,29 @@ _BPictureExtent_::ImportData(const void *data, const int32 &size)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
_BPictureExtent_::ImportData(BDataIO *stream)
|
_BPictureExtent_::Unflatten(BDataIO *stream)
|
||||||
{
|
{
|
||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
int32 count = 0;
|
||||||
|
ssize_t bytesRead = stream->Read(&count, sizeof(count));
|
||||||
|
if (bytesRead < B_OK)
|
||||||
|
return bytesRead;
|
||||||
|
if (bytesRead != (ssize_t)sizeof(count))
|
||||||
|
return B_BAD_DATA;
|
||||||
|
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
BPicture* picture = new BPicture;
|
||||||
|
status_t status = picture->Unflatten(stream);
|
||||||
|
if (status < B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
AddPicture(picture);
|
||||||
|
}
|
||||||
|
|
||||||
int32 size;
|
int32 size;
|
||||||
ssize_t bytesRead = stream->Read(&size, sizeof(size));
|
bytesRead = stream->Read(&size, sizeof(size));
|
||||||
if (bytesRead < B_OK)
|
if (bytesRead < B_OK)
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
if (bytesRead != (ssize_t)sizeof(size))
|
if (bytesRead != (ssize_t)sizeof(size))
|
||||||
@@ -617,6 +580,38 @@ _BPictureExtent_::ImportData(BDataIO *stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
_BPictureExtent_::Flatten(BDataIO *stream)
|
||||||
|
{
|
||||||
|
int32 count = fPictures.CountItems();
|
||||||
|
ssize_t bytesWritten = stream->Write(&count, sizeof(count));
|
||||||
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
if (bytesWritten != (ssize_t)sizeof(count))
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
status_t status = PictureAt(i)->Flatten(stream);
|
||||||
|
if (status < B_OK)
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesWritten = stream->Write(&fNewSize, sizeof(fNewSize));
|
||||||
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
if (bytesWritten != (ssize_t)sizeof(fNewSize))
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
bytesWritten = stream->Write(fNewData, fNewSize);
|
||||||
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
if (bytesWritten != fNewSize)
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
_BPictureExtent_::SetSize(const int32 &size)
|
_BPictureExtent_::SetSize(const int32 &size)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user