Back out 4b82f26f8593:2fcf9cbedd48 (bug 743393, bug 719776) for bustage
authorPhil Ringnalda <philringnalda@gmail.com>
Wed, 11 Apr 2012 09:06:40 -0700
changeset 94747 ed7531e3906623539ba95963ab9c3d17082ab1bb
parent 94746 022be5c5073244276e949327f7339cf7f8335389
child 94748 305e5980de923618abda73d6ea3d86b1779b1395
push idunknown
push userunknown
push dateunknown
bugs743393, 719776
milestone14.0a1
backs out4b82f26f8593af632e852833fae06c8d4263d606
Back out 4b82f26f8593:2fcf9cbedd48 (bug 743393, bug 719776) for bustage
gfx/layers/d3d10/LayerManagerD3D10.cpp
gfx/layers/d3d10/LayerManagerD3D10.h
gfx/layers/d3d10/ThebesLayerD3D10.cpp
gfx/layers/d3d10/ThebesLayerD3D10.h
js/public/Utility.h
js/src/assembler/wtf/Assertions.h
js/src/jscntxt.h
mfbt/Assertions.h
--- a/gfx/layers/d3d10/LayerManagerD3D10.cpp
+++ b/gfx/layers/d3d10/LayerManagerD3D10.cpp
@@ -533,28 +533,16 @@ LayerManagerD3D10::SetViewport(const nsI
     SetRawValue(&projection._11, 0, 64);
 
   if (FAILED(hr)) {
     NS_WARNING("Failed to set projection matrix.");
   }
 }
 
 void
-LayerManagerD3D10::SetupInputAssembler()
-{
-  mDevice->IASetInputLayout(mInputLayout);
-
-  UINT stride = sizeof(Vertex);
-  UINT offset = 0;
-  ID3D10Buffer *buffer = mVertexBuffer;
-  mDevice->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
-  mDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
-}
-
-void
 LayerManagerD3D10::SetupPipeline()
 {
   VerifyBufferSize();
   UpdateRenderTarget();
 
   nsIntRect rect;
   mWidget->GetClientBounds(rect);
 
@@ -565,18 +553,23 @@ LayerManagerD3D10::SetupPipeline()
 
   if (FAILED(hr)) {
     NS_WARNING("Failed to set Texture Coordinates.");
     return;
   }
 
   ID3D10RenderTargetView *view = mRTView;
   mDevice->OMSetRenderTargets(1, &view, NULL);
+  mDevice->IASetInputLayout(mInputLayout);
 
-  SetupInputAssembler();
+  UINT stride = sizeof(Vertex);
+  UINT offset = 0;
+  ID3D10Buffer *buffer = mVertexBuffer;
+  mDevice->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
+  mDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
 
   SetViewport(nsIntSize(rect.width, rect.height));
 }
 
 void
 LayerManagerD3D10::UpdateRenderTarget()
 {
   if (mRTView) {
--- a/gfx/layers/d3d10/LayerManagerD3D10.h
+++ b/gfx/layers/d3d10/LayerManagerD3D10.h
@@ -179,17 +179,16 @@ public:
   // Public helpers
 
   ID3D10Device1 *device() const { return mDevice; }
 
   ID3D10Effect *effect() const { return mEffect; }
 
   ReadbackManagerD3D10 *readbackManager();
 
-  void SetupInputAssembler();
   void SetViewport(const nsIntSize &aViewport);
   const nsIntSize &GetViewport() { return mViewport; }
 
   /**
    * Return pointer to the Nv3DVUtils instance
    */
   Nv3DVUtils *GetNv3DVUtils()  { return mNv3DVUtils; }
 
--- a/gfx/layers/d3d10/ThebesLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.cpp
@@ -361,44 +361,66 @@ ThebesLayerD3D10::VerifyContentType(Surf
     mD2DSurfaceOnWhite = nsnull;
     mSRViewOnWhite = nsnull;
     mTextureOnWhite = nsnull;
     mValidRegion.SetEmpty();
   }
 }
 
 void
+ThebesLayerD3D10::SetupDualViewports(const gfxIntSize &aSize)
+{
+    D3D10_VIEWPORT viewport;
+    viewport.MaxDepth = 1.0f;
+    viewport.MinDepth = 0;
+    viewport.Width = aSize.width;
+    viewport.Height = aSize.height;
+    viewport.TopLeftX = 0;
+    viewport.TopLeftY = 0;
+
+    D3D10_VIEWPORT vps[2] = { viewport, viewport };
+    device()->RSSetViewports(2, vps);
+
+    gfx3DMatrix projection;
+    /*
+     * Matrix to transform to viewport space ( <-1.0, 1.0> topleft,
+     * <1.0, -1.0> bottomright)
+     */
+    projection._11 = 2.0f / aSize.width;
+    projection._22 = -2.0f / aSize.height;
+    projection._33 = 0.0f;
+    projection._41 = -1.0f;
+    projection._42 = 1.0f;
+    projection._44 = 1.0f;
+
+    effect()->GetVariableByName("mProjection")->
+      SetRawValue(&projection._11, 0, 64);
+}
+
+void
 ThebesLayerD3D10::FillTexturesBlackWhite(const nsIntRegion& aRegion, const nsIntPoint& aOffset)
 {
   if (mTexture && mTextureOnWhite) {
     // It would be more optimal to draw the actual geometry, but more code
     // and probably not worth the win here as this will often be a single
     // rect.
     nsRefPtr<ID3D10RenderTargetView> oldRT;
     device()->OMGetRenderTargets(1, getter_AddRefs(oldRT), NULL);
 
     nsRefPtr<ID3D10RenderTargetView> viewBlack;
     nsRefPtr<ID3D10RenderTargetView> viewWhite;
     device()->CreateRenderTargetView(mTexture, NULL, getter_AddRefs(viewBlack));
     device()->CreateRenderTargetView(mTextureOnWhite, NULL, getter_AddRefs(viewWhite));
 
-    D3D10_RECT oldScissor;
-    UINT numRects = 1;
-    device()->RSGetScissorRects(&numRects, &oldScissor);
-
     D3D10_TEXTURE2D_DESC desc;
     mTexture->GetDesc(&desc);
 
-    D3D10_RECT scissor = { 0, 0, desc.Width, desc.Height };
-    device()->RSSetScissorRects(1, &scissor);
-
-    mD3DManager->SetupInputAssembler();
     nsIntSize oldVP = mD3DManager->GetViewport();
 
-    mD3DManager->SetViewport(nsIntSize(desc.Width, desc.Height));
+    SetupDualViewports(gfxIntSize(desc.Width, desc.Height));
 
     ID3D10RenderTargetView *views[2] = { viewBlack, viewWhite };
     device()->OMSetRenderTargets(2, views, NULL);
 
     gfx3DMatrix transform;
     transform.Translate(gfxPoint3D(-aOffset.x, -aOffset.y, 0));
     void* raw = &const_cast<gfx3DMatrix&>(transform)._11;
     effect()->GetVariableByName("mLayerTransform")->SetRawValue(raw, 0, 64);
@@ -420,17 +442,16 @@ ThebesLayerD3D10::FillTexturesBlackWhite
 
       technique->GetPassByIndex(0)->Apply(0);
       device()->Draw(4, 0);
     }
 
     views[0] = oldRT;
     device()->OMSetRenderTargets(1, views, NULL);
     mD3DManager->SetViewport(oldVP);
-    device()->RSSetScissorRects(1, &oldScissor);
   }
 }
 
 void
 ThebesLayerD3D10::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode)
 {
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
 
--- a/gfx/layers/d3d10/ThebesLayerD3D10.h
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.h
@@ -92,16 +92,18 @@ private:
   nsRefPtr<gfxASurface> mD2DSurfaceOnWhite;
 
   /* Have a region of our layer drawn */
   void DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode);
 
   /* Create a new texture */
   void CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode);
 
+  void SetupDualViewports(const gfxIntSize &aSize);
+  
   // Fill textures with opaque black and white in the specified region.
   void FillTexturesBlackWhite(const nsIntRegion& aRegion, const nsIntPoint& aOffset);
 
   /* Copy a texture region */
   void CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
                   ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
                   const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion);
 };
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -327,16 +327,32 @@ unsigned char _BitScanReverse64(unsigned
             (_log2) += 4, (j_) >>= 4;                                         \
         if ((j_) >> 2)                                                        \
             (_log2) += 2, (j_) >>= 2;                                         \
         if ((j_) >> 1)                                                        \
             (_log2) += 1;                                                     \
     JS_END_MACRO
 #endif
 
+/*
+ * Internal function.
+ * Compute the log of the least power of 2 greater than or equal to n. This is
+ * a version of JS_CeilingLog2 that operates on unsigned integers with
+ * CPU-dependant size.
+ */
+#define JS_CEILING_LOG2W(n) ((n) <= 1 ? 0 : 1 + JS_FLOOR_LOG2W((n) - 1))
+
+/*
+ * Internal function.
+ * Compute the log of the greatest power of 2 less than or equal to n.
+ * This is a version of JS_FloorLog2 that operates on unsigned integers with
+ * CPU-dependant size and requires that n != 0.
+ */
+#define JS_FLOOR_LOG2W(n) (JS_ASSERT((n) != 0), js_FloorLog2wImpl(n))
+
 #if JS_BYTES_PER_WORD == 4
 # ifdef JS_HAS_BUILTIN_BITSCAN32
 #  define js_FloorLog2wImpl(n)                                                \
     ((size_t)(JS_BITS_PER_WORD - 1 - js_bitscan_clz32(n)))
 # else
 JS_PUBLIC_API(size_t) js_FloorLog2wImpl(size_t n);
 # endif
 #elif JS_BYTES_PER_WORD == 8
@@ -345,37 +361,16 @@ JS_PUBLIC_API(size_t) js_FloorLog2wImpl(
     ((size_t)(JS_BITS_PER_WORD - 1 - js_bitscan_clz64(n)))
 # else
 JS_PUBLIC_API(size_t) js_FloorLog2wImpl(size_t n);
 # endif
 #else
 # error "NOT SUPPORTED"
 #endif
 
-/*
- * Internal function.
- * Compute the log of the least power of 2 greater than or equal to n. This is
- * a version of JS_CeilingLog2 that operates on unsigned integers with
- * CPU-dependant size.
- */
-#define JS_CEILING_LOG2W(n) ((n) <= 1 ? 0 : 1 + JS_FLOOR_LOG2W((n) - 1))
-
-/*
- * Internal function.
- * Compute the log of the greatest power of 2 less than or equal to n.
- * This is a version of JS_FloorLog2 that operates on unsigned integers with
- * CPU-dependant size and requires that n != 0.
- */
-static MOZ_ALWAYS_INLINE size_t
-JS_FLOOR_LOG2W(size_t n)
-{
-    JS_ASSERT(n != 0);
-    return js_FloorLog2wImpl(n);
-}
-
 JS_END_EXTERN_C
 
 #ifdef __cplusplus
 #include <new>
 
 /*
  * User guide to memory management within SpiderMonkey:
  *
--- a/js/src/assembler/wtf/Assertions.h
+++ b/js/src/assembler/wtf/Assertions.h
@@ -33,22 +33,19 @@
    /*
     * Prevent unused-variable warnings by defining the macro WTF uses to test
     * for assertions taking effect.
     */
 #  define ASSERT_DISABLED 1
 #endif
 
 #define ASSERT(assertion) MOZ_ASSERT(assertion)
-#define ASSERT_UNUSED(variable, assertion) do { \
-    (void)variable; \
-    ASSERT(assertion); \
-} while (0)
+#define ASSERT_UNUSED(variable, assertion) (((void)variable), ASSERT(assertion))
 #define ASSERT_NOT_REACHED() MOZ_NOT_REACHED("")
-#define CRASH() MOZ_CRASH()
+#define CRASH() MOZ_Crash()
 #define COMPILE_ASSERT(exp, name) MOZ_STATIC_ASSERT(exp, #name)
 
 #endif
 
 #if 0
 /*
    no namespaces because this file has to be includable from C and Objective-C
 
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -1531,43 +1531,40 @@ extern JSErrorFormatString js_ErrorForma
 
 #ifdef JS_THREADSAFE
 # define JS_ASSERT_REQUEST_DEPTH(cx)  JS_ASSERT((cx)->runtime->requestDepth >= 1)
 #else
 # define JS_ASSERT_REQUEST_DEPTH(cx)  ((void) 0)
 #endif
 
 /*
+ * If the operation callback flag was set, call the operation callback.
+ * This macro can run the full GC. Return true if it is OK to continue and
+ * false otherwise.
+ */
+#define JS_CHECK_OPERATION_LIMIT(cx)                                          \
+    (JS_ASSERT_REQUEST_DEPTH(cx),                                             \
+     (!cx->runtime->interrupt || js_InvokeOperationCallback(cx)))
+
+/*
  * Invoke the operation callback and return false if the current execution
  * is to be terminated.
  */
 extern JSBool
 js_InvokeOperationCallback(JSContext *cx);
 
 extern JSBool
 js_HandleExecutionInterrupt(JSContext *cx);
 
 extern jsbytecode*
 js_GetCurrentBytecodePC(JSContext* cx);
 
 extern JSScript *
 js_GetCurrentScript(JSContext* cx);
 
-/*
- * If the operation callback flag was set, call the operation callback.
- * This macro can run the full GC. Return true if it is OK to continue and
- * false otherwise.
- */
-static MOZ_ALWAYS_INLINE bool
-JS_CHECK_OPERATION_LIMIT(JSContext *cx)
-{
-    JS_ASSERT_REQUEST_DEPTH(cx);
-    return !cx->runtime->interrupt || js_InvokeOperationCallback(cx);
-}
-
 namespace js {
 
 #ifdef JS_METHODJIT
 namespace mjit {
     void ExpandInlineFrames(JSCompartment *compartment);
 }
 #endif
 
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -1,9 +1,9 @@
-/* -*- 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: 4 -*-
  * vim: set ts=8 sw=4 et tw=99 ft=cpp:
  *
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
@@ -41,25 +41,16 @@
 /* Implementations of runtime and static assertion macros for C and C++. */
 
 #ifndef mozilla_Assertions_h_
 #define mozilla_Assertions_h_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/Types.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#ifndef WIN32
-#  include <signal.h>
-#endif
-#ifdef ANDROID
-#  include <android/log.h>
-#endif
-
 /*
  * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time*.  This
  * can be useful when you make certain assumptions about what must hold for
  * optimal, or even correct, behavior.  For example, you might assert that the
  * size of a struct is a multiple of the target architecture's word size:
  *
  *   struct S { ... };
  *   MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0,
@@ -135,69 +126,22 @@
 #endif
 
 #define MOZ_STATIC_ASSERT_IF(cond, expr, reason)  MOZ_STATIC_ASSERT(!(cond) || (expr), reason)
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#if defined(WIN32)
-   /*
-    * We used to call DebugBreak() on Windows, but amazingly, it causes
-    * the MSVS 2010 debugger not to be able to recover a call stack.
-    */
-#  define MOZ_CRASH() \
-     do { \
-       *((volatile int *) NULL) = 123; \
-       exit(3); \
-     } while (0)
-#elif defined(ANDROID)
-   /*
-    * On Android, raise(SIGABRT) is handled asynchronously. Seg fault now
-    * so we crash immediately and capture the current call stack.
-    */
-#  define MOZ_CRASH() \
-     do { \
-       *((volatile int *) NULL) = 123; \
-       abort(); \
-     } while (0)
-#elif defined(__APPLE__)
-   /*
-    * On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
-    * trapped.
-    */
-#  define MOZ_CRASH() \
-     do { \
-       *((volatile int *) NULL) = 123; \
-       raise(SIGABRT);  /* In case above statement gets nixed by the optimizer. */ \
-     } while (0)
-#else
-#  define MOZ_CRASH() \
-     do { \
-       raise(SIGABRT);  /* To continue from here in GDB: "signal 0". */ \
-     } while (0)
-#endif
-
+extern MFBT_API(void)
+MOZ_Crash(void);
 
 extern MFBT_API(void)
 MOZ_Assert(const char* s, const char* file, int ln);
 
-static MOZ_ALWAYS_INLINE void
-MOZ_OutputAssertMessage(const char* s, const char *file, int ln)
-{
-#ifdef ANDROID
-  __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert",
-                      "Assertion failure: %s, at %s:%d\n", s, file, ln);
-#else
-  fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
-  fflush(stderr);
-#endif
-}
-
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
 /*
  * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in
  * debug builds.  If it is, execution continues.  Otherwise, an error message
  * including the expression and the explanation-string (if provided) is printed,
@@ -227,30 +171,20 @@ MOZ_OutputAssertMessage(const char* s, c
  *              "we already set [[PrimitiveThis]] for this String object");
  *
  * MOZ_ASSERT has no effect in non-debug builds.  It is designed to catch bugs
  * *only* during debugging, not "in the field".
  */
 #ifdef DEBUG
    /* First the single-argument form. */
 #  define MOZ_ASSERT_HELPER1(expr) \
-     do { \
-       if (expr) { \
-         MOZ_OutputAssertMessage(#expr, __FILE__, __LINE__); \
-         MOZ_CRASH(); \
-       } \
-     } while (0)
+     ((expr) ? ((void)0) : MOZ_Assert(#expr, __FILE__, __LINE__))
    /* Now the two-argument form. */
 #  define MOZ_ASSERT_HELPER2(expr, explain) \
-     do { \
-       if (expr) { \
-         MOZ_OutputAssertMessage(#expr " (" explain ")", __FILE__, __LINE__); \
-         MOZ_CRASH(); \
-       } \
-     } while (0)
+     ((expr) ? ((void)0) : MOZ_Assert(#expr " (" explain ")", __FILE__, __LINE__))
    /* And now, helper macrology up the wazoo. */
    /*
     * Count the number of arguments passed to MOZ_ASSERT, very carefully
     * tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a
     * single token in argument lists.  See these URLs for details:
     *
     *   http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement
     *   http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644
@@ -266,36 +200,32 @@ MOZ_OutputAssertMessage(const char* s, c
 #  define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count)
 #  define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count)
    /* The actual macro. */
 #  define MOZ_ASSERT_GLUE(x, y) x y
 #  define MOZ_ASSERT(...) \
      MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \
                      (__VA_ARGS__))
 #else
-#  define MOZ_ASSERT(...) do { } while(0)
+#  define MOZ_ASSERT(...) ((void)0)
 #endif /* DEBUG */
 
 /*
  * MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is
  * true.
  *
  *   MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num));
  *
  * As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds.  It is
  * designed to catch bugs during debugging, not "in the field".
  */
 #ifdef DEBUG
-#  define MOZ_ASSERT_IF(cond, expr) \
-     do { \
-       if ((cond)) \
-         MOZ_ASSERT(expr); \
-     } while (0)
+#  define MOZ_ASSERT_IF(cond, expr)  ((cond) ? MOZ_ASSERT(expr) : ((void)0))
 #else
-#  define MOZ_ASSERT_IF(cond, expr)  do { } while (0)
+#  define MOZ_ASSERT_IF(cond, expr)  ((void)0)
 #endif
 
 /* MOZ_NOT_REACHED_MARKER() expands (in compilers which support it) to an
  * expression which states that it is undefined behavior for the compiler to
  * reach this point. Most code should probably use the higher level
  * MOZ_NOT_REACHED (which expands to this when appropriate).
  */
 #if defined(__clang__)