b=561168; convert canvas to use layers for rendering - followup #2; r=roc
authorVladimir Vukicevic <vladimir@pobox.com>
Mon, 17 May 2010 21:04:22 -0700
changeset 42404 56f033dd888a56adcaa92aaf9b14b8d8ff6ac78e
parent 42403 f3d0956d3413614a9af21bf76187817578b26069
child 42405 94591caa7f0c6317b8191068c27ccd86dcfaa688
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs561168
milestone1.9.3a5pre
b=561168; convert canvas to use layers for rendering - followup #2; r=roc
gfx/layers/Layers.h
gfx/layers/basic/BasicLayers.cpp
layout/generic/nsHTMLCanvasFrame.cpp
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -42,16 +42,17 @@
 #include "gfxASurface.h"
 #include "nsRegion.h"
 #include "nsPoint.h"
 #include "nsRect.h"
 #include "nsISupportsImpl.h"
 #include "nsAutoPtr.h"
 #include "gfx3DMatrix.h"
 #include "gfxColor.h"
+#include "gfxPattern.h"
 
 class gfxContext;
 class nsPaintEvent;
 
 namespace mozilla {
 namespace gl {
 class GLContext;
 }
@@ -491,17 +492,26 @@ public:
    * CONSTRUCTION PHASE ONLY
    * Notify this CanvasLayer that the rectangle given by aRect
    * has been updated, and any work that needs to be done
    * to bring the contents from the Surface/GLContext to the
    * Layer in preparation for compositing should be performed.
    */
   virtual void Updated(const nsIntRect& aRect) = 0;
 
+  /**
+   * CONSTRUCTION PHASE ONLY
+   * Set the filter used to resample this image (if necessary).
+   */
+  void SetFilter(gfxPattern::GraphicsFilter aFilter) { mFilter = aFilter; }
+  gfxPattern::GraphicsFilter GetFilter() const { return mFilter; }
+
 protected:
   CanvasLayer(LayerManager* aManager, void* aImplData)
-    : Layer(aManager, aImplData) {}
+    : Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD) {}
+
+  gfxPattern::GraphicsFilter mFilter;
 };
 
 }
 }
 
 #endif /* GFX_LAYERS_H */
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -483,16 +483,18 @@ BasicCanvasLayer::Updated(const nsIntRec
                "CanvasLayer: Updated rect bigger than bounds!");
 }
 
 void
 BasicCanvasLayer::Paint(gfxContext* aContext)
 {
   nsRefPtr<gfxPattern> pat = new gfxPattern(mSurface);
 
+  pat->SetFilter(mFilter);
+
   gfxRect r(0, 0, mBounds.width, mBounds.height);
   gfxMatrix m;
   if (mNeedsYFlip) {
     m = aContext->CurrentMatrix();
     aContext->Translate(gfxPoint(0.0, mBounds.height));
     aContext->Scale(1.0, -1.0);
   }
 
--- a/layout/generic/nsHTMLCanvasFrame.cpp
+++ b/layout/generic/nsHTMLCanvasFrame.cpp
@@ -256,16 +256,17 @@ nsHTMLCanvasFrame::BuildLayer(nsDisplayL
                       presContext->AppUnitsToGfxUnits(area.width),
                       presContext->AppUnitsToGfxUnits(area.height));
 
   // Transform the canvas into the right place
   gfxMatrix transform;
   transform.Translate(r.pos);
   transform.Scale(r.Width()/canvasSize.width, r.Height()/canvasSize.height);
   layer->SetTransform(gfx3DMatrix::From2D(transform));
+  layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this));
 
   nsRefPtr<Layer> result = layer.forget();
   return result.forget();
 }
 
 NS_IMETHODIMP
 nsHTMLCanvasFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                     const nsRect&           aDirtyRect,