Added bitmap allocation code which talks to the app_server
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2896 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
//
|
//
|
||||||
// File Name: Bitmap.cpp
|
// File Name: Bitmap.cpp
|
||||||
// Author: Ingo Weinhold ([email protected])
|
// Author: Ingo Weinhold ([email protected])
|
||||||
|
// DarkWyrm <[email protected]>
|
||||||
// Description: BBitmap objects represent off-screen windows that
|
// Description: BBitmap objects represent off-screen windows that
|
||||||
// contain bitmap data.
|
// contain bitmap data.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -35,6 +36,11 @@
|
|||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
// Includes to be able to talk to the app_server
|
||||||
|
#include <Application.h>
|
||||||
|
#include <ServerProtocol.h>
|
||||||
|
#include <PortLink.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NOT_IMPLEMENTED = B_ERROR,
|
NOT_IMPLEMENTED = B_ERROR,
|
||||||
};
|
};
|
||||||
@@ -2141,13 +2147,35 @@ void
|
|||||||
BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags,
|
BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags,
|
||||||
int32 bytesPerRow, screen_id screenID)
|
int32 bytesPerRow, screen_id screenID)
|
||||||
{
|
{
|
||||||
|
status_t error = B_OK;
|
||||||
|
|
||||||
|
PortLink::ReplyData replydata;
|
||||||
|
PortLink *link=new PortLink(be_app->fServerTo);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
if (fBasePtr) {
|
if (fBasePtr) {
|
||||||
free(fBasePtr);
|
// free(fBasePtr);
|
||||||
fBasePtr = NULL;
|
fBasePtr = NULL;
|
||||||
|
|
||||||
|
// AS_DELETE_BITMAP:
|
||||||
|
// Attached Data:
|
||||||
|
// 1) int32 server token
|
||||||
|
|
||||||
|
// Reply Code: SERVER_TRUE if successful,
|
||||||
|
// SERVER_FALSE if the buffer was already deleted
|
||||||
|
// Reply Data:
|
||||||
|
// none
|
||||||
|
status_t freestat;
|
||||||
|
link->SetOpCode(AS_DELETE_BITMAP);
|
||||||
|
link->Attach(fServerToken);
|
||||||
|
error=link->FlushWithReply(&replydata);
|
||||||
|
if(replydata.code==SERVER_FALSE)
|
||||||
|
error=B_NO_MEMORY;
|
||||||
|
fBasePtr=NULL;
|
||||||
|
fArea=-1;
|
||||||
|
fServerToken=-1;
|
||||||
}
|
}
|
||||||
// check params
|
// check params
|
||||||
status_t error = B_OK;
|
|
||||||
if (!bounds.IsValid() || !is_supported(colorSpace))
|
if (!bounds.IsValid() || !is_supported(colorSpace))
|
||||||
error = B_BAD_VALUE;
|
error = B_BAD_VALUE;
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
@@ -2160,21 +2188,68 @@ BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags,
|
|||||||
// allocate the bitmap buffer
|
// allocate the bitmap buffer
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
int32 size = bytesPerRow * (bounds.IntegerHeight() + 1);
|
int32 size = bytesPerRow * (bounds.IntegerHeight() + 1);
|
||||||
fBasePtr = malloc(size);
|
// fBasePtr = malloc(size);
|
||||||
if (fBasePtr) {
|
|
||||||
|
// Ask the server (via our owning application) to create a bitmap.
|
||||||
|
|
||||||
|
// AS_CREATE_BITMAP:
|
||||||
|
|
||||||
|
// Attached Data:
|
||||||
|
// None
|
||||||
|
|
||||||
|
// Reply Code: SERVER_TRUE
|
||||||
|
// Reply Data:
|
||||||
|
// 1) int32 server token
|
||||||
|
// 2) area_id id of the area in which the bitmap data resides
|
||||||
|
// 3) int32 area pointer offset used to calculate fBasePtr
|
||||||
|
|
||||||
|
// alternatively, if something went wrong
|
||||||
|
// Reply Code: SERVER_FALSE
|
||||||
|
// Reply Data:
|
||||||
|
// None
|
||||||
|
|
||||||
|
link->SetOpCode(AS_CREATE_BITMAP);
|
||||||
|
|
||||||
|
error=link->FlushWithReply(&replydata);
|
||||||
|
|
||||||
|
// We shouldn't ever have to execute this block, but just in case...
|
||||||
|
if(error!=B_OK)
|
||||||
|
fBasePtr=NULL;
|
||||||
|
|
||||||
|
if(replydata.code==SERVER_TRUE)
|
||||||
|
{
|
||||||
|
int8 *bufferindex=replydata.buffer;
|
||||||
|
|
||||||
|
// Get token
|
||||||
|
fServerToken=*((int32*)bufferindex); bufferindex+=sizeof(int32);
|
||||||
|
|
||||||
|
// Get the area in which the data resides
|
||||||
|
fArea=clone_area("shared bitmap area",(void**)&fBasePtr,B_ANY_ADDRESS,
|
||||||
|
B_READ_AREA | B_WRITE_AREA,*((area_id*)bufferindex));
|
||||||
|
bufferindex+=sizeof(area_id);
|
||||||
|
|
||||||
|
// Jump to the location in the area
|
||||||
|
fBasePtr=(int8*)fBasePtr + *((int32*)bufferindex);
|
||||||
|
|
||||||
fSize = size;
|
fSize = size;
|
||||||
fColorSpace = colorSpace;
|
fColorSpace = colorSpace;
|
||||||
fBounds = bounds;
|
fBounds = bounds;
|
||||||
fBytesPerRow = bytesPerRow;
|
fBytesPerRow = bytesPerRow;
|
||||||
fWindow = NULL;
|
|
||||||
fServerToken = -1;
|
|
||||||
fToken = -1;
|
|
||||||
fArea = -1;
|
|
||||||
fOrigArea = -1;
|
|
||||||
fFlags = flags;
|
fFlags = flags;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fServerToken = -1;
|
||||||
|
fArea = -1;
|
||||||
|
fFlags = flags;
|
||||||
|
|
||||||
error = B_NO_MEMORY;
|
error = B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
fWindow = NULL;
|
||||||
|
fToken = -1;
|
||||||
|
fOrigArea = -1;
|
||||||
}
|
}
|
||||||
|
delete link;
|
||||||
fInitError = error;
|
fInitError = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user