~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/src/beos/nsDrawingSurfaceBeOS.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#include "nsDrawingSurfaceBeOS.h"
 
40
#include "nsCoord.h"
 
41
 
 
42
NS_IMPL_ISUPPORTS2(nsDrawingSurfaceBeOS, nsIDrawingSurface, nsIDrawingSurfaceBeOS)
 
43
 
 
44
#ifdef CHEAP_PERFORMANCE_MEASUREMENT 
 
45
static PRTime mLockTime, mUnlockTime; 
 
46
#endif 
 
47
 
 
48
nsDrawingSurfaceBeOS :: nsDrawingSurfaceBeOS()
 
49
{
 
50
  mView = NULL;
 
51
 
 
52
  mBitmap = nsnull;
 
53
  mWidth = 0; 
 
54
  mHeight = 0; 
 
55
  
 
56
  mLockWidth = 0; 
 
57
  mLockHeight = 0;
 
58
  mLockFlags = 0;
 
59
  mLockX = 0; 
 
60
  mLockY = 0; 
 
61
  mLocked = PR_FALSE;
 
62
}
 
63
 
 
64
nsDrawingSurfaceBeOS :: ~nsDrawingSurfaceBeOS()
 
65
{
 
66
  if(mBitmap)
 
67
  {
 
68
    mBitmap->RemoveChild(mView);
 
69
        delete mBitmap;
 
70
  }
 
71
}
 
72
 
 
73
/** 
 
74
 * Lock a rect of a drawing surface and return a 
 
75
 * pointer to the upper left hand corner of the 
 
76
 * bitmap. 
 
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 
 
82
 *         corner of bitmap 
 
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 
 
88
 * 
 
89
 **/ 
 
90
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Lock(PRInt32 aX, PRInt32 aY,
 
91
                                          PRUint32 aWidth, PRUint32 aHeight,
 
92
                                          void **aBits, PRInt32 *aStride,
 
93
                                          PRInt32 *aWidthBytes, PRUint32 aFlags)
 
94
{
 
95
#ifdef CHEAP_PERFORMANCE_MEASUREMENT 
 
96
  mLockTime = PR_Now(); 
 
97
  //  MOZ_TIMER_RESET(mLockTime); 
 
98
  //  MOZ_TIMER_START(mLockTime); 
 
99
#endif 
 
100
 
 
101
  if (mLocked)
 
102
  {
 
103
    NS_ASSERTION(0, "nested lock attempt");
 
104
    return NS_ERROR_FAILURE;
 
105
  }
 
106
  mLocked = PR_TRUE;
 
107
 
 
108
  mLockX = aX; 
 
109
  mLockY = aY; 
 
110
  mLockWidth = aWidth; 
 
111
  mLockHeight = aHeight; 
 
112
  mLockFlags = aFlags;
 
113
 
 
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 
 
116
  mView->LockLooper(); 
 
117
 
 
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);
 
123
#endif
 
124
 
 
125
  return NS_OK;
 
126
}
 
127
 
 
128
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Unlock(void)
 
129
{
 
130
 
 
131
#ifdef CHEAP_PERFORMANCE_MEASUREMENT 
 
132
  mUnlockTime = PR_Now(); 
 
133
#endif 
 
134
 
 
135
  //  g_print("nsDrawingSurfaceGTK::UnLock() called\n"); 
 
136
  if (!mLocked) 
 
137
  {
 
138
    NS_ASSERTION(0, "attempting to unlock an DS that isn't locked"); 
 
139
    return NS_ERROR_FAILURE;
 
140
  }
 
141
 
 
142
  // If the lock was not read only, put the bits back on the pixmap
 
143
        if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY))
 
144
        {
 
145
    // FIX ME!!! 
 
146
    // Now draw the image ... 
 
147
        }
 
148
 
 
149
  // FIX ME!!! 
 
150
  // Destroy mImage 
 
151
       mView->UnlockLooper();
 
152
 
 
153
  mLocked = PR_FALSE; 
 
154
 
 
155
 
 
156
#ifdef CHEAP_PERFORMANCE_MEASUREMENT 
 
157
  printf("Time taken to unlock: %d\n", PR_Now() - mUnlockTime);
 
158
#endif
 
159
  return NS_OK;
 
160
}
 
161
 
 
162
NS_IMETHODIMP nsDrawingSurfaceBeOS :: GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
 
163
{
 
164
  *aWidth = mWidth;
 
165
  *aHeight = mHeight;
 
166
 
 
167
  return NS_OK;
 
168
}
 
169
 
 
170
NS_IMETHODIMP nsDrawingSurfaceBeOS :: IsOffscreen(PRBool *aOffScreen)
 
171
{
 
172
  *aOffScreen = mIsOffscreen;//mBitmap ? PR_TRUE : PR_FALSE;
 
173
  return NS_OK;
 
174
}
 
175
 
 
176
NS_IMETHODIMP nsDrawingSurfaceBeOS :: IsPixelAddressable(PRBool *aAddressable)
 
177
{
 
178
  *aAddressable = PR_FALSE; 
 
179
  return NS_OK;
 
180
}
 
181
 
 
182
NS_IMETHODIMP nsDrawingSurfaceBeOS :: GetPixelFormat(nsPixelFormat *aFormat)
 
183
{
 
184
  *aFormat = mPixFormat;
 
185
 
 
186
  return NS_OK;
 
187
}
 
188
 
 
189
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Init(BView *aView)
 
190
{
 
191
  if(aView->LockLooper()) 
 
192
  { 
 
193
    //remember dimensions 
 
194
    mWidth=nscoord(aView->Bounds().Width()+1); 
 
195
    mHeight=nscoord(aView->Bounds().Height()+1); 
 
196
    
 
197
    mView = aView;
 
198
 
 
199
    aView->UnlockLooper(); 
 
200
  } 
 
201
 
 
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; 
 
206
 
 
207
  return NS_OK;
 
208
}
 
209
 
 
210
NS_IMETHODIMP nsDrawingSurfaceBeOS :: Init(BView *aView, PRUint32 aWidth,
 
211
                                          PRUint32 aHeight, PRUint32 aFlags)
 
212
{
 
213
  NS_ASSERTION(!(aView == nsnull), "null BView");
 
214
 
 
215
  //remember dimensions
 
216
  mWidth=aWidth;
 
217
  mHeight=aHeight;
 
218
  mFlags = aFlags; 
 
219
  
 
220
  // we can draw on this offscreen because it has no parent 
 
221
  mIsOffscreen = PR_TRUE; 
 
222
 
 
223
  BRect r(0,0, mWidth-1, mHeight-1);
 
224
  mView = new BView(r, "", 0, 0);
 
225
  if (!mView)
 
226
    return NS_ERROR_OUT_OF_MEMORY;
 
227
 
 
228
//if((aFlags & NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS) &&
 
229
//  (aWidth > 0) && (aHeight > 0))
 
230
  if(aWidth > 0 && aHeight > 0)
 
231
  {
 
232
    mBitmap = new BBitmap(r, B_RGBA32, true);
 
233
    if (!mBitmap)
 
234
      return NS_ERROR_OUT_OF_MEMORY;
 
235
 
 
236
    if (mBitmap->InitCheck()!=B_OK) {
 
237
      //for some reason, the bitmap isn't valid - delete the
 
238
      //bitmap object, then indicate failure
 
239
      delete mBitmap;
 
240
      mBitmap=NULL;
 
241
      
 
242
      return NS_ERROR_FAILURE;
 
243
    }
 
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);
 
248
  }
 
249
  return NS_OK;
 
250
}
 
251
 
 
252
NS_IMETHODIMP nsDrawingSurfaceBeOS :: AcquireView(BView **aView) 
 
253
{
 
254
  *aView = mView;
 
255
 
 
256
  return NS_OK;
 
257
}
 
258
 
 
259
NS_IMETHODIMP nsDrawingSurfaceBeOS :: AcquireBitmap(BBitmap **aBitmap)
 
260
{
 
261
  if(mBitmap && mBitmap->Lock())
 
262
  {
 
263
    mView->Sync();
 
264
    mBitmap->Unlock();
 
265
  }
 
266
  *aBitmap = mBitmap;
 
267
 
 
268
  return NS_OK;
 
269
}
 
270
 
 
271
NS_IMETHODIMP nsDrawingSurfaceBeOS :: ReleaseView(void)
 
272
{
 
273
  return NS_OK;
 
274
}
 
275
 
 
276
NS_IMETHODIMP nsDrawingSurfaceBeOS :: ReleaseBitmap(void)
 
277
{
 
278
  return NS_OK;
 
279
}