Commit 189c11e3 authored by reveman@chromium.org's avatar reveman@chromium.org

cc: Remove racy initialization code in cc/base/switches.cc.

This moves all lazy initialization code out of cc/base/switches.cc. Code
that needs the value of these switches in a critical path should not rely
on lazy initialization in cc/switches.cc but instead handle this on its own.

Thread-safe lazy initialization code of impl-side painting status has
been added to WebLayerImpl.

This also removes the cc::switches::IsGPURasterizationEnabled() function,
which for consistency should not exist unless the logic to determine the
value is more complicated than HasSwitch(kEnableGPURasterization). This
function was never used in performance sensitive code so lazy initialization
was never necessary.

BUG=330937
TBR=jamesr

Review URL: https://codereview.chromium.org/122063002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243432 0039d316-1c4b-4281-b951-d872f2087c98
parent a4b944c1
......@@ -165,8 +165,7 @@ bool IsLCDTextEnabled() {
#endif
}
namespace {
bool CheckImplSidePaintingStatus() {
bool IsImplSidePaintingEnabled() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableImplSidePainting))
......@@ -181,23 +180,6 @@ bool CheckImplSidePaintingStatus() {
#endif
}
bool CheckGPURasterizationStatus() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
return command_line.HasSwitch(switches::kEnableGPURasterization);
}
} // namespace
bool IsImplSidePaintingEnabled() {
static bool enabled = CheckImplSidePaintingStatus();
return enabled;
}
bool IsGPURasterizationEnabled() {
static bool enabled = CheckGPURasterizationStatus();
return enabled;
}
bool IsMapImageEnabled() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
......
......@@ -74,7 +74,6 @@ CC_EXPORT extern const char kCCRebaselinePixeltests[];
CC_EXPORT bool IsLCDTextEnabled();
CC_EXPORT bool IsImplSidePaintingEnabled();
CC_EXPORT bool IsGPURasterizationEnabled();
CC_EXPORT bool IsMapImageEnabled();
} // namespace switches
......
......@@ -130,7 +130,8 @@ scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
max_untiled_layer_height);
settings.impl_side_painting = cc::switches::IsImplSidePaintingEnabled();
settings.gpu_rasterization = cc::switches::IsGPURasterizationEnabled();
settings.gpu_rasterization =
cmd->HasSwitch(cc::switches::kEnableGPURasterization);
settings.calculate_top_controls_position =
cmd->HasSwitch(cc::switches::kEnableTopControlsPositionCalculation);
......
......@@ -29,6 +29,7 @@
'type': '<(component)',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'<(DEPTH)/cc/cc.gyp:cc',
'<(DEPTH)/gpu/gpu.gyp:gpu',
'<(DEPTH)/media/media.gyp:media',
......
......@@ -4,8 +4,6 @@
#include "webkit/renderer/compositor_bindings/web_content_layer_impl.h"
#include "base/command_line.h"
#include "cc/base/switches.h"
#include "cc/layers/content_layer.h"
#include "cc/layers/picture_layer.h"
#include "third_party/WebKit/public/platform/WebContentLayerClient.h"
......@@ -20,14 +18,10 @@ using cc::PictureLayer;
namespace webkit {
static bool usingPictureLayer() {
return cc::switches::IsImplSidePaintingEnabled();
}
WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client)
: client_(client),
ignore_lcd_text_change_(false) {
if (usingPictureLayer())
if (WebLayerImpl::UsingPictureLayer())
layer_ = make_scoped_ptr(new WebLayerImpl(PictureLayer::Create(this)));
else
layer_ = make_scoped_ptr(new WebLayerImpl(ContentLayer::Create(this)));
......@@ -36,7 +30,7 @@ WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client)
}
WebContentLayerImpl::~WebContentLayerImpl() {
if (usingPictureLayer())
if (WebLayerImpl::UsingPictureLayer())
static_cast<PictureLayer*>(layer_->layer())->ClearClient();
else
static_cast<ContentLayer*>(layer_->layer())->ClearClient();
......@@ -61,7 +55,7 @@ void WebContentLayerImpl::PaintContents(SkCanvas* canvas,
blink::WebFloatRect web_opaque;
// For picture layers, always record with LCD text. PictureLayerImpl
// will turn this off later during rasterization.
bool use_lcd_text = usingPictureLayer() || can_use_lcd_text_;
bool use_lcd_text = WebLayerImpl::UsingPictureLayer() || can_use_lcd_text_;
client_->paintContents(canvas, clip, use_lcd_text, web_opaque);
*opaque = web_opaque;
}
......
......@@ -4,21 +4,15 @@
#include "webkit/renderer/compositor_bindings/web_image_layer_impl.h"
#include "base/command_line.h"
#include "cc/base/switches.h"
#include "cc/layers/image_layer.h"
#include "cc/layers/picture_image_layer.h"
#include "webkit/renderer/compositor_bindings/web_layer_impl.h"
#include "webkit/renderer/compositor_bindings/web_layer_impl_fixed_bounds.h"
static bool usingPictureLayer() {
return cc::switches::IsImplSidePaintingEnabled();
}
namespace webkit {
WebImageLayerImpl::WebImageLayerImpl() {
if (usingPictureLayer())
if (WebLayerImpl::UsingPictureLayer())
layer_.reset(new WebLayerImplFixedBounds(cc::PictureImageLayer::Create()));
else
layer_.reset(new WebLayerImpl(cc::ImageLayer::Create()));
......@@ -29,7 +23,7 @@ WebImageLayerImpl::~WebImageLayerImpl() {}
blink::WebLayer* WebImageLayerImpl::layer() { return layer_.get(); }
void WebImageLayerImpl::setBitmap(SkBitmap bitmap) {
if (usingPictureLayer()) {
if (WebLayerImpl::UsingPictureLayer()) {
static_cast<cc::PictureImageLayer*>(layer_->layer())->SetBitmap(bitmap);
static_cast<WebLayerImplFixedBounds*>(layer_.get())->SetFixedBounds(
gfx::Size(bitmap.width(), bitmap.height()));
......
......@@ -6,10 +6,12 @@
#include "base/bind.h"
#include "base/debug/trace_event_impl.h"
#include "base/lazy_instance.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_checker.h"
#include "cc/animation/animation.h"
#include "cc/base/region.h"
#include "cc/base/switches.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_position_constraint.h"
#include "third_party/WebKit/public/platform/WebCompositingReasons.h"
......@@ -37,6 +39,18 @@ using blink::WebColor;
using blink::WebFilterOperations;
namespace webkit {
namespace {
struct ImplSidePaintingStatus {
ImplSidePaintingStatus()
: enabled(cc::switches::IsImplSidePaintingEnabled()) {
}
bool enabled;
};
base::LazyInstance<ImplSidePaintingStatus> g_impl_side_painting_status =
LAZY_INSTANCE_INITIALIZER;
} // namespace
WebLayerImpl::WebLayerImpl() : layer_(Layer::Create()) {
web_layer_client_ = NULL;
......@@ -54,6 +68,11 @@ WebLayerImpl::~WebLayerImpl() {
web_layer_client_ = NULL;
}
// static
bool WebLayerImpl::UsingPictureLayer() {
return g_impl_side_painting_status.Get().enabled;
}
int WebLayerImpl::id() const { return layer_->id(); }
void WebLayerImpl::invalidateRect(const blink::WebFloatRect& rect) {
......
......@@ -52,6 +52,8 @@ class WebLayerImpl : public blink::WebLayer, public cc::LayerClient {
scoped_refptr<cc::Layer>);
virtual ~WebLayerImpl();
static bool UsingPictureLayer();
WEBKIT_COMPOSITOR_BINDINGS_EXPORT cc::Layer* layer() const;
// WebLayer implementation.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment