1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#include "nsDrawingSurfaceBeOS.h"
42
NS_IMPL_ISUPPORTS2(nsDrawingSurfaceBeOS, nsIDrawingSurface, nsIDrawingSurfaceBeOS)
44
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
45
static PRTime mLockTime, mUnlockTime;
48
nsDrawingSurfaceBeOS :: nsDrawingSurfaceBeOS()
64
nsDrawingSurfaceBeOS :: ~nsDrawingSurfaceBeOS()
68
mBitmap->RemoveChild(mView);
74
* Lock a rect of a drawing surface and return a
75
* pointer to the upper left hand corner of the
77
* @param aX x position of subrect of bitmap
78
* @param aY y position of subrect of bitmap
79
* @param aWidth width of subrect of bitmap
80
* @param aHeight height of subrect of bitmap
81
* @param aBits out parameter for upper left hand
83
* @param aStride out parameter for number of bytes
84
* to add to aBits to go from scanline to scanline
85
* @param aWidthBytes out parameter for number of
86
* bytes per line in aBits to process aWidth pixels
87
* @return error status
90
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Lock(PRInt32 aX, PRInt32 aY,
91
PRUint32 aWidth, PRUint32 aHeight,
92
void **aBits, PRInt32 *aStride,
93
PRInt32 *aWidthBytes, PRUint32 aFlags)
95
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
97
// MOZ_TIMER_RESET(mLockTime);
98
// MOZ_TIMER_START(mLockTime);
103
NS_ASSERTION(0, "nested lock attempt");
104
return NS_ERROR_FAILURE;
111
mLockHeight = aHeight;
114
// Obtain an ximage from the pixmap. ( I think this copy the bitmap )
115
// FIX ME !!!! We need to copy the part locked into the mImage
118
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
119
// MOZ_TIMER_STOP(mLockTime);
120
// MOZ_TIMER_LOG(("Time taken to lock: "));
121
// MOZ_TIMER_PRINT(mLockTime);
122
printf("Time taken to lock: %d\n", PR_Now() - mLockTime);
128
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Unlock(void)
131
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
132
mUnlockTime = PR_Now();
135
// g_print("nsDrawingSurfaceGTK::UnLock() called\n");
138
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
139
return NS_ERROR_FAILURE;
142
// If the lock was not read only, put the bits back on the pixmap
143
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY))
146
// Now draw the image ...
151
mView->UnlockLooper();
156
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
157
printf("Time taken to unlock: %d\n", PR_Now() - mUnlockTime);
162
NS_IMETHODIMP nsDrawingSurfaceBeOS :: GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
170
NS_IMETHODIMP nsDrawingSurfaceBeOS :: IsOffscreen(PRBool *aOffScreen)
172
*aOffScreen = mIsOffscreen;//mBitmap ? PR_TRUE : PR_FALSE;
176
NS_IMETHODIMP nsDrawingSurfaceBeOS :: IsPixelAddressable(PRBool *aAddressable)
178
*aAddressable = PR_FALSE;
182
NS_IMETHODIMP nsDrawingSurfaceBeOS :: GetPixelFormat(nsPixelFormat *aFormat)
184
*aFormat = mPixFormat;
189
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Init(BView *aView)
191
if(aView->LockLooper())
193
//remember dimensions
194
mWidth=nscoord(aView->Bounds().Width()+1);
195
mHeight=nscoord(aView->Bounds().Height()+1);
199
aView->UnlockLooper();
202
// XXX was i smoking crack when i wrote this comment?
203
// this is definatly going to be on the screen, as it will be the window of a
204
// widget or something.
205
mIsOffscreen = PR_FALSE;
210
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Init(BView *aView, PRUint32 aWidth,
211
PRUint32 aHeight, PRUint32 aFlags)
213
NS_ASSERTION(!(aView == nsnull), "null BView");
215
//remember dimensions
220
// we can draw on this offscreen because it has no parent
221
mIsOffscreen = PR_TRUE;
223
BRect r(0,0, mWidth-1, mHeight-1);
224
mView = new BView(r, "", 0, 0);
226
return NS_ERROR_OUT_OF_MEMORY;
228
//if((aFlags & NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS) &&
229
// (aWidth > 0) && (aHeight > 0))
230
if(aWidth > 0 && aHeight > 0)
232
mBitmap = new BBitmap(r, B_RGBA32, true);
234
return NS_ERROR_OUT_OF_MEMORY;
236
if (mBitmap->InitCheck()!=B_OK) {
237
//for some reason, the bitmap isn't valid - delete the
238
//bitmap object, then indicate failure
242
return NS_ERROR_FAILURE;
244
//Setting ViewColor transparent noticeably decreases AppServer load in DrawBitmp()
245
//Applicable here, because Mozilla paints backgrounds explicitly, with images or filling areas.
246
mView->SetViewColor(B_TRANSPARENT_32_BIT);
247
mBitmap->AddChild(mView);
252
NS_IMETHODIMP nsDrawingSurfaceBeOS :: AcquireView(BView **aView)
259
NS_IMETHODIMP nsDrawingSurfaceBeOS :: AcquireBitmap(BBitmap **aBitmap)
261
if(mBitmap && mBitmap->Lock())
271
NS_IMETHODIMP nsDrawingSurfaceBeOS :: ReleaseView(void)
276
NS_IMETHODIMP nsDrawingSurfaceBeOS :: ReleaseBitmap(void)