95a4b7f9b13bb3ed178261c13c6b578e2f04cf17
[platform/framework/web/crosswalk.git] / src / webkit / renderer / compositor_bindings / web_content_layer_impl.cc
1 // Copyright 2011 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.
4
5 #include "webkit/renderer/compositor_bindings/web_content_layer_impl.h"
6
7 #include "cc/layers/content_layer.h"
8 #include "cc/layers/picture_layer.h"
9 #include "third_party/WebKit/public/platform/WebContentLayerClient.h"
10 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
11 #include "third_party/WebKit/public/platform/WebFloatRect.h"
12 #include "third_party/WebKit/public/platform/WebRect.h"
13 #include "third_party/WebKit/public/platform/WebSize.h"
14 #include "third_party/skia/include/utils/SkMatrix44.h"
15
16 using cc::ContentLayer;
17 using cc::PictureLayer;
18
19 namespace webkit {
20
21 WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client)
22     : client_(client),
23       ignore_lcd_text_change_(false) {
24   if (WebLayerImpl::UsingPictureLayer())
25     layer_ = make_scoped_ptr(new WebLayerImpl(PictureLayer::Create(this)));
26   else
27     layer_ = make_scoped_ptr(new WebLayerImpl(ContentLayer::Create(this)));
28   layer_->layer()->SetIsDrawable(true);
29   can_use_lcd_text_ = layer_->layer()->can_use_lcd_text();
30 }
31
32 WebContentLayerImpl::~WebContentLayerImpl() {
33   if (WebLayerImpl::UsingPictureLayer())
34     static_cast<PictureLayer*>(layer_->layer())->ClearClient();
35   else
36     static_cast<ContentLayer*>(layer_->layer())->ClearClient();
37 }
38
39 blink::WebLayer* WebContentLayerImpl::layer() { return layer_.get(); }
40
41 void WebContentLayerImpl::setDoubleSided(bool double_sided) {
42   layer_->layer()->SetDoubleSided(double_sided);
43 }
44
45 void WebContentLayerImpl::setDrawCheckerboardForMissingTiles(bool enable) {
46   layer_->layer()->SetDrawCheckerboardForMissingTiles(enable);
47 }
48
49 void WebContentLayerImpl::setHasGpuRasterizationHint(bool has_hint) {
50   if (WebLayerImpl::UsingPictureLayer()) {
51     static_cast<PictureLayer*>(layer_->layer())
52         ->SetHasGpuRasterizationHint(has_hint);
53   }
54 }
55
56 void WebContentLayerImpl::PaintContents(SkCanvas* canvas,
57                                         const gfx::Rect& clip,
58                                         gfx::RectF* opaque) {
59   if (!client_)
60     return;
61
62   blink::WebFloatRect web_opaque;
63   // For picture layers, always record with LCD text.  PictureLayerImpl
64   // will turn this off later during rasterization.
65   bool use_lcd_text = WebLayerImpl::UsingPictureLayer() || can_use_lcd_text_;
66   client_->paintContents(canvas, clip, use_lcd_text, web_opaque);
67   *opaque = web_opaque;
68 }
69
70 void WebContentLayerImpl::DidChangeLayerCanUseLCDText() {
71   // It is important to make this comparison because the LCD text status
72   // here can get out of sync with that in the layer.
73   if (can_use_lcd_text_ == layer_->layer()->can_use_lcd_text())
74     return;
75
76   // LCD text cannot be enabled once disabled.
77   if (layer_->layer()->can_use_lcd_text() && ignore_lcd_text_change_)
78     return;
79
80   can_use_lcd_text_ = layer_->layer()->can_use_lcd_text();
81   ignore_lcd_text_change_ = true;
82   layer_->invalidate();
83 }
84
85 bool WebContentLayerImpl::FillsBoundsCompletely() const { return false; }
86
87 }  // namespace webkit