Skip to content

Commit

Permalink
cc: Toggle LCD text at raster time instead of record time.
Browse files Browse the repository at this point in the history
Always tell blink that it can use LCD text (in future this can stop
being passed at all). And at raster time:

- If LCD text is allowed initialize SkSurfaceProps with the LegacyHost
parameter which will cause skia to pick an LCD text format matching
current behaviour.
- If LCD is not allowed initialize SkSurfaceProps with an "unknown
pixelformat" causing LCD text to not be used.

This also removes the need for SK_SUPPORT_LEGACY_TEXTRENDERMODE from
resource_provider.cc.

R=enne,reveman
BUG=430617

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

Cr-Commit-Position: refs/heads/master@{#304486}
  • Loading branch information
danakj authored and Commit bot committed Nov 17, 2014
1 parent 9f3e33d commit ad672f6
Show file tree
Hide file tree
Showing 38 changed files with 282 additions and 252 deletions.
25 changes: 5 additions & 20 deletions cc/blink/web_content_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ using cc::PictureLayer;
namespace cc_blink {

WebContentLayerImpl::WebContentLayerImpl(blink::WebContentLayerClient* client)
: client_(client), ignore_lcd_text_change_(false) {
: client_(client) {
if (WebLayerImpl::UsingPictureLayer())
layer_ = make_scoped_ptr(new WebLayerImpl(PictureLayer::Create(this)));
else
layer_ = make_scoped_ptr(new WebLayerImpl(ContentLayer::Create(this)));
layer_->layer()->SetIsDrawable(true);
can_use_lcd_text_ = layer_->layer()->can_use_lcd_text();
}

WebContentLayerImpl::~WebContentLayerImpl() {
Expand Down Expand Up @@ -54,30 +53,16 @@ void WebContentLayerImpl::PaintContents(
if (!client_)
return;

// TODO(danakj): Stop passing this to blink it should always use LCD when it
// wants to. crbug.com/430617
bool can_use_lcd_text = true;
client_->paintContents(
canvas,
clip,
can_use_lcd_text_,
canvas, clip, can_use_lcd_text,
graphics_context_status == ContentLayerClient::GRAPHICS_CONTEXT_ENABLED
? blink::WebContentLayerClient::GraphicsContextEnabled
: blink::WebContentLayerClient::GraphicsContextDisabled);
}

void WebContentLayerImpl::DidChangeLayerCanUseLCDText() {
// It is important to make this comparison because the LCD text status
// here can get out of sync with that in the layer.
if (can_use_lcd_text_ == layer_->layer()->can_use_lcd_text())
return;

// LCD text cannot be enabled once disabled.
if (layer_->layer()->can_use_lcd_text() && ignore_lcd_text_change_)
return;

can_use_lcd_text_ = layer_->layer()->can_use_lcd_text();
ignore_lcd_text_change_ = true;
layer_->invalidate();
}

bool WebContentLayerImpl::FillsBoundsCompletely() const {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion cc/blink/web_content_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class WebContentLayerImpl : public blink::WebContentLayer,
const gfx::Rect& clip,
ContentLayerClient::GraphicsContextStatus
graphics_context_status) override;
void DidChangeLayerCanUseLCDText() override;
bool FillsBoundsCompletely() const override;

scoped_ptr<WebLayerImpl> layer_;
Expand Down
14 changes: 1 addition & 13 deletions cc/layers/content_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) {
}

ContentLayer::ContentLayer(ContentLayerClient* client)
: TiledLayer(),
client_(client),
can_use_lcd_text_last_frame_(can_use_lcd_text()) {
: TiledLayer(), client_(client) {
}

ContentLayer::~ContentLayer() {}
Expand Down Expand Up @@ -74,7 +72,6 @@ bool ContentLayer::Update(ResourceUpdateQueue* queue,
true);

CreateUpdaterIfNeeded();
UpdateCanUseLCDText();
}

bool updated = TiledLayer::Update(queue, occlusion);
Expand Down Expand Up @@ -118,15 +115,6 @@ void ContentLayer::SetContentsOpaque(bool opaque) {
updater_->SetOpaque(opaque);
}

void ContentLayer::UpdateCanUseLCDText() {
if (can_use_lcd_text_last_frame_ == can_use_lcd_text())
return;

can_use_lcd_text_last_frame_ = can_use_lcd_text();
if (client_)
client_->DidChangeLayerCanUseLCDText();
}

bool ContentLayer::SupportsLCDText() const {
return true;
}
Expand Down
3 changes: 0 additions & 3 deletions cc/layers/content_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ class CC_EXPORT ContentLayer : public TiledLayer {
// TiledLayer implementation.
void CreateUpdaterIfNeeded() override;

void UpdateCanUseLCDText();

ContentLayerClient* client_;
scoped_refptr<ContentLayerUpdater> updater_;
bool can_use_lcd_text_last_frame_;

DISALLOW_COPY_AND_ASSIGN(ContentLayer);
};
Expand Down
4 changes: 0 additions & 4 deletions cc/layers/content_layer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class CC_EXPORT ContentLayerClient {
const gfx::Rect& clip,
GraphicsContextStatus gc_status) = 0;

// Called by the content layer during the update phase.
// If the client paints LCD text, it may want to invalidate the layer.
virtual void DidChangeLayerCanUseLCDText() = 0;

// If true the layer may skip clearing the background before rasterizing,
// because it will cover any uncleared data with content.
virtual bool FillsBoundsCompletely() const = 0;
Expand Down
1 change: 0 additions & 1 deletion cc/layers/picture_image_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient {
SkCanvas* canvas,
const gfx::Rect& clip,
ContentLayerClient::GraphicsContextStatus gc_status) override;
void DidChangeLayerCanUseLCDText() override {}
bool FillsBoundsCompletely() const override;

protected:
Expand Down
29 changes: 13 additions & 16 deletions cc/layers/picture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PictureLayer::PictureLayer(ContentLayerClient* client)
recording_source_(new PicturePile),
instrumentation_object_tracker_(id()),
update_source_frame_number_(-1),
can_use_lcd_text_last_frame_(can_use_lcd_text()) {
can_use_lcd_text_for_update_(true) {
}

PictureLayer::PictureLayer(ContentLayerClient* client,
Expand Down Expand Up @@ -95,18 +95,14 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
update_source_frame_number_ = layer_tree_host()->source_frame_number();
bool updated = Layer::Update(queue, occlusion);

{
base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_,
true);
UpdateCanUseLCDText();
}
bool can_use_lcd_text_changed = UpdateCanUseLCDText();

gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect(
visible_content_rect(), 1.f / contents_scale_x());
gfx::Size layer_size = paint_properties().bounds;

if (last_updated_visible_content_rect_ == visible_content_rect() &&
recording_source_->GetSize() == layer_size &&
recording_source_->GetSize() == layer_size && !can_use_lcd_text_changed &&
pending_invalidation_.IsEmpty()) {
// Only early out if the visible content rect of this layer hasn't changed.
return updated;
Expand Down Expand Up @@ -136,9 +132,9 @@ bool PictureLayer::Update(ResourceUpdateQueue* queue,
DCHECK(client_);
updated |= recording_source_->UpdateAndExpandInvalidation(
client_, &recording_invalidation_, SafeOpaqueBackgroundColor(),
contents_opaque(), client_->FillsBoundsCompletely(), layer_size,
visible_layer_rect, update_source_frame_number_,
Picture::RECORD_NORMALLY);
contents_opaque(), client_->FillsBoundsCompletely(),
can_use_lcd_text_for_update_, layer_size, visible_layer_rect,
update_source_frame_number_, Picture::RECORD_NORMALLY);
last_updated_visible_content_rect_ = visible_content_rect();

if (updated) {
Expand All @@ -160,13 +156,14 @@ bool PictureLayer::SupportsLCDText() const {
return true;
}

void PictureLayer::UpdateCanUseLCDText() {
if (can_use_lcd_text_last_frame_ == can_use_lcd_text())
return;
bool PictureLayer::UpdateCanUseLCDText() {
if (!can_use_lcd_text_for_update_)
return false; // Don't allow the LCD text state to change once disabled.
if (can_use_lcd_text_for_update_ == can_use_lcd_text())
return false;

can_use_lcd_text_last_frame_ = can_use_lcd_text();
if (client_)
client_->DidChangeLayerCanUseLCDText();
can_use_lcd_text_for_update_ = can_use_lcd_text();
return true;
}

skia::RefPtr<SkPicture> PictureLayer::GetPicture() const {
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/picture_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CC_EXPORT PictureLayer : public Layer {
~PictureLayer() override;

bool HasDrawableContent() const override;
void UpdateCanUseLCDText();
bool UpdateCanUseLCDText();

private:
ContentLayerClient* client_;
Expand All @@ -64,7 +64,7 @@ class CC_EXPORT PictureLayer : public Layer {
gfx::Rect last_updated_visible_content_rect_;

int update_source_frame_number_;
bool can_use_lcd_text_last_frame_;
bool can_use_lcd_text_for_update_;

DISALLOW_COPY_AND_ASSIGN(PictureLayer);
};
Expand Down
6 changes: 3 additions & 3 deletions cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4502,7 +4502,7 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {

Region invalidation(layer_rect);
recording_source->UpdateAndExpandInvalidation(
&client, &invalidation, SK_ColorWHITE, false, false, layer_bounds,
&client, &invalidation, SK_ColorWHITE, false, false, false, layer_bounds,
layer_rect, frame_number++, Picture::RECORD_NORMALLY);

scoped_refptr<RasterSource> pending_raster_source =
Expand Down Expand Up @@ -4569,7 +4569,7 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {

Region invalidation1(layer_rect);
recording_source->UpdateAndExpandInvalidation(
&client, &invalidation1, SK_ColorWHITE, false, false, layer_bounds,
&client, &invalidation1, SK_ColorWHITE, false, false, false, layer_bounds,
layer_rect, frame_number++, Picture::RECORD_NORMALLY);

scoped_refptr<RasterSource> raster_source1 =
Expand All @@ -4587,7 +4587,7 @@ TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {

Region invalidation2(layer_rect);
recording_source->UpdateAndExpandInvalidation(
&client, &invalidation2, SK_ColorWHITE, false, false, layer_bounds,
&client, &invalidation2, SK_ColorWHITE, false, false, false, layer_bounds,
layer_rect, frame_number++, Picture::RECORD_NORMALLY);

scoped_refptr<RasterSource> raster_source2 =
Expand Down
1 change: 0 additions & 1 deletion cc/layers/picture_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class MockContentLayerClient : public ContentLayerClient {
SkCanvas* canvas,
const gfx::Rect& clip,
ContentLayerClient::GraphicsContextStatus gc_status) override {}
void DidChangeLayerCanUseLCDText() override {}
bool FillsBoundsCompletely() const override { return false; };
};

Expand Down
3 changes: 2 additions & 1 deletion cc/resources/gpu_raster_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class RasterBufferImpl : public RasterBuffer {
bool use_distance_field_text =
use_distance_field_text_ ||
raster_source->ShouldAttemptToUseDistanceFieldText();
SkSurface* sk_surface = lock_.GetSkSurface(use_distance_field_text);
SkSurface* sk_surface = lock_.GetSkSurface(use_distance_field_text,
raster_source->CanUseLCDText());

if (!sk_surface)
return;
Expand Down
35 changes: 23 additions & 12 deletions cc/resources/picture_pile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,33 @@ bool PicturePile::UpdateAndExpandInvalidation(
SkColor background_color,
bool contents_opaque,
bool contents_fill_bounds_completely,
bool can_use_lcd_text,
const gfx::Size& layer_size,
const gfx::Rect& visible_layer_rect,
int frame_number,
Picture::RecordingMode recording_mode) {
background_color_ = background_color;
contents_opaque_ = contents_opaque;
contents_fill_bounds_completely_ = contents_fill_bounds_completely;
bool can_use_lcd_text_changed = can_use_lcd_text_ != can_use_lcd_text;
can_use_lcd_text_ = can_use_lcd_text;

bool updated = false;

Region resize_invalidation;
Region synthetic_invalidation;
gfx::Size old_tiling_size = GetSize();
if (old_tiling_size != layer_size) {
tiling_.SetTilingSize(layer_size);
updated = true;
}
if (can_use_lcd_text_changed) {
// When LCD text is enabled/disabled, we must drop any raster tiles for
// the pile, so they can be recreated in a manner consistent with the new
// setting. We do this with |synthetic_invalidation| since we don't need to
// do a new recording, just invalidate rastered content.
synthetic_invalidation.Union(gfx::Rect(GetSize()));
updated = true;
}

gfx::Rect interest_rect = visible_layer_rect;
interest_rect.Inset(-pixel_record_distance_, -pixel_record_distance_);
Expand Down Expand Up @@ -372,11 +383,11 @@ bool PicturePile::UpdateAndExpandInvalidation(
exposed_top,
exposed_left_until - exposed_left,
exposed_bottom - exposed_top);
resize_invalidation.Union(left_rect);
resize_invalidation.Union(right_rect);
resize_invalidation.Union(top_rect);
resize_invalidation.Union(bottom_rect);
resize_invalidation.Union(exposed_rect);
synthetic_invalidation.Union(left_rect);
synthetic_invalidation.Union(right_rect);
synthetic_invalidation.Union(top_rect);
synthetic_invalidation.Union(bottom_rect);
synthetic_invalidation.Union(exposed_rect);
}
if (min_toss_y < tiling_.num_tiles_y()) {
// The same thing occurs here as in the case above, but the invalidation
Expand Down Expand Up @@ -408,11 +419,11 @@ bool PicturePile::UpdateAndExpandInvalidation(
exposed_top,
exposed_right - exposed_left,
exposed_top_until - exposed_top);
resize_invalidation.Union(left_rect);
resize_invalidation.Union(right_rect);
resize_invalidation.Union(top_rect);
resize_invalidation.Union(bottom_rect);
resize_invalidation.Union(exposed_rect);
synthetic_invalidation.Union(left_rect);
synthetic_invalidation.Union(right_rect);
synthetic_invalidation.Union(top_rect);
synthetic_invalidation.Union(bottom_rect);
synthetic_invalidation.Union(exposed_rect);
}
}

Expand Down Expand Up @@ -474,7 +485,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
invalidation->Union(invalidation_expanded_to_full_tiles);
}

invalidation->Union(resize_invalidation);
invalidation->Union(synthetic_invalidation);

// Make a list of all invalid tiles; we will attempt to
// cluster these into multiple invalidation regions.
Expand Down
2 changes: 2 additions & 0 deletions cc/resources/picture_pile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CC_EXPORT PicturePile : public RecordingSource {
SkColor background_color,
bool contents_opaque,
bool contents_fill_bounds_completely,
bool can_use_lcd_text,
const gfx::Size& layer_size,
const gfx::Rect& visible_layer_rect,
int frame_number,
Expand Down Expand Up @@ -101,6 +102,7 @@ class CC_EXPORT PicturePile : public RecordingSource {
int slow_down_raster_scale_factor_for_debug_;
bool contents_opaque_;
bool contents_fill_bounds_completely_;
bool can_use_lcd_text_;
bool clear_canvas_with_debug_color_;
// A hint about whether there are any recordings. This may be a false
// positive.
Expand Down
6 changes: 6 additions & 0 deletions cc/resources/picture_pile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PicturePileImpl::PicturePileImpl()
: background_color_(SK_ColorTRANSPARENT),
contents_opaque_(false),
contents_fill_bounds_completely_(false),
can_use_lcd_text_(false),
is_solid_color_(false),
solid_color_(SK_ColorTRANSPARENT),
has_any_recordings_(false),
Expand All @@ -45,6 +46,7 @@ PicturePileImpl::PicturePileImpl(const PicturePile* other)
background_color_(other->background_color_),
contents_opaque_(other->contents_opaque_),
contents_fill_bounds_completely_(other->contents_fill_bounds_completely_),
can_use_lcd_text_(other->can_use_lcd_text_),
is_solid_color_(other->is_solid_color_),
solid_color_(other->solid_color_),
recorded_viewport_(other->recorded_viewport_),
Expand Down Expand Up @@ -427,6 +429,10 @@ bool PicturePileImpl::IsMask() const {
return is_mask_;
}

bool PicturePileImpl::CanUseLCDText() const {
return can_use_lcd_text_;
}

PicturePileImpl::PixelRefIterator::PixelRefIterator(
const gfx::Rect& content_rect,
float contents_scale,
Expand Down
2 changes: 2 additions & 0 deletions cc/resources/picture_pile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CC_EXPORT PicturePileImpl : public RasterSource {
SkColor GetSolidColor() const override;
bool HasRecordings() const override;
bool IsMask() const override;
bool CanUseLCDText() const override;

// Tracing functionality.
void DidBeginTracing() override;
Expand Down Expand Up @@ -110,6 +111,7 @@ class CC_EXPORT PicturePileImpl : public RasterSource {
SkColor background_color_;
bool contents_opaque_;
bool contents_fill_bounds_completely_;
bool can_use_lcd_text_;
bool is_solid_color_;
SkColor solid_color_;
gfx::Rect recorded_viewport_;
Expand Down
2 changes: 1 addition & 1 deletion cc/resources/picture_pile_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PicturePileTestBase {
frame_number_++;
return pile_.UpdateAndExpandInvalidation(
&client_, invalidation, background_color_, contents_opaque_, false,
layer_size, visible_layer_rect, frame_number_,
false, layer_size, visible_layer_rect, frame_number_,
Picture::RECORD_NORMALLY);
}

Expand Down
Loading

0 comments on commit ad672f6

Please sign in to comment.