summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-19 20:33:49 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-19 20:33:49 +0000
commite1262d1c7cba259c233577ffe6969de4c6b3bd3e (patch)
treedf2a5f5fd7c09fe8d2cc1da0e834aeaf408a1acf /webkit
parent1c31e45e6eb2bbdad3036bdca7a0067be4f660cb (diff)
downloadchromium_src-e1262d1c7cba259c233577ffe6969de4c6b3bd3e.zip
chromium_src-e1262d1c7cba259c233577ffe6969de4c6b3bd3e.tar.gz
chromium_src-e1262d1c7cba259c233577ffe6969de4c6b3bd3e.tar.bz2
Inline ppb_graphics_2d_impl to the host.
- Split original tests to content_browsertests and test_shell_tests - *_flush_callback_ are no longer needed This is a reland of r171234 (http://codereview.chromium.org/11434049) by victorhsieh@chromium.org. Changes from the original: - Merge to minor changes in pepper_graphics_2d_host.cc - Fix test shell tests on Mac. This patch creates a mock PlatformGraphics2D with enough information to make the test work. Conveniently, this also makes the test run on other platforms (previously it was ifdefed to Mac only) so I enabled it everywhere. Review URL: https://codereview.chromium.org/12282011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183280 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc2
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc9
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h6
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance_unittest.cc127
-rw-r--r--webkit/plugins/ppapi/ppapi_unittest.cc4
-rw-r--r--webkit/plugins/ppapi/ppapi_unittest.h2
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc136
-rw-r--r--webkit/tools/test_shell/test_shell.gypi2
9 files changed, 145 insertions, 145 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index d1ff407..9bd73fa 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -217,8 +217,6 @@
'../plugins/ppapi/ppb_flash_message_loop_impl.h',
'../plugins/ppapi/ppb_gpu_blacklist_private_impl.cc',
'../plugins/ppapi/ppb_gpu_blacklist_private_impl.h',
- '../plugins/ppapi/ppb_graphics_2d_impl.cc',
- '../plugins/ppapi/ppb_graphics_2d_impl.h',
'../plugins/ppapi/ppb_graphics_3d_impl.cc',
'../plugins/ppapi/ppb_graphics_3d_impl.h',
'../plugins/ppapi/ppb_image_data_impl.cc',
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index af3d88e..f325428 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -104,6 +104,7 @@
#include "ppapi/shared_impl/ppb_var_shared.h"
#include "ppapi/shared_impl/time_conversion.h"
#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_graphics_2d_api.h"
#include "ppapi/thunk/thunk.h"
#include "webkit/plugins/plugin_switches.h"
#include "webkit/plugins/ppapi/common.h"
@@ -111,7 +112,6 @@
#include "webkit/plugins/ppapi/ppapi_interface_factory.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_gpu_blacklist_private_impl.h"
-#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
#include "webkit/plugins/ppapi/ppb_proxy_impl.h"
#include "webkit/plugins/ppapi/ppb_scrollbar_impl.h"
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index ae043de..4a7b8d4 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -1404,6 +1404,15 @@ bool PluginInstance::CanRotateView() {
return true;
}
+void PluginInstance::SetBoundGraphics2DForTest(
+ PluginDelegate::PlatformGraphics2D* graphics) {
+ BindGraphics(pp_instance(), 0); // Unbind any old stuff.
+ if (graphics) {
+ bound_graphics_2d_platform_ = graphics;
+ bound_graphics_2d_platform_->BindToInstance(this);
+ }
+}
+
void PluginInstance::RotateView(WebPlugin::RotationType type) {
if (!LoadPdfInterface())
return;
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index 59079432..92ee472 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -247,7 +247,10 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
bool CanRotateView();
void RotateView(WebKit::WebPlugin::RotationType type);
- void Graphics3DContextLost();
+ // Sets the bound_graphics_2d_platform_ for testing purposes. This is instead
+ // of calling BindGraphics and allows any PlatformGraphics implementation to
+ // be used, not just a resource one.
+ void SetBoundGraphics2DForTest(PluginDelegate::PlatformGraphics2D* graphics);
// There are 2 implementations of the fullscreen interface
// PPB_FlashFullscreen is used by Pepper Flash.
@@ -775,6 +778,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
// calls and handles PPB_ContentDecryptor_Private calls.
scoped_ptr<ContentDecryptorDelegate> content_decryptor_delegate_;
+ friend class PpapiPluginInstanceTest;
DISALLOW_COPY_AND_ASSIGN(PluginInstance);
};
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance_unittest.cc b/webkit/plugins/ppapi/ppapi_plugin_instance_unittest.cc
new file mode 100644
index 0000000..7f774a7
--- /dev/null
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance_unittest.cc
@@ -0,0 +1,127 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/safe_integer_conversions.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/ppapi_unittest.h"
+#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+// A mock graphics object to bind. We only have to implement enough so that
+// GetBitmapForOptimizedPluginPaint runs.
+//
+// If this is eventually all moved to content, we can simplify this. The
+// point here is that we need to just have a bound graphics 2d resource host
+// with the right properties.
+class MockPlatformGraphics2D : public PluginDelegate::PlatformGraphics2D {
+ public:
+ // The image data pointer must outlive this class.
+ MockPlatformGraphics2D(PPB_ImageData_Impl* image_data, float scale)
+ : image_data_(image_data),
+ scale_(scale),
+ bound_instance_(NULL) {
+ }
+ virtual ~MockPlatformGraphics2D() {
+ if (bound_instance_)
+ bound_instance_->SetBoundGraphics2DForTest(NULL);
+ }
+
+ virtual bool ReadImageData(PP_Resource image,
+ const PP_Point* top_left) OVERRIDE {
+ return false;
+ }
+ virtual bool BindToInstance(PluginInstance* new_instance) OVERRIDE {
+ bound_instance_ = new_instance;
+ return true;
+ }
+ virtual void Paint(WebKit::WebCanvas* canvas,
+ const gfx::Rect& plugin_rect,
+ const gfx::Rect& paint_rect) OVERRIDE {}
+ virtual void ViewWillInitiatePaint() OVERRIDE {}
+ virtual void ViewInitiatedPaint() OVERRIDE {}
+ virtual void ViewFlushedPaint() OVERRIDE {}
+
+ virtual bool IsAlwaysOpaque() const OVERRIDE { return true; }
+ virtual void SetScale(float scale) OVERRIDE {}
+ virtual float GetScale() const OVERRIDE { return scale_; }
+ virtual PPB_ImageData_Impl* ImageData() OVERRIDE {
+ return image_data_;
+ }
+
+ private:
+ PPB_ImageData_Impl* image_data_;
+ float scale_;
+ PluginInstance* bound_instance_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockPlatformGraphics2D);
+};
+
+} // namespace
+
+// This class is forward-declared as a friend so can't be in the anonymous
+// namespace.
+class PpapiPluginInstanceTest : public PpapiUnittest {
+ public:
+ bool GetBitmapForOptimizedPluginPaint(const gfx::Rect& paint_bounds,
+ TransportDIB** dib,
+ gfx::Rect* location,
+ gfx::Rect* clip,
+ float* scale_factor) {
+ return !!instance()->GetBitmapForOptimizedPluginPaint(
+ paint_bounds, dib, location, clip, scale_factor);
+ }
+};
+
+
+// Test that GetBitmapForOptimizedPluginPaint doesn't return a bitmap rect
+// that's bigger than the actual backing store bitmap.
+TEST_F(PpapiPluginInstanceTest, GetBitmap2xScale) {
+ PP_Size size;
+ size.width = 3;
+ size.height = 3;
+
+ scoped_refptr<PPB_ImageData_Impl> image_data = new PPB_ImageData_Impl(
+ instance()->pp_instance(), PPB_ImageData_Impl::PLATFORM);
+ image_data->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(),
+ size.width, size.height, true);
+ ASSERT_TRUE(image_data->Map() != NULL);
+
+ float scale = 2.0;
+ MockPlatformGraphics2D mock_graphics_2d(image_data.get(), 1.0 / scale);
+ instance()->SetBoundGraphics2DForTest(&mock_graphics_2d);
+
+ instance()->set_always_on_top(true);
+ SetViewSize(size.width, size.height);
+
+ gfx::Rect bounds(0, 0, 1, 1);
+ gfx::Rect location;
+ gfx::Rect clip;
+ float bitmap_scale = 0;
+ TransportDIB* dib = NULL;
+ EXPECT_TRUE(GetBitmapForOptimizedPluginPaint(
+ bounds, &dib, &location, &clip, &bitmap_scale));
+
+ EXPECT_EQ(0, location.x());
+ EXPECT_EQ(0, location.y());
+ EXPECT_EQ(gfx::ToFlooredInt(size.width / scale), location.width());
+ EXPECT_EQ(gfx::ToFlooredInt(size.height / scale), location.height());
+ EXPECT_EQ(0, clip.x());
+ EXPECT_EQ(0, clip.y());
+ EXPECT_EQ(size.width, clip.width());
+ EXPECT_EQ(size.height, clip.height());
+ EXPECT_EQ(scale, bitmap_scale);
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppapi_unittest.cc b/webkit/plugins/ppapi/ppapi_unittest.cc
index bccebd9..b91e629 100644
--- a/webkit/plugins/ppapi/ppapi_unittest.cc
+++ b/webkit/plugins/ppapi/ppapi_unittest.cc
@@ -12,7 +12,6 @@
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_interface_factory.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
-#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
namespace webkit {
namespace ppapi {
@@ -111,10 +110,9 @@ void PpapiUnittest::ShutdownModule() {
module_ = NULL;
}
-void PpapiUnittest::SetViewSize(int width, int height, float scale) const {
+void PpapiUnittest::SetViewSize(int width, int height) const {
instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height));
instance_->view_data_.clip_rect = instance_->view_data_.rect;
- instance_->GetBoundGraphics2D()->SetScale(scale);
}
void PpapiUnittest::PluginModuleDead(PluginModule* /* dead_module */) {
diff --git a/webkit/plugins/ppapi/ppapi_unittest.h b/webkit/plugins/ppapi/ppapi_unittest.h
index ba6669a..0c64db0 100644
--- a/webkit/plugins/ppapi/ppapi_unittest.h
+++ b/webkit/plugins/ppapi/ppapi_unittest.h
@@ -39,7 +39,7 @@ class PpapiUnittest : public testing::Test,
void ShutdownModule();
// Sets the view size of the plugin instance.
- void SetViewSize(int width, int height, float scale) const;
+ void SetViewSize(int width, int height) const;
protected:
virtual MockPluginDelegate* NewPluginDelegate();
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc
deleted file mode 100644
index 644b8c0..0000000
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/basictypes.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/safe_integer_conversions.h"
-#include "webkit/plugins/ppapi/ppapi_unittest.h"
-#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
-#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
-
-namespace webkit {
-namespace ppapi {
-
-typedef PpapiUnittest PpapiGraphics2DImplTest;
-
-TEST_F(PpapiGraphics2DImplTest, ConvertToLogicalPixels) {
- static const struct {
- int x1;
- int y1;
- int w1;
- int h1;
- int x2;
- int y2;
- int w2;
- int h2;
- int dx1;
- int dy1;
- int dx2;
- int dy2;
- float scale;
- bool result;
- } tests[] = {
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, true },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.0, true },
- { 0, 0, 4, 4, 0, 0, 2, 2, 0, 0, 0, 0, 0.5, true },
- { 1, 1, 4, 4, 0, 0, 3, 3, 0, 0, 0, 0, 0.5, false },
- { 53, 75, 100, 100, 53, 75, 100, 100, 0, 0, 0, 0, 1.0, true },
- { 53, 75, 100, 100, 106, 150, 200, 200, 0, 0, 0, 0, 2.0, true },
- { 53, 75, 100, 100, 26, 37, 51, 51, 0, 0, 0, 0, 0.5, false },
- { 53, 74, 100, 100, 26, 37, 51, 50, 0, 0, 0, 0, 0.5, false },
- { -1, -1, 100, 100, -1, -1, 51, 51, 0, 0, 0, 0, 0.5, false },
- { -2, -2, 100, 100, -1, -1, 50, 50, 4, -4, 2, -2, 0.5, true },
- { -101, -100, 50, 50, -51, -50, 26, 25, 0, 0, 0, 0, 0.5, false },
- { 10, 10, 20, 20, 5, 5, 10, 10, 0, 0, 0, 0, 0.5, true },
- // Cannot scroll due to partial coverage on sides
- { 11, 10, 20, 20, 5, 5, 11, 10, 0, 0, 0, 0, 0.5, false },
- // Can scroll since backing store is actually smaller/scaling up
- { 11, 20, 100, 100, 22, 40, 200, 200, 7, 3, 14, 6, 2.0, true },
- // Can scroll due to delta and bounds being aligned
- { 10, 10, 20, 20, 5, 5, 10, 10, 6, 4, 3, 2, 0.5, true },
- // Cannot scroll due to dx
- { 10, 10, 20, 20, 5, 5, 10, 10, 5, 4, 2, 2, 0.5, false },
- // Cannot scroll due to dy
- { 10, 10, 20, 20, 5, 5, 10, 10, 6, 3, 3, 1, 0.5, false },
- // Cannot scroll due to top
- { 10, 11, 20, 20, 5, 5, 10, 11, 6, 4, 3, 2, 0.5, false },
- // Cannot scroll due to left
- { 7, 10, 20, 20, 3, 5, 11, 10, 6, 4, 3, 2, 0.5, false },
- // Cannot scroll due to width
- { 10, 10, 21, 20, 5, 5, 11, 10, 6, 4, 3, 2, 0.5, false },
- // Cannot scroll due to height
- { 10, 10, 20, 51, 5, 5, 10, 26, 6, 4, 3, 2, 0.5, false },
- // Check negative scroll deltas
- { 10, 10, 20, 20, 5, 5, 10, 10, -6, -4, -3, -2, 0.5, true },
- { 10, 10, 20, 20, 5, 5, 10, 10, -6, -3, -3, -1, 0.5, false },
- };
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
- gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
- gfx::Rect orig = r1;
- gfx::Point delta(tests[i].dx1, tests[i].dy1);
- bool res = webkit::ppapi::PPB_Graphics2D_Impl::ConvertToLogicalPixels(
- tests[i].scale, &r1, &delta);
- EXPECT_EQ(r2.ToString(), r1.ToString());
- EXPECT_EQ(res, tests[i].result);
- if (res) {
- EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2));
- }
- // Reverse the scale and ensure all the original pixels are still inside
- // the result.
- webkit::ppapi::PPB_Graphics2D_Impl::ConvertToLogicalPixels(
- 1.0f / tests[i].scale, &r1, NULL);
- EXPECT_TRUE(r1.Contains(orig));
- }
-}
-
-/*
-Disabled because this doesn't run with the new proxy design.
-TODO(brettw) Rewrite this test to use the new design.
-
-#if !defined(USE_AURA) && (defined(OS_WIN) || defined(OS_LINUX))
-// Windows and Linux don't support scaled optimized plugin paints ATM.
-#define MAYBE_GetBitmap2xScale DISABLED_GetBitmap2xScale
-#else
-#define MAYBE_GetBitmap2xScale GetBitmap2xScale
-#endif
-
-// Test that GetBitmapForOptimizedPluginPaint doesn't return a bitmap rect
-// that's bigger than the actual backing store bitmap.
-TEST_F(PpapiGraphics2DImplTest, GetBitmap2xScale) {
- PP_Size size;
- size.width = 3;
- size.height = 3;
- PP_Resource resource =
- PPB_Graphics2D_Impl::Create(instance()->pp_instance(), size, PP_TRUE);
- EXPECT_TRUE(resource);
- EXPECT_TRUE(instance()->BindGraphics(instance()->pp_instance(), resource));
- instance()->set_always_on_top(true);
- float scale = 2.0;
- SetViewSize(size.width, size.height, 1.0 / scale);
-
- gfx::Rect bounds(0, 0, 1, 1);
- gfx::Rect location;
- gfx::Rect clip;
- float bitmap_scale = 0;
- TransportDIB* dib = NULL;
- EXPECT_TRUE(instance()->GetBitmapForOptimizedPluginPaint(
- bounds, &dib, &location, &clip, &bitmap_scale));
-
- EXPECT_EQ(0, location.x());
- EXPECT_EQ(0, location.y());
- EXPECT_EQ(gfx::ToFlooredInt(size.width / scale), location.width());
- EXPECT_EQ(gfx::ToFlooredInt(size.height / scale), location.height());
- EXPECT_EQ(0, clip.x());
- EXPECT_EQ(0, clip.y());
- EXPECT_EQ(size.width, clip.width());
- EXPECT_EQ(size.height, clip.height());
- EXPECT_EQ(scale, bitmap_scale);
-}
-*/
-
-} // namespace ppapi
-} // namespace webkit
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index c08bba8..7c364a6 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -388,7 +388,7 @@
'../../plugins/ppapi/mock_plugin_delegate.cc',
'../../plugins/ppapi/mock_plugin_delegate.h',
'../../plugins/ppapi/mock_resource.h',
- '../../plugins/ppapi/ppb_graphics_2d_impl_unittest.cc',
+ '../../plugins/ppapi/ppapi_plugin_instance_unittest.cc',
'../../plugins/ppapi/ppapi_unittest.cc',
'../../plugins/ppapi/ppapi_unittest.h',
'../../plugins/ppapi/quota_file_io_unittest.cc',