Commit 06d68d07 authored by dtrainor@chromium.org's avatar dtrainor@chromium.org

Add optimization to TextureLayer

Since there's no way to query UV coords, we shouldn't be committing if we have to
push UV every frame.

BUG=

Review URL: https://chromiumcodereview.appspot.com/13910011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195248 0039d316-1c4b-4281-b951-d872f2087c98
parent 2f7b6fcf
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h" #include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_test_common.h"
#include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_host.h"
#include "cc/trees/single_thread_proxy.h" #include "cc/trees/single_thread_proxy.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -26,12 +27,6 @@ using ::testing::Mock; ...@@ -26,12 +27,6 @@ using ::testing::Mock;
using ::testing::StrictMock; using ::testing::StrictMock;
using ::testing::_; using ::testing::_;
#define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test) do { \
EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
code_to_test; \
Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
} while (false)
#define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) do { \ #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) do { \
EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \
code_to_test; \ code_to_test; \
......
...@@ -83,11 +83,15 @@ scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { ...@@ -83,11 +83,15 @@ scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
} }
void TextureLayer::SetFlipped(bool flipped) { void TextureLayer::SetFlipped(bool flipped) {
if (flipped_ == flipped)
return;
flipped_ = flipped; flipped_ = flipped;
SetNeedsCommit(); SetNeedsCommit();
} }
void TextureLayer::SetUV(gfx::PointF top_left, gfx::PointF bottom_right) { void TextureLayer::SetUV(gfx::PointF top_left, gfx::PointF bottom_right) {
if (uv_top_left_ == top_left && uv_bottom_right_ == bottom_right)
return;
uv_top_left_ = top_left; uv_top_left_ = top_left;
uv_bottom_right_ = bottom_right; uv_bottom_right_ = bottom_right;
SetNeedsCommit(); SetNeedsCommit();
...@@ -101,6 +105,11 @@ void TextureLayer::SetVertexOpacity(float bottom_left, ...@@ -101,6 +105,11 @@ void TextureLayer::SetVertexOpacity(float bottom_left,
// 1--2 // 1--2
// | | // | |
// 0--3 // 0--3
if (vertex_opacity_[0] == bottom_left &&
vertex_opacity_[1] == top_left &&
vertex_opacity_[2] == top_right &&
vertex_opacity_[3] == bottom_right)
return;
vertex_opacity_[0] = bottom_left; vertex_opacity_[0] = bottom_left;
vertex_opacity_[1] = top_left; vertex_opacity_[1] = top_left;
vertex_opacity_[2] = top_right; vertex_opacity_[2] = top_right;
...@@ -109,6 +118,8 @@ void TextureLayer::SetVertexOpacity(float bottom_left, ...@@ -109,6 +118,8 @@ void TextureLayer::SetVertexOpacity(float bottom_left,
} }
void TextureLayer::SetPremultipliedAlpha(bool premultiplied_alpha) { void TextureLayer::SetPremultipliedAlpha(bool premultiplied_alpha) {
if (premultiplied_alpha_ == premultiplied_alpha)
return;
premultiplied_alpha_ = premultiplied_alpha; premultiplied_alpha_ = premultiplied_alpha;
SetNeedsCommit(); SetNeedsCommit();
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/layer_tree_test.h" #include "cc/test/layer_tree_test.h"
#include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h" #include "cc/trees/layer_tree_impl.h"
...@@ -181,6 +182,24 @@ TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { ...@@ -181,6 +182,24 @@ TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) {
Mock::VerifyAndClearExpectations(layer_tree_host_.get()); Mock::VerifyAndClearExpectations(layer_tree_host_.get());
} }
TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
test_layer->SetLayerTreeHost(layer_tree_host_.get());
// 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->SetUV(
gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
0.5f, 0.5f, 0.5f, 0.5f));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1));
// Calling SetTextureId can call AcquireLayerTextures.
EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
}
class MockMailboxCallback { class MockMailboxCallback {
public: public:
MOCK_METHOD3(Release, void(const std::string& mailbox, MOCK_METHOD3(Release, void(const std::string& mailbox,
......
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
#ifndef CC_TEST_LAYER_TEST_COMMON_H_ #ifndef CC_TEST_LAYER_TEST_COMMON_H_
#define CC_TEST_LAYER_TEST_COMMON_H_ #define CC_TEST_LAYER_TEST_COMMON_H_
#define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test) do { \
EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
code_to_test; \
Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
} while (false)
namespace gfx { class Rect; } namespace gfx { class Rect; }
namespace cc { namespace cc {
......
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