summaryrefslogtreecommitdiffstats
path: root/webkit/compositor_bindings/web_content_layer_impl.cc
blob: 504a459b634cdb723558b34aef148c9d6493677e (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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 "webkit/compositor_bindings/web_content_layer_impl.h"

#include "base/command_line.h"
#include "cc/content_layer.h"
#include "cc/picture_layer.h"
#include "cc/switches.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayerClient.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
#include "third_party/skia/include/utils/SkMatrix44.h"

using namespace cc;

namespace WebKit {

static bool usingPictureLayer()
{
    return CommandLine::ForCurrentProcess()->HasSwitch(cc::switches::kEnableImplSidePainting);
}

WebContentLayerImpl::WebContentLayerImpl(WebContentLayerClient* client)
    : m_client(client)
{
    if (usingPictureLayer())
        m_layer = make_scoped_ptr(new WebLayerImpl(PictureLayer::create(this)));
    else
        m_layer = make_scoped_ptr(new WebLayerImpl(ContentLayer::create(this)));
    m_layer->layer()->setIsDrawable(true);
}

WebContentLayerImpl::~WebContentLayerImpl()
{
    if (usingPictureLayer())
        static_cast<PictureLayer*>(m_layer->layer())->clearClient();
    else
        static_cast<ContentLayer*>(m_layer->layer())->clearClient();
}

WebLayer* WebContentLayerImpl::layer()
{
    return m_layer.get();
}

void WebContentLayerImpl::setDoubleSided(bool doubleSided)
{
    m_layer->layer()->setDoubleSided(doubleSided);
}

void WebContentLayerImpl::setBoundsContainPageScale(bool boundsContainPageScale)
{
    return m_layer->layer()->setBoundsContainPageScale(boundsContainPageScale);
}

bool WebContentLayerImpl::boundsContainPageScale() const
{
    return m_layer->layer()->boundsContainPageScale();
}

void WebContentLayerImpl::setAutomaticallyComputeRasterScale(bool automatic)
{
  m_layer->layer()->setAutomaticallyComputeRasterScale(automatic);
}

// TODO(alokp): Remove this function from WebContentLayer API.
void WebContentLayerImpl::setUseLCDText(bool enable)
{
}

void WebContentLayerImpl::setDrawCheckerboardForMissingTiles(bool enable)
{
    m_layer->layer()->setDrawCheckerboardForMissingTiles(enable);
}


void WebContentLayerImpl::paintContents(SkCanvas* canvas, const gfx::Rect& clip, gfx::RectF& opaque)
{
    if (!m_client)
        return;

    bool useLCDText = usingPictureLayer() ?
            false :
            static_cast<ContentLayer*>(m_layer->layer())->useLCDText();
    WebFloatRect webOpaque;
    m_client->paintContents(canvas, clip, useLCDText, webOpaque);
    opaque = webOpaque;
}

} // namespace WebKit