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.
5 #include "webkit/renderer/compositor_bindings/web_content_layer_impl.h"
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"
16 using cc::ContentLayer;
17 using cc::PictureLayer;
21 WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client)
23 ignore_lcd_text_change_(false) {
24 if (WebLayerImpl::UsingPictureLayer())
25 layer_ = make_scoped_ptr(new WebLayerImpl(PictureLayer::Create(this)));
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();
32 WebContentLayerImpl::~WebContentLayerImpl() {
33 if (WebLayerImpl::UsingPictureLayer())
34 static_cast<PictureLayer*>(layer_->layer())->ClearClient();
36 static_cast<ContentLayer*>(layer_->layer())->ClearClient();
39 blink::WebLayer* WebContentLayerImpl::layer() { return layer_.get(); }
41 void WebContentLayerImpl::setDoubleSided(bool double_sided) {
42 layer_->layer()->SetDoubleSided(double_sided);
45 void WebContentLayerImpl::setDrawCheckerboardForMissingTiles(bool enable) {
46 layer_->layer()->SetDrawCheckerboardForMissingTiles(enable);
49 void WebContentLayerImpl::setHasGpuRasterizationHint(bool has_hint) {
50 if (WebLayerImpl::UsingPictureLayer()) {
51 static_cast<PictureLayer*>(layer_->layer())
52 ->SetHasGpuRasterizationHint(has_hint);
56 void WebContentLayerImpl::PaintContents(SkCanvas* canvas,
57 const gfx::Rect& clip,
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);
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())
76 // LCD text cannot be enabled once disabled.
77 if (layer_->layer()->can_use_lcd_text() && ignore_lcd_text_change_)
80 can_use_lcd_text_ = layer_->layer()->can_use_lcd_text();
81 ignore_lcd_text_change_ = true;
85 bool WebContentLayerImpl::FillsBoundsCompletely() const { return false; }