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. 4 5#include "content/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 16using cc::ContentLayer; 17using cc::PictureLayer; 18 19namespace content { 20 21WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client) 22 : client_(client), ignore_lcd_text_change_(false) { 23 if (WebLayerImpl::UsingPictureLayer()) 24 layer_ = make_scoped_ptr(new WebLayerImpl(PictureLayer::Create(this))); 25 else 26 layer_ = make_scoped_ptr(new WebLayerImpl(ContentLayer::Create(this))); 27 layer_->layer()->SetIsDrawable(true); 28 can_use_lcd_text_ = layer_->layer()->can_use_lcd_text(); 29} 30 31WebContentLayerImpl::~WebContentLayerImpl() { 32 if (WebLayerImpl::UsingPictureLayer()) 33 static_cast<PictureLayer*>(layer_->layer())->ClearClient(); 34 else 35 static_cast<ContentLayer*>(layer_->layer())->ClearClient(); 36} 37 38blink::WebLayer* WebContentLayerImpl::layer() { 39 return layer_.get(); 40} 41 42void WebContentLayerImpl::setDoubleSided(bool double_sided) { 43 layer_->layer()->SetDoubleSided(double_sided); 44} 45 46void WebContentLayerImpl::setDrawCheckerboardForMissingTiles(bool enable) { 47 layer_->layer()->SetDrawCheckerboardForMissingTiles(enable); 48} 49 50void WebContentLayerImpl::PaintContents( 51 SkCanvas* canvas, 52 const gfx::Rect& clip, 53 gfx::RectF* opaque, 54 ContentLayerClient::GraphicsContextStatus graphics_context_status) { 55 if (!client_) 56 return; 57 58 blink::WebFloatRect web_opaque; 59 client_->paintContents( 60 canvas, 61 clip, 62 can_use_lcd_text_, 63 web_opaque, 64 graphics_context_status == ContentLayerClient::GRAPHICS_CONTEXT_ENABLED 65 ? blink::WebContentLayerClient::GraphicsContextEnabled 66 : blink::WebContentLayerClient::GraphicsContextDisabled); 67 *opaque = web_opaque; 68} 69 70void 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 85bool WebContentLayerImpl::FillsBoundsCompletely() const { 86 return false; 87} 88 89} // namespace content 90 91