summaryrefslogtreecommitdiffstats
path: root/cc/content_layer_updater.cc
blob: b151bfb34736822ca8d28e134fc3569216e7eb34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "cc/content_layer_updater.h"

#include "FloatRect.h"
#include "SkiaUtils.h"
#include "base/debug/trace_event.h"
#include "base/time.h"
#include "cc/layer_painter.h"
#include "cc/rendering_stats.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkRect.h"

namespace cc {

ContentLayerUpdater::ContentLayerUpdater(scoped_ptr<LayerPainter> painter)
    : m_painter(painter.Pass())
{
}

ContentLayerUpdater::~ContentLayerUpdater()
{
}

void ContentLayerUpdater::paintContents(SkCanvas* canvas, const IntRect& contentRect, float contentsWidthScale, float contentsHeightScale, IntRect& resultingOpaqueRect, RenderingStats& stats)
{
    TRACE_EVENT0("cc", "ContentLayerUpdater::paintContents");
    canvas->save();
    canvas->translate(FloatToSkScalar(-contentRect.x()), FloatToSkScalar(-contentRect.y()));

    IntRect layerRect = contentRect;

    if (contentsWidthScale != 1 || contentsHeightScale != 1) {
        canvas->scale(FloatToSkScalar(contentsWidthScale), FloatToSkScalar(contentsHeightScale));

        FloatRect rect = contentRect;
        rect.scale(1 / contentsWidthScale, 1 / contentsHeightScale);
        layerRect = enclosingIntRect(rect);
    }

    SkPaint paint;
    paint.setAntiAlias(false);
    paint.setXfermodeMode(SkXfermode::kClear_Mode);
    SkRect layerSkRect = SkRect::MakeXYWH(layerRect.x(), layerRect.y(), layerRect.width(), layerRect.height());
    canvas->drawRect(layerSkRect, paint);
    canvas->clipRect(layerSkRect);

    FloatRect opaqueLayerRect;
    base::TimeTicks paintBeginTime = base::TimeTicks::Now();
    m_painter->paint(canvas, layerRect, opaqueLayerRect);
    stats.totalPaintTimeInSeconds += (base::TimeTicks::Now() - paintBeginTime).InSecondsF();
    canvas->restore();

    FloatRect opaqueContentRect = opaqueLayerRect;
    opaqueContentRect.scale(contentsWidthScale, contentsHeightScale);
    resultingOpaqueRect = enclosedIntRect(opaqueContentRect);

    m_contentRect = contentRect;
}

} // namespace cc