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
67
68
69
70
|
// 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"
#if USE(ACCELERATED_COMPOSITING)
#include "CanvasLayerTextureUpdater.h"
#include "CCRenderingStats.h"
#include "FloatRect.h"
#include "LayerPainterChromium.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRect.h"
#include "SkiaUtils.h"
#include "TraceEvent.h"
#include <wtf/CurrentTime.h>
namespace cc {
CanvasLayerTextureUpdater::CanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium> painter)
: m_painter(painter)
{
}
CanvasLayerTextureUpdater::~CanvasLayerTextureUpdater()
{
}
void CanvasLayerTextureUpdater::paintContents(SkCanvas* canvas, const IntRect& contentRect, float contentsWidthScale, float contentsHeightScale, IntRect& resultingOpaqueRect, CCRenderingStats& stats)
{
TRACE_EVENT0("cc", "CanvasLayerTextureUpdater::paintContents");
canvas->save();
canvas->translate(CCFloatToSkScalar(-contentRect.x()), CCFloatToSkScalar(-contentRect.y()));
IntRect layerRect = contentRect;
if (contentsWidthScale != 1 || contentsHeightScale != 1) {
canvas->scale(CCFloatToSkScalar(contentsWidthScale), CCFloatToSkScalar(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;
double paintBeginTime = monotonicallyIncreasingTime();
m_painter->paint(canvas, layerRect, opaqueLayerRect);
stats.totalPaintTimeInSeconds += monotonicallyIncreasingTime() - paintBeginTime;
canvas->restore();
FloatRect opaqueContentRect = opaqueLayerRect;
opaqueContentRect.scale(contentsWidthScale, contentsHeightScale);
resultingOpaqueRect = enclosedIntRect(opaqueContentRect);
m_contentRect = contentRect;
}
} // namespace cc
#endif // USE(ACCELERATED_COMPOSITING)
|