Bug 627656 - Move the implementation of DrawOver to nsChildView, because that's the widget on which we create our OpenGL view, and it's therefore easier to reason about texture lifetimes with that. r=jrmuizel,mattwoodrow a=jrmuizel
authorJoe Drew <joe@drew.ca>
Sat, 19 Feb 2011 17:22:12 -0500
changeset 62870 c22790bab37ac767d7bb098974443c9ed5c905a3
parent 62869 77e1fe783407e3af600bd794ed520ac35db0bccb
child 62871 3e52c6d7f7283cc0921d19a74bf4867fdd8777d0
push id18923
push usermwoodrow@mozilla.com
push dateSat, 19 Feb 2011 22:42:01 +0000
treeherdermozilla-central@3e52c6d7f728 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, mattwoodrow, jrmuizel
bugs627656
milestone2.0b12pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 627656 - Move the implementation of DrawOver to nsChildView, because that's the widget on which we create our OpenGL view, and it's therefore easier to reason about texture lifetimes with that. r=jrmuizel,mattwoodrow a=jrmuizel
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsCocoaWindow.h
widget/src/cocoa/nsCocoaWindow.mm
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -84,22 +84,24 @@
 #include "ComplexTextInputPanel.h"
 #endif
 
 #include "gfxContext.h"
 #include "gfxQuartzSurface.h"
 #include "nsRegion.h"
 #include "Layers.h"
 #include "LayerManagerOGL.h"
+#include "GLContext.h"
 
 #include <dlfcn.h>
 
 #include <ApplicationServices/ApplicationServices.h>
 
 using namespace mozilla::layers;
+using namespace mozilla::gl;
 #undef DEBUG_IME
 #undef DEBUG_UPDATE
 #undef INVALIDATE_DEBUGGING  // flash areas as they are invalidated
 
 // Don't put more than this many rects in the dirty region, just fluff
 // out to the bounding-box if there are more
 #define MAX_RECTS_IN_REGION 100
 
@@ -2092,20 +2094,84 @@ nsChildView::GetThebesSurface()
   }
 
   return mTempThebesSurface;
 }
 
 void
 nsChildView::DrawOver(LayerManager* aManager, nsIntRect aRect)
 {
-  nsCocoaWindow *cocoaWindow = GetXULWindowWidget();
-  if (cocoaWindow) {
-    cocoaWindow->DrawOver(aManager, aRect);
-  }
+  if (!ShowsResizeIndicator(nsnull)) {
+    return;
+  }
+
+  nsRefPtr<LayerManagerOGL> manager(static_cast<LayerManagerOGL*>(aManager));
+  if (!manager) {
+    return;
+  }
+
+  float bottomX = aRect.x + aRect.width;
+  float bottomY = aRect.y + aRect.height;
+
+  nsRefPtr<gfxQuartzSurface> image =
+    new gfxQuartzSurface(gfxIntSize(15, 15), gfxASurface::ImageFormatARGB32);
+  CGContextRef ctx = image->GetCGContext();
+
+  CGContextSetShouldAntialias(ctx, false);
+  CGPoint points[6];
+  points[0] = CGPointMake(13.0f, 4.0f);
+  points[1] = CGPointMake(3.0f, 14.0f);
+  points[2] = CGPointMake(13.0f, 8.0f);
+  points[3] = CGPointMake(7.0f, 14.0f);
+  points[4] = CGPointMake(13.0f, 12.0f);
+  points[5] = CGPointMake(11.0f, 14.0f);
+  CGContextSetRGBStrokeColor(ctx, 0.00f, 0.00f, 0.00f, 0.15f);
+  CGContextStrokeLineSegments(ctx, points, 6);
+
+  points[0] = CGPointMake(13.0f, 5.0f);
+  points[1] = CGPointMake(4.0f, 14.0f);
+  points[2] = CGPointMake(13.0f, 9.0f);
+  points[3] = CGPointMake(8.0f, 14.0f);
+  points[4] = CGPointMake(13.0f, 13.0f);
+  points[5] = CGPointMake(12.0f, 14.0f);
+  CGContextSetRGBStrokeColor(ctx, 0.13f, 0.13f, 0.13f, 0.54f);
+  CGContextStrokeLineSegments(ctx, points, 6);
+
+  points[0] = CGPointMake(13.0f, 6.0f);
+  points[1] = CGPointMake(5.0f, 14.0f);
+  points[2] = CGPointMake(13.0f, 10.0f);
+  points[3] = CGPointMake(9.0f, 14.0f);
+  points[5] = CGPointMake(13.0f, 13.9f);
+  points[4] = CGPointMake(13.0f, 14.0f);
+  CGContextSetRGBStrokeColor(ctx, 0.84f, 0.84f, 0.84f, 0.55f);
+  CGContextStrokeLineSegments(ctx, points, 6);
+
+  GLuint tex = 0;
+
+  ShaderProgramType shader =
+#ifdef MOZ_ENABLE_LIBXUL
+    manager->gl()->UploadSurfaceToTexture(image, nsIntRect(0, 0, 15, 15), tex);
+#else
+    manager->gl()->UploadSurfaceToTextureExternal(image, nsIntRect(0, 0, 15, 15), tex);
+#endif
+
+  ColorTextureLayerProgram *program =
+    manager->GetColorTextureLayerProgram(shader);
+  program->Activate();
+  program->SetLayerQuadRect(nsIntRect(bottomX - 15,
+                                      bottomY - 15,
+                                      15,
+                                      15));
+  program->SetLayerTransform(gfx3DMatrix());
+  program->SetLayerOpacity(1.0);
+  program->SetRenderOffset(nsIntPoint(0,0));
+  program->SetTextureUnit(0);
+
+  manager->BindAndDrawQuad(program);
+  manager->gl()->fDeleteTextures(1, &tex);
 }
 
 void
 nsChildView::UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries)
 {
   NSWindow* win = [mView window];
   if (!win || ![win isKindOfClass:[ToolbarWindow class]])
     return;
--- a/widget/src/cocoa/nsCocoaWindow.h
+++ b/widget/src/cocoa/nsCocoaWindow.h
@@ -271,17 +271,16 @@ public:
     virtual void SetDrawsInTitlebar(PRBool aState);
     virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
                                                 PRUint32 aNativeMessage,
                                                 PRUint32 aModifierFlags);
 
     void DispatchSizeModeEvent();
 
     virtual gfxASurface* GetThebesSurface();
-    virtual void DrawOver(LayerManager* aManager, nsIntRect aRect);
 
     // be notified that a some form of drag event needs to go into Gecko
     virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers);
 
     PRBool HasModalDescendents() { return mNumModalDescendents > 0; }
     NSWindow *GetCocoaWindow() { return mWindow; }
 
     void SetMenuBar(nsMenuBarX* aMenuBar);
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -66,27 +66,22 @@
 #include "nsStyleConsts.h"
 #include "nsNativeThemeColors.h"
 #include "nsChildView.h"
 #include "nsIMenuRollup.h"
 
 #include "gfxPlatform.h"
 #include "qcms.h"
 
-#include "GLContext.h"
-#include "LayerManagerOGL.h"
-#include "gfxQuartzSurface.h"
-
 namespace mozilla {
 namespace layers {
 class LayerManager;
 }
 }
 using namespace mozilla::layers;
-using namespace mozilla::gl;
 
 // defined in nsAppShell.mm
 extern nsCocoaAppModalWindowList *gCocoaAppModalWindowList;
 
 PRInt32 gXULModalLevel = 0;
 
 // In principle there should be only one app-modal window at any given time.
 // But sometimes, despite our best efforts, another window appears above the
@@ -941,89 +936,16 @@ LayerManager*
 nsCocoaWindow::GetLayerManager(LayerManagerPersistence, bool* aAllowRetaining)
 {
   if (mPopupContentView) {
     return mPopupContentView->GetLayerManager(aAllowRetaining);
   }
   return nsnull;
 }
 
-void
-nsCocoaWindow::DrawOver(LayerManager* aManager, nsIntRect aRect)
-{
-  if (!([mWindow styleMask] & NSResizableWindowMask)) {
-    return;
-  }
-
-  nsRefPtr<LayerManagerOGL> manager(static_cast<LayerManagerOGL*>(aManager));
-  if (!manager) {
-    return;
-  }
-  
-  float bottomX = aRect.x + aRect.width;
-  float bottomY = aRect.y + aRect.height;
-
-  nsRefPtr<gfxQuartzSurface> image =
-    new gfxQuartzSurface(gfxIntSize(15, 15), gfxASurface::ImageFormatARGB32);
-  CGContextRef ctx = image->GetCGContext();
-
-  CGContextSetShouldAntialias(ctx, false);
-  CGPoint points[6];
-  points[0] = CGPointMake(13.0f, 4.0f);
-  points[1] = CGPointMake(3.0f, 14.0f);
-  points[2] = CGPointMake(13.0f, 8.0f);
-  points[3] = CGPointMake(7.0f, 14.0f);
-  points[4] = CGPointMake(13.0f, 12.0f);
-  points[5] = CGPointMake(11.0f, 14.0f);
-  CGContextSetRGBStrokeColor(ctx, 0.00f, 0.00f, 0.00f, 0.15f);
-  CGContextStrokeLineSegments(ctx, points, 6);
-
-  points[0] = CGPointMake(13.0f, 5.0f);
-  points[1] = CGPointMake(4.0f, 14.0f);
-  points[2] = CGPointMake(13.0f, 9.0f);
-  points[3] = CGPointMake(8.0f, 14.0f);
-  points[4] = CGPointMake(13.0f, 13.0f);
-  points[5] = CGPointMake(12.0f, 14.0f);
-  CGContextSetRGBStrokeColor(ctx, 0.13f, 0.13f, 0.13f, 0.54f);
-  CGContextStrokeLineSegments(ctx, points, 6);
-
-  points[0] = CGPointMake(13.0f, 6.0f);
-  points[1] = CGPointMake(5.0f, 14.0f);
-  points[2] = CGPointMake(13.0f, 10.0f);
-  points[3] = CGPointMake(9.0f, 14.0f);
-  points[5] = CGPointMake(13.0f, 13.9f);
-  points[4] = CGPointMake(13.0f, 14.0f);
-  CGContextSetRGBStrokeColor(ctx, 0.84f, 0.84f, 0.84f, 0.55f);
-  CGContextStrokeLineSegments(ctx, points, 6);
-
-  GLuint tex = 0;
-
-  ShaderProgramType shader = 
-#ifdef MOZ_ENABLE_LIBXUL
-    manager->gl()->UploadSurfaceToTexture(image, nsIntRect(0, 0, 15, 15), tex);
-#else
-    manager->gl()->UploadSurfaceToTextureExternal(image, nsIntRect(0, 0, 15, 15), tex);
-#endif
-
-  ColorTextureLayerProgram *program =
-    manager->GetColorTextureLayerProgram(shader);
-  program->Activate();
-  program->SetLayerQuadRect(nsIntRect(bottomX - 15,
-                                      bottomY - 15,
-                                      15,
-                                      15));
-  program->SetLayerTransform(gfx3DMatrix());
-  program->SetLayerOpacity(1.0);
-  program->SetRenderOffset(nsIntPoint(0,0));
-  program->SetTextureUnit(0);
-
-  manager->BindAndDrawQuad(program);
-  manager->gl()->fDeleteTextures(1, &tex);
-}
-
 nsTransparencyMode nsCocoaWindow::GetTransparencyMode()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   return [mWindow isOpaque] ? eTransparencyOpaque : eTransparencyTransparent;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(eTransparencyOpaque);
 }