[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / cc / blink / web_content_layer_impl.cc
blob4ccd763908686e31d2818548c4c4330c4caf4ff6
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/blink/web_content_layer_impl.h"
7 #include "cc/blink/web_display_item_list_impl.h"
8 #include "cc/layers/picture_layer.h"
9 #include "cc/playback/display_item_list_settings.h"
10 #include "third_party/WebKit/public/platform/WebContentLayerClient.h"
11 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
12 #include "third_party/WebKit/public/platform/WebFloatRect.h"
13 #include "third_party/WebKit/public/platform/WebRect.h"
14 #include "third_party/WebKit/public/platform/WebSize.h"
15 #include "third_party/skia/include/utils/SkMatrix44.h"
17 using cc::PictureLayer;
19 namespace cc_blink {
21 static blink::WebContentLayerClient::PaintingControlSetting
22 PaintingControlToWeb(
23 cc::ContentLayerClient::PaintingControlSetting painting_control) {
24 switch (painting_control) {
25 case cc::ContentLayerClient::PAINTING_BEHAVIOR_NORMAL:
26 return blink::WebContentLayerClient::PaintDefaultBehavior;
27 case cc::ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED:
28 return blink::WebContentLayerClient::DisplayListConstructionDisabled;
29 case cc::ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED:
30 return blink::WebContentLayerClient::DisplayListCachingDisabled;
31 case cc::ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED:
32 return blink::WebContentLayerClient::DisplayListPaintingDisabled;
34 NOTREACHED();
35 return blink::WebContentLayerClient::PaintDefaultBehavior;
38 WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client)
39 : client_(client) {
40 layer_ = make_scoped_ptr(new WebLayerImpl(
41 PictureLayer::Create(WebLayerImpl::LayerSettings(), this)));
42 layer_->layer()->SetIsDrawable(true);
45 WebContentLayerImpl::~WebContentLayerImpl() {
46 static_cast<PictureLayer*>(layer_->layer())->ClearClient();
49 blink::WebLayer* WebContentLayerImpl::layer() {
50 return layer_.get();
53 void WebContentLayerImpl::setDoubleSided(bool double_sided) {
54 layer_->layer()->SetDoubleSided(double_sided);
57 void WebContentLayerImpl::PaintContents(
58 SkCanvas* canvas,
59 const gfx::Rect& clip,
60 cc::ContentLayerClient::PaintingControlSetting painting_control) {
61 if (!client_)
62 return;
64 client_->paintContents(canvas, clip, PaintingControlToWeb(painting_control));
67 scoped_refptr<cc::DisplayItemList>
68 WebContentLayerImpl::PaintContentsToDisplayList(
69 const gfx::Rect& clip,
70 cc::ContentLayerClient::PaintingControlSetting painting_control) {
71 cc::DisplayItemListSettings settings;
72 settings.use_cached_picture = true;
74 scoped_refptr<cc::DisplayItemList> display_list =
75 cc::DisplayItemList::Create(clip, settings);
76 if (client_) {
77 WebDisplayItemListImpl list(display_list.get());
78 client_->paintContents(&list, clip, PaintingControlToWeb(painting_control));
80 display_list->Finalize();
81 return display_list;
84 bool WebContentLayerImpl::FillsBoundsCompletely() const {
85 return false;
88 size_t WebContentLayerImpl::GetApproximateUnsharedMemoryUsage() const {
89 return client_->approximateUnsharedMemoryUsage();
92 } // namespace cc_blink