Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 #include "config.h"
     28 #include "WebViewBenchmarkSupportImpl.h"
     29 
     30 #include "WebViewImpl.h"
     31 #include "core/page/FrameView.h"
     32 #include "core/platform/graphics/FloatSize.h"
     33 #include "core/platform/graphics/GraphicsContext.h"
     34 #include "core/platform/graphics/GraphicsLayer.h"
     35 #include "core/platform/graphics/IntRect.h"
     36 #include "core/platform/graphics/IntSize.h"
     37 
     38 #include "public/platform/WebCanvas.h"
     39 #include "wtf/CurrentTime.h"
     40 #include "wtf/OwnPtr.h"
     41 #include "wtf/Vector.h"
     42 
     43 using namespace WebCore;
     44 
     45 namespace WebKit {
     46 
     47 void WebViewBenchmarkSupportImpl::paintLayer(PaintClient* paintClient, GraphicsLayer& layer, const IntRect& clip)
     48 {
     49     WebSize canvasSize(clip.width(), clip.height());
     50     WebCanvas* canvas = paintClient->willPaint(canvasSize);
     51     GraphicsContext context(canvas);
     52 
     53     layer.paintGraphicsLayerContents(context, clip);
     54     paintClient->didPaint(canvas);
     55 }
     56 
     57 void WebViewBenchmarkSupportImpl::acceleratedPaintUnclipped(PaintClient* paintClient, GraphicsLayer& layer)
     58 {
     59     FloatSize layerSize = layer.size();
     60     IntRect clip(0, 0, layerSize.width(), layerSize.height());
     61 
     62     if (layer.drawsContent())
     63         paintLayer(paintClient, layer, clip);
     64 
     65     const Vector<GraphicsLayer*>& children = layer.children();
     66     Vector<GraphicsLayer*>::const_iterator it;
     67     for (it = children.begin(); it != children.end(); ++it)
     68         acceleratedPaintUnclipped(paintClient, **it);
     69 }
     70 
     71 void WebViewBenchmarkSupportImpl::softwarePaint(PaintClient* paintClient, PaintMode paintMode)
     72 {
     73     WebSize size = m_webViewImpl->size();
     74     WebRect paintSize;
     75     switch (paintMode) {
     76     case PaintModeEverything:
     77         if (m_webViewImpl->page() && m_webViewImpl->page()->mainFrame()) {
     78             FrameView* view = m_webViewImpl->page()->mainFrame()->view();
     79             IntSize contentsSize = view->contentsSize();
     80             paintSize = WebRect(0, 0, contentsSize.width(), contentsSize.height());
     81         } else
     82             paintSize = WebRect(0, 0, size.width, size.height);
     83         break;
     84     }
     85 
     86     WebSize canvasSize(paintSize.width, paintSize.height);
     87     WebCanvas* canvas = paintClient->willPaint(canvasSize);
     88     m_webViewImpl->paint(canvas, paintSize);
     89     paintClient->didPaint(canvas);
     90 }
     91 
     92 void WebViewBenchmarkSupportImpl::paint(PaintClient* paintClient, PaintMode paintMode)
     93 {
     94     m_webViewImpl->layout();
     95     if (!m_webViewImpl->isAcceleratedCompositingActive())
     96         return softwarePaint(paintClient, paintMode);
     97     GraphicsLayer* layer = m_webViewImpl->rootGraphicsLayer();
     98     switch (paintMode) {
     99     case PaintModeEverything:
    100         acceleratedPaintUnclipped(paintClient, *layer);
    101         break;
    102     }
    103 }
    104 }
    105