In article <[EMAIL PROTECTED]>, Simon 
Fraser <[EMAIL PROTECTED]> wrote:

> In article <[EMAIL PROTECTED]>, Patrick 
> Beard <[EMAIL PROTECTED]> wrote:
> 
> > In article <[EMAIL PROTECTED]>, Patrick 
> > Beard <[EMAIL PROTECTED]> wrote:
> > > Looks like a bug to me! In fact, there are a large number of bugs in 
> > > this file, such as nsDrawingSurfaceMac::IsPixelAddressable() not setting 
> > > its out parameter, and nsDrawingSurfaceMac::GetPixelFormat() also. 
> > > Patches coming up.
> > 
> > Index: mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp
> 
> Now give us a diff without all the whitespace mangling.

Grrr. Well, the indenting needed some help. Here's a smaller diff.

Index: mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp
===================================================================
RCS file: /cvsroot/mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp,v
retrieving revision 1.14
diff -b -u -2 -r1.14 nsDrawingSurfaceMac.cpp
--- nsDrawingSurfaceMac.cpp   2000/10/19 21:17:08  1.14
+++ nsDrawingSurfaceMac.cpp   2000/12/05 23:13:36
@@ -1,3 +1,3 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 
2 -*-
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 
2 -*-
  *
  * The contents of this file are subject to the Netscape Public
@@ -25,10 +25,6 @@
 #include "nsDrawingSurfaceMac.h"
 #include "nsGraphicState.h"
+#include "nsCarbonHelpers.h"
 
-
-static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
-static NS_DEFINE_IID(kIDrawingSurfaceMacIID, 
NS_IDRAWING_SURFACE_MAC_IID);
-
-
 /** --------------------------------------------------- 
  * See Documentation in nsIDrawingSurface.h
@@ -41,5 +37,5 @@
 
   mPort = NULL;
-  mGS = sGraphicStatePool.GetNewGS(); //new nsGraphicState();
+    mGS = sGraphicStatePool.GetNewGS();
   mWidth = mHeight = 0;
   mLockOffset = mLockHeight = 0;
@@ -47,5 +43,4 @@
   mIsOffscreen = PR_FALSE;
   mIsLocked = PR_FALSE;
-
 }
 
@@ -59,5 +54,5 @@
   GWorldPtr offscreenGWorld;
 
-  if(mIsOffscreen && mPort){
+    if (mIsOffscreen && mPort){
      offscreenGWorld = (GWorldPtr)mPort;
      ::UnlockPixels(::GetGWorldPixMap(offscreenGWorld));
@@ -65,50 +60,11 @@
   }
 
-  if (mGS){
-     sGraphicStatePool.ReleaseGS(mGS); //delete mGS;
+    if (mGS) {
+        sGraphicStatePool.ReleaseGS(mGS);
   }
-     
 }
 
-/** --------------------------------------------------- 
- * See Documentation in nsIDrawingSurface.h
- * @update 3/02/99 dwc
- * @return error status
- */
-NS_IMETHODIMP nsDrawingSurfaceMac :: QueryInterface(REFNSIID aIID, 
void** aInstancePtr)
-{
-  if (nsnull == aInstancePtr)
-    return NS_ERROR_NULL_POINTER;
-
-  if (aIID.Equals(kIDrawingSurfaceIID)){
-    nsIDrawingSurface* tmp = this;
-    *aInstancePtr = (void*) tmp;
-    NS_ADDREF_THIS();
-    return NS_OK;
-  }
-
-  if (aIID.Equals(kIDrawingSurfaceMacIID)){
-    nsIDrawingSurfaceMac* tmp = this;
-    *aInstancePtr = (void*) tmp;
-    NS_ADDREF_THIS();
-    return NS_OK;
-  }
+NS_IMPL_ISUPPORTS2(nsDrawingSurfaceMac, nsIDrawingSurface, 
nsIDrawingSurfaceMac)
 
-  static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
-
-  if (aIID.Equals(kISupportsIID)){
-    nsIDrawingSurface* tmp = this;
-    nsISupports* tmp2 = tmp;
-    *aInstancePtr = (void*) tmp2;
-    NS_ADDREF_THIS();
-    return NS_OK;
-  }
-
-  return NS_NOINTERFACE;
-}
-
-NS_IMPL_ADDREF(nsDrawingSurfaceMac);
-NS_IMPL_RELEASE(nsDrawingSurfaceMac);
-
 #pragma mark-
 
@@ -128,5 +84,4 @@
   PixMapHandle   thePixMap;
 
-
   if ((mIsLocked == PR_FALSE) && mIsOffscreen && mPort) {
     // get the offscreen gworld for our use
@@ -167,5 +122,10 @@
   *aWidth = mWidth;
   *aHeight = mHeight;
+    return NS_OK;
+}
 
+NS_IMETHODIMP nsDrawingSurfaceMac :: IsOffscreen(PRBool *aOffScreen)
+{
+    *aOffScreen = mIsOffscreen;
   return NS_OK;
 }
@@ -178,4 +138,5 @@
 NS_IMETHODIMP nsDrawingSurfaceMac :: IsPixelAddressable(PRBool 
*aAddressable)
 {
+    *aAddressable = PR_TRUE;
   return NS_OK;
 }
@@ -188,5 +149,25 @@
 NS_IMETHODIMP nsDrawingSurfaceMac :: GetPixelFormat(nsPixelFormat 
*aFormat)
 {
-  //*aFormat = mPixFormat;
+    // TODO:  fill in proper fields for 3 most likely bit depths.
+    static nsPixelFormat k8BitPixelFormat = {};
+    static nsPixelFormat k16BitPixelFormat = {};
+    static nsPixelFormat k32BitPixelFormat = {};
+
+    nsPixelFormat* format = NULL;
+    PixMapHandle pixmap = ::GetPortPixMap((CGrafPtr)mPort);
+    short depth = (**pixmap).pixelSize;
+    switch (depth) {
+    case 8:
+        format = &k8BitPixelFormat;
+        break;
+    case 16:
+        format = &k16BitPixelFormat;
+        break;
+    case 32:
+        format = &k32BitPixelFormat;
+        break;
+    }
+    if (format)
+        ::memcpy(aFormat, format, sizeof(nsPixelFormat));
 
   return NS_OK;
@@ -202,12 +183,7 @@
 NS_IMETHODIMP nsDrawingSurfaceMac :: Init(nsDrawingSurface aDS)
 {
-GrafPtr gport;
-
   nsDrawingSurfaceMac* surface = static_cast<nsDrawingSurfaceMac*>(aDS);
-  surface->GetGrafPtr(&gport);
-  mPort = gport;
+    surface->GetGrafPtr(&mPort);
   mGS->Init(surface);
-  
-  
   return NS_OK;
 }
@@ -220,5 +196,4 @@
 NS_IMETHODIMP nsDrawingSurfaceMac :: Init(GrafPtr aPort)
 {
-
   // set our grafPtr to the passed in port
   mPort = aPort;
@@ -260,7 +235,7 @@
 
   // calculate the rectangle
-  if (aWidth != 0){
+    if (aWidth != 0) {
      ::SetRect(&macRect, 0, 0, aWidth, aHeight);
-  }else{
+    } else {
      ::SetRect(&macRect, 0, 0, 2, 2);
   }
Index: mozilla/gfx/src/mac/nsDrawingSurfaceMac.h
===================================================================
RCS file: /cvsroot/mozilla/gfx/src/mac/nsDrawingSurfaceMac.h,v
retrieving revision 1.9
diff -b -u -2 -r1.9 nsDrawingSurfaceMac.h
--- nsDrawingSurfaceMac.h  2000/02/04 15:53:39  1.9
+++ nsDrawingSurfaceMac.h  2000/12/05 23:13:37
@@ -44,5 +44,5 @@
   NS_IMETHOD Unlock(void);
   NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
-  NS_IMETHOD IsOffscreen(PRBool *aOffScreen) {return mIsOffscreen;}
+  NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
   NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
   NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
Index: mozilla/gfx/src/mac/nsIDrawingSurfaceMac.h
===================================================================
RCS file: /cvsroot/mozilla/gfx/src/mac/nsIDrawingSurfaceMac.h,v
retrieving revision 1.3
diff -b -u -2 -r1.3 nsIDrawingSurfaceMac.h
--- nsIDrawingSurfaceMac.h 1999/11/06 03:21:20  1.3
+++ nsIDrawingSurfaceMac.h 2000/12/05 23:13:37
@@ -39,4 +39,5 @@
 {
 public:
+  NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDRAWING_SURFACE_MAC_IID)
   /**
    * Initialize a drawing surface using a Macintosh GrafPtr.

Reply via email to