Bug 811836. Fast path eCSSUnit_Color colors when parsing colors in canvas. r=dholbert
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Wed, 14 Nov 2012 12:46:26 -0800
changeset 113281 a858e1fa0bcc5157ac7441db2e7b1b0fa96f354c
parent 113280 2fc346d2488a789a570596d0d818db9a50001104
child 113282 4789d67c601738d05935747991ae157b2385d03e
push id23864
push userryanvm@gmail.com
push dateThu, 15 Nov 2012 02:43:16 +0000
treeherdermozilla-central@7845cfa93e3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs811836
milestone19.0a1
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 811836. Fast path eCSSUnit_Color colors when parsing colors in canvas. r=dholbert This will avoid doing extra work/flushing layout in the common case.
content/canvas/src/CanvasRenderingContext2D.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -586,27 +586,33 @@ CanvasRenderingContext2D::ParseColor(con
   // Pass the CSS Loader object to the parser, to allow parser error
   // reports to include the outer window ID.
   nsCSSParser parser(document ? document->CSSLoader() : nullptr);
   nsCSSValue value;
   if (!parser.ParseColorString(aString, nullptr, 0, value)) {
     return false;
   }
 
-  nsIPresShell* presShell = GetPresShell();
-  nsRefPtr<nsStyleContext> parentContext;
-  if (mCanvasElement && mCanvasElement->IsInDoc()) {
-    // Inherit from the canvas element.
-    parentContext = nsComputedDOMStyle::GetStyleContextForElement(
-      mCanvasElement, nullptr, presShell);
+  if (value.GetUnit() == nsCSSUnit::eCSSUnit_Color) {
+    // if we already have a color we can just use it directly
+    *aColor = value.GetColorValue();
+  } else {
+    // otherwise resolve it
+    nsIPresShell* presShell = GetPresShell();
+    nsRefPtr<nsStyleContext> parentContext;
+    if (mCanvasElement && mCanvasElement->IsInDoc()) {
+      // Inherit from the canvas element.
+      parentContext = nsComputedDOMStyle::GetStyleContextForElement(
+        mCanvasElement, nullptr, presShell);
+    }
+
+    unused << nsRuleNode::ComputeColor(
+      value, presShell ? presShell->GetPresContext() : nullptr, parentContext,
+      *aColor);
   }
-
-  unused << nsRuleNode::ComputeColor(
-    value, presShell ? presShell->GetPresContext() : nullptr, parentContext,
-    *aColor);
   return true;
 }
 
 nsresult
 CanvasRenderingContext2D::Reset()
 {
   if (mCanvasElement) {
     mCanvasElement->InvalidateCanvas();