Skip to content

Commit

Permalink
[cc] Add nearest neighbor filtering for TextureLayer.
Browse files Browse the repository at this point in the history
Blink side is here (depends on this CL):
https://codereview.chromium.org/562583002/

This CL also depends on another blink side change here:
https://codereview.chromium.org/699103002/

BUG=134040

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

Cr-Commit-Position: refs/heads/master@{#306768}
  • Loading branch information
jackhou-chromium authored and Commit bot committed Dec 4, 2014
1 parent edbe919 commit 10c9af4
Show file tree
Hide file tree
Showing 34 changed files with 309 additions and 126 deletions.
6 changes: 6 additions & 0 deletions cc/blink/web_external_texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void WebExternalTextureLayerImpl::setRateLimitContext(bool rate_limit) {
static_cast<TextureLayer*>(layer_->layer())->SetRateLimitContext(rate_limit);
}

void WebExternalTextureLayerImpl::setNearestNeighbor(bool nearest_neighbor) {
static_cast<TextureLayer*>(layer_->layer())
->SetNearestNeighbor(nearest_neighbor);
}

bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
cc::TextureMailbox* mailbox,
scoped_ptr<cc::SingleReleaseCallback>* release_callback,
Expand All @@ -85,6 +90,7 @@ bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint);
}
mailbox->set_allow_overlay(client_mailbox.allowOverlay);
mailbox->set_nearest_neighbor(client_mailbox.nearestNeighbor);

if (mailbox->IsValid()) {
*release_callback = cc::SingleReleaseCallback::Create(
Expand Down
1 change: 1 addition & 0 deletions cc/blink/web_external_texture_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class WebExternalTextureLayerImpl
virtual void setPremultipliedAlpha(bool premultiplied);
virtual void setBlendBackgroundColor(bool blend);
virtual void setRateLimitContext(bool rate_limit);
virtual void setNearestNeighbor(bool nearest_neighbor);

// TextureLayerClient implementation.
bool PrepareTextureMailbox(
Expand Down
1 change: 1 addition & 0 deletions cc/layers/delegated_frame_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DelegatedFrameProviderTest
gfx::PointF(1.f, 1.f),
SK_ColorTRANSPARENT,
vertex_opacity,
false,
false);
}

Expand Down
4 changes: 3 additions & 1 deletion cc/layers/heads_up_display_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
gfx::PointF uv_bottom_right(1.f, 1.f);
const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f };
bool flipped = false;
bool nearest_neighbor = false;
TextureDrawQuad* quad =
render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
quad->SetNew(shared_quad_state,
Expand All @@ -161,7 +162,8 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
uv_bottom_right,
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

void HeadsUpDisplayLayerImpl::UpdateHudTexture(
Expand Down
28 changes: 19 additions & 9 deletions cc/layers/nine_patch_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void NinePatchLayerImpl::AppendQuads(
return;

static const bool flipped = false;
static const bool nearest_neighbor = false;
static const bool premultiplied_alpha = true;

DCHECK(!bounds().IsEmpty());
Expand Down Expand Up @@ -228,7 +229,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_top_left.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect =
Expand All @@ -247,7 +249,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_top_right.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect =
Expand All @@ -266,7 +269,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_bottom_left.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect =
Expand All @@ -285,7 +289,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_bottom_right.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect = occlusion_in_content_space.GetUnoccludedContentRect(layer_top);
Expand All @@ -303,7 +308,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_top.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect =
Expand All @@ -322,7 +328,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_left.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect =
Expand All @@ -341,7 +348,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_right.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

visible_rect =
Expand All @@ -360,7 +368,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_bottom.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}

if (fill_center_) {
Expand All @@ -380,7 +389,8 @@ void NinePatchLayerImpl::AppendQuads(
uv_center.bottom_right(),
SK_ColorTRANSPARENT,
vertex_opacity,
flipped);
flipped,
nearest_neighbor);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions cc/layers/painted_scrollbar_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void PaintedScrollbarLayerImpl::AppendQuads(
AppendQuadsData* append_quads_data) {
bool premultipled_alpha = true;
bool flipped = false;
bool nearest_neighbor = false;
gfx::PointF uv_top_left(0.f, 0.f);
gfx::PointF uv_bottom_right(1.f, 1.f);
gfx::Rect bounds_rect(bounds());
Expand Down Expand Up @@ -109,7 +110,8 @@ void PaintedScrollbarLayerImpl::AppendQuads(
uv_bottom_right,
SK_ColorTRANSPARENT,
opacity,
flipped);
flipped,
nearest_neighbor);
}

gfx::Rect track_quad_rect = content_bounds_rect;
Expand All @@ -130,7 +132,8 @@ void PaintedScrollbarLayerImpl::AppendQuads(
uv_bottom_right,
SK_ColorTRANSPARENT,
opacity,
flipped);
flipped,
nearest_neighbor);
}
}

Expand Down
9 changes: 9 additions & 0 deletions cc/layers/texture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TextureLayer::TextureLayer(TextureLayerClient* client)
: Layer(),
client_(client),
flipped_(true),
nearest_neighbor_(false),
uv_top_left_(0.f, 0.f),
uv_bottom_right_(1.f, 1.f),
premultiplied_alpha_(true),
Expand Down Expand Up @@ -65,6 +66,13 @@ void TextureLayer::SetFlipped(bool flipped) {
SetNeedsCommit();
}

void TextureLayer::SetNearestNeighbor(bool nearest_neighbor) {
if (nearest_neighbor_ == nearest_neighbor)
return;
nearest_neighbor_ = nearest_neighbor;
SetNeedsCommit();
}

void TextureLayer::SetUV(const gfx::PointF& top_left,
const gfx::PointF& bottom_right) {
if (uv_top_left_ == top_left && uv_bottom_right_ == bottom_right)
Expand Down Expand Up @@ -238,6 +246,7 @@ void TextureLayer::PushPropertiesTo(LayerImpl* layer) {

TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer);
texture_layer->SetFlipped(flipped_);
texture_layer->SetNearestNeighbor(nearest_neighbor_);
texture_layer->SetUVTopLeft(uv_top_left_);
texture_layer->SetUVBottomRight(uv_bottom_right_);
texture_layer->SetVertexOpacity(vertex_opacity_);
Expand Down
5 changes: 5 additions & 0 deletions cc/layers/texture_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class CC_EXPORT TextureLayer : public Layer {
// true.
void SetFlipped(bool flipped);

// Sets whether this texture should use nearest neighbor interpolation as
// opposed to bilinear. Defaults to false.
void SetNearestNeighbor(bool nearest_neighbor);

// Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1).
void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right);

Expand Down Expand Up @@ -156,6 +160,7 @@ class CC_EXPORT TextureLayer : public Layer {
TextureLayerClient* client_;

bool flipped_;
bool nearest_neighbor_;
gfx::PointF uv_top_left_;
gfx::PointF uv_bottom_right_;
// [bottom left, top left, top right, bottom right]
Expand Down
10 changes: 9 additions & 1 deletion cc/layers/texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* tree_impl, int id)
premultiplied_alpha_(true),
blend_background_color_(false),
flipped_(true),
nearest_neighbor_(false),
uv_top_left_(0.f, 0.f),
uv_bottom_right_(1.f, 1.f),
own_mailbox_(false),
Expand Down Expand Up @@ -62,6 +63,7 @@ void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) {
texture_layer->SetVertexOpacity(vertex_opacity_);
texture_layer->SetPremultipliedAlpha(premultiplied_alpha_);
texture_layer->SetBlendBackgroundColor(blend_background_color_);
texture_layer->SetNearestNeighbor(nearest_neighbor_);
if (own_mailbox_) {
texture_layer->SetTextureMailbox(texture_mailbox_,
release_callback_.Pass());
Expand Down Expand Up @@ -176,7 +178,8 @@ void TextureLayerImpl::AppendQuads(RenderPass* render_pass,
uv_bottom_right_,
bg_color,
vertex_opacity_,
flipped_);
flipped_,
nearest_neighbor_);
}

SimpleEnclosedRegion TextureLayerImpl::VisibleContentOpaqueRegion() const {
Expand Down Expand Up @@ -211,6 +214,11 @@ void TextureLayerImpl::SetFlipped(bool flipped) {
SetNeedsPushProperties();
}

void TextureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) {
nearest_neighbor_ = nearest_neighbor;
SetNeedsPushProperties();
}

void TextureLayerImpl::SetUVTopLeft(const gfx::PointF top_left) {
uv_top_left_ = top_left;
SetNeedsPushProperties();
Expand Down
2 changes: 2 additions & 0 deletions cc/layers/texture_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
void SetPremultipliedAlpha(bool premultiplied_alpha);
void SetBlendBackgroundColor(bool blend);
void SetFlipped(bool flipped);
void SetNearestNeighbor(bool nearest_neighbor);
void SetUVTopLeft(const gfx::PointF top_left);
void SetUVBottomRight(const gfx::PointF bottom_right);

Expand All @@ -63,6 +64,7 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
bool premultiplied_alpha_;
bool blend_background_color_;
bool flipped_;
bool nearest_neighbor_;
gfx::PointF uv_top_left_;
gfx::PointF uv_bottom_right_;
float vertex_opacity_[4];
Expand Down
1 change: 1 addition & 0 deletions cc/layers/texture_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
// Test properties that should call SetNeedsCommit. All properties need to
// be set to new values in order for SetNeedsCommit to be called.
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetNearestNeighbor(true));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
Expand Down
4 changes: 3 additions & 1 deletion cc/layers/ui_resource_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void UIResourceLayerImpl::AppendQuads(
return;

static const bool flipped = false;
static const bool nearest_neighbor = false;
static const bool premultiplied_alpha = true;

DCHECK(!bounds().IsEmpty());
Expand All @@ -138,7 +139,8 @@ void UIResourceLayerImpl::AppendQuads(
uv_bottom_right_,
SK_ColorTRANSPARENT,
vertex_opacity_,
flipped);
flipped,
nearest_neighbor);
}

const char* UIResourceLayerImpl::LayerTypeAsString() const {
Expand Down
8 changes: 6 additions & 2 deletions cc/layers/video_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale);
float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
bool flipped = false;
bool nearest_neighbor = false;
TextureDrawQuad* texture_quad =
render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
texture_quad->SetNew(shared_quad_state,
Expand All @@ -212,7 +213,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
uv_bottom_right,
SK_ColorTRANSPARENT,
opacity,
flipped);
flipped,
nearest_neighbor);
break;
}
case VideoFrameExternalResources::YUV_RESOURCE: {
Expand Down Expand Up @@ -249,6 +251,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
gfx::PointF uv_bottom_right(tex_width_scale, tex_height_scale);
float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
bool flipped = false;
bool nearest_neighbor = false;
TextureDrawQuad* texture_quad =
render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
texture_quad->SetNew(shared_quad_state,
Expand All @@ -261,7 +264,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
uv_bottom_right,
SK_ColorTRANSPARENT,
opacity,
flipped);
flipped,
nearest_neighbor);
break;
}
case VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE: {
Expand Down
8 changes: 6 additions & 2 deletions cc/output/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2054,8 +2054,10 @@ void GLRenderer::FlushTextureQuadCache() {
GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0));

// Assume the current active textures is 0.
ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_,
draw_cache_.resource_id);
ResourceProvider::ScopedSamplerGL locked_quad(
resource_provider_,
draw_cache_.resource_id,
draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR);
DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_));
GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id()));

Expand Down Expand Up @@ -2133,12 +2135,14 @@ void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame,
if (draw_cache_.program_id != binding.program_id ||
draw_cache_.resource_id != resource_id ||
draw_cache_.needs_blending != quad->ShouldDrawWithBlending() ||
draw_cache_.nearest_neighbor != quad->nearest_neighbor ||
draw_cache_.background_color != quad->background_color ||
draw_cache_.matrix_data.size() >= 8) {
FlushTextureQuadCache();
draw_cache_.program_id = binding.program_id;
draw_cache_.resource_id = resource_id;
draw_cache_.needs_blending = quad->ShouldDrawWithBlending();
draw_cache_.nearest_neighbor = quad->nearest_neighbor;
draw_cache_.background_color = quad->background_color;

draw_cache_.uv_xform_location = binding.tex_transform_location;
Expand Down
1 change: 1 addition & 0 deletions cc/output/gl_renderer_draw_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TexturedQuadDrawCache::TexturedQuadDrawCache()
: program_id(-1),
resource_id(-1),
needs_blending(false),
nearest_neighbor(false),
background_color(0),
uv_xform_location(-1),
background_color_location(-1),
Expand Down
1 change: 1 addition & 0 deletions cc/output/gl_renderer_draw_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct TexturedQuadDrawCache {
int program_id;
int resource_id;
bool needs_blending;
bool nearest_neighbor;
SkColor background_color;

// Information about the program binding that is required to draw.
Expand Down
Loading

0 comments on commit 10c9af4

Please sign in to comment.