| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
| 11 #include "ui/gfx/safe_integer_conversions.h" | 11 #include "ui/gfx/safe_integer_conversions.h" |
| 12 #include "webkit/plugins/ppapi/plugin_delegate.h" | 12 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 13 #include "webkit/plugins/ppapi/ppapi_unittest.h" | 13 #include "webkit/plugins/ppapi/ppapi_unittest.h" |
| 14 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 14 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 15 | 15 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 virtual ~MockPlatformGraphics2D() { | 35 virtual ~MockPlatformGraphics2D() { |
| 36 if (bound_instance_) | 36 if (bound_instance_) |
| 37 bound_instance_->SetBoundGraphics2DForTest(NULL); | 37 bound_instance_->SetBoundGraphics2DForTest(NULL); |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual bool ReadImageData(PP_Resource image, | 40 virtual bool ReadImageData(PP_Resource image, |
| 41 const PP_Point* top_left) OVERRIDE { | 41 const PP_Point* top_left) OVERRIDE { |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 virtual bool BindToInstance(PluginInstance* new_instance) OVERRIDE { | 44 virtual bool BindToInstance(PluginInstanceImpl* new_instance) OVERRIDE { |
| 45 bound_instance_ = new_instance; | 45 bound_instance_ = new_instance; |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 virtual void Paint(WebKit::WebCanvas* canvas, | 48 virtual void Paint(WebKit::WebCanvas* canvas, |
| 49 const gfx::Rect& plugin_rect, | 49 const gfx::Rect& plugin_rect, |
| 50 const gfx::Rect& paint_rect) OVERRIDE {} | 50 const gfx::Rect& paint_rect) OVERRIDE {} |
| 51 virtual void ViewWillInitiatePaint() OVERRIDE {} | 51 virtual void ViewWillInitiatePaint() OVERRIDE {} |
| 52 virtual void ViewInitiatedPaint() OVERRIDE {} | 52 virtual void ViewInitiatedPaint() OVERRIDE {} |
| 53 virtual void ViewFlushedPaint() OVERRIDE {} | 53 virtual void ViewFlushedPaint() OVERRIDE {} |
| 54 | 54 |
| 55 virtual bool IsAlwaysOpaque() const OVERRIDE { return true; } | 55 virtual bool IsAlwaysOpaque() const OVERRIDE { return true; } |
| 56 virtual void SetScale(float scale) OVERRIDE {} | 56 virtual void SetScale(float scale) OVERRIDE {} |
| 57 virtual float GetScale() const OVERRIDE { return scale_; } | 57 virtual float GetScale() const OVERRIDE { return scale_; } |
| 58 virtual PPB_ImageData_Impl* ImageData() OVERRIDE { | 58 virtual PPB_ImageData_Impl* ImageData() OVERRIDE { |
| 59 return image_data_; | 59 return image_data_; |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 PPB_ImageData_Impl* image_data_; | 63 PPB_ImageData_Impl* image_data_; |
| 64 float scale_; | 64 float scale_; |
| 65 PluginInstance* bound_instance_; | 65 PluginInstanceImpl* bound_instance_; |
| 66 | 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(MockPlatformGraphics2D); | 67 DISALLOW_COPY_AND_ASSIGN(MockPlatformGraphics2D); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 // This class is forward-declared as a friend so can't be in the anonymous | 72 // This class is forward-declared as a friend so can't be in the anonymous |
| 73 // namespace. | 73 // namespace. |
| 74 class PpapiPluginInstanceTest : public PpapiUnittest { | 74 class PpapiPluginInstanceTest : public PpapiUnittest { |
| 75 public: | 75 public: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 scoped_refptr<PPB_ImageData_Impl> image_data = new PPB_ImageData_Impl( | 94 scoped_refptr<PPB_ImageData_Impl> image_data = new PPB_ImageData_Impl( |
| 95 instance()->pp_instance(), PPB_ImageData_Impl::PLATFORM); | 95 instance()->pp_instance(), PPB_ImageData_Impl::PLATFORM); |
| 96 image_data->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), | 96 image_data->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), |
| 97 size.width, size.height, true); | 97 size.width, size.height, true); |
| 98 ASSERT_TRUE(image_data->Map() != NULL); | 98 ASSERT_TRUE(image_data->Map() != NULL); |
| 99 | 99 |
| 100 float scale = 2.0; | 100 float scale = 2.0; |
| 101 MockPlatformGraphics2D mock_graphics_2d(image_data.get(), 1.0 / scale); | 101 MockPlatformGraphics2D mock_graphics_2d(image_data.get(), 1.0 / scale); |
| 102 instance()->SetBoundGraphics2DForTest(&mock_graphics_2d); | 102 instance()->SetBoundGraphics2DForTest(&mock_graphics_2d); |
| 103 | 103 |
| 104 instance()->set_always_on_top(true); | 104 instance()->SetAlwaysOnTop(true); |
| 105 SetViewSize(size.width, size.height); | 105 SetViewSize(size.width, size.height); |
| 106 | 106 |
| 107 gfx::Rect bounds(0, 0, 1, 1); | 107 gfx::Rect bounds(0, 0, 1, 1); |
| 108 gfx::Rect location; | 108 gfx::Rect location; |
| 109 gfx::Rect clip; | 109 gfx::Rect clip; |
| 110 float bitmap_scale = 0; | 110 float bitmap_scale = 0; |
| 111 TransportDIB* dib = NULL; | 111 TransportDIB* dib = NULL; |
| 112 EXPECT_TRUE(GetBitmapForOptimizedPluginPaint( | 112 EXPECT_TRUE(GetBitmapForOptimizedPluginPaint( |
| 113 bounds, &dib, &location, &clip, &bitmap_scale)); | 113 bounds, &dib, &location, &clip, &bitmap_scale)); |
| 114 | 114 |
| 115 EXPECT_EQ(0, location.x()); | 115 EXPECT_EQ(0, location.x()); |
| 116 EXPECT_EQ(0, location.y()); | 116 EXPECT_EQ(0, location.y()); |
| 117 EXPECT_EQ(gfx::ToFlooredInt(size.width / scale), location.width()); | 117 EXPECT_EQ(gfx::ToFlooredInt(size.width / scale), location.width()); |
| 118 EXPECT_EQ(gfx::ToFlooredInt(size.height / scale), location.height()); | 118 EXPECT_EQ(gfx::ToFlooredInt(size.height / scale), location.height()); |
| 119 EXPECT_EQ(0, clip.x()); | 119 EXPECT_EQ(0, clip.x()); |
| 120 EXPECT_EQ(0, clip.y()); | 120 EXPECT_EQ(0, clip.y()); |
| 121 EXPECT_EQ(size.width, clip.width()); | 121 EXPECT_EQ(size.width, clip.width()); |
| 122 EXPECT_EQ(size.height, clip.height()); | 122 EXPECT_EQ(size.height, clip.height()); |
| 123 EXPECT_EQ(scale, bitmap_scale); | 123 EXPECT_EQ(scale, bitmap_scale); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace ppapi | 126 } // namespace ppapi |
| 127 } // namespace webkit | 127 } // namespace webkit |
| OLD | NEW |