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 "content/renderer/pepper/pepper_graphics_2d_host.h" | 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/renderer/pepper/gfx_conversion.h" | 9 #include "content/renderer/pepper/gfx_conversion.h" |
10 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" | 10 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 host_.reset(); | 37 host_.reset(); |
38 } | 38 } |
39 | 39 |
40 void Init(PP_Instance instance, | 40 void Init(PP_Instance instance, |
41 const PP_Size& backing_store_size, | 41 const PP_Size& backing_store_size, |
42 const PP_Rect& plugin_rect) { | 42 const PP_Rect& plugin_rect) { |
43 renderer_view_data_.rect = plugin_rect; | 43 renderer_view_data_.rect = plugin_rect; |
44 test_globals_.GetResourceTracker()->DidCreateInstance(instance); | 44 test_globals_.GetResourceTracker()->DidCreateInstance(instance); |
45 scoped_refptr<PPB_ImageData_Impl> backing_store( | 45 scoped_refptr<PPB_ImageData_Impl> backing_store( |
46 new PPB_ImageData_Impl(instance, PPB_ImageData_Impl::ForTest())); | 46 new PPB_ImageData_Impl(instance, PPB_ImageData_Impl::ForTest())); |
47 host_.reset(PepperGraphics2DHost::Create( | 47 host_.reset(PepperGraphics2DHost::Create(&renderer_ppapi_host_, |
48 &renderer_ppapi_host_, instance, 12345, backing_store_size, PP_FALSE, | 48 instance, |
49 backing_store)); | 49 12345, |
| 50 backing_store_size, |
| 51 PP_FALSE, |
| 52 backing_store)); |
50 DCHECK(host_.get()); | 53 DCHECK(host_.get()); |
51 } | 54 } |
52 | 55 |
53 void PaintImageData(PPB_ImageData_Impl* image_data) { | 56 void PaintImageData(PPB_ImageData_Impl* image_data) { |
54 ppapi::HostResource image_data_resource; | 57 ppapi::HostResource image_data_resource; |
55 image_data_resource.SetHostResource(image_data->pp_instance(), | 58 image_data_resource.SetHostResource(image_data->pp_instance(), |
56 image_data->pp_resource()); | 59 image_data->pp_resource()); |
57 host_->OnHostMsgPaintImageData(NULL, image_data_resource, | 60 host_->OnHostMsgPaintImageData( |
58 PP_Point(), false, PP_Rect()); | 61 NULL, image_data_resource, PP_Point(), false, PP_Rect()); |
59 } | 62 } |
60 | 63 |
61 void Flush() { | 64 void Flush() { |
62 ppapi::host::HostMessageContext context( | 65 ppapi::host::HostMessageContext context( |
63 ppapi::proxy::ResourceMessageCallParams(host_->pp_resource(), 0)); | 66 ppapi::proxy::ResourceMessageCallParams(host_->pp_resource(), 0)); |
64 host_->OnHostMsgFlush(&context); | 67 host_->OnHostMsgFlush(&context); |
65 host_->ViewFlushedPaint(); | 68 host_->ViewFlushedPaint(); |
66 host_->SendOffscreenFlushAck(); | 69 host_->SendOffscreenFlushAck(); |
67 } | 70 } |
68 | 71 |
69 void PaintToWebCanvas(SkBitmap* bitmap) { | 72 void PaintToWebCanvas(SkBitmap* bitmap) { |
70 scoped_ptr<WebCanvas> canvas(new WebCanvas(*bitmap)); | 73 scoped_ptr<WebCanvas> canvas(new WebCanvas(*bitmap)); |
71 gfx::Rect plugin_rect(PP_ToGfxRect(renderer_view_data_.rect)); | 74 gfx::Rect plugin_rect(PP_ToGfxRect(renderer_view_data_.rect)); |
72 host_->Paint(canvas.get(), plugin_rect, | 75 host_->Paint(canvas.get(), |
| 76 plugin_rect, |
73 gfx::Rect(0, 0, plugin_rect.width(), plugin_rect.height())); | 77 gfx::Rect(0, 0, plugin_rect.width(), plugin_rect.height())); |
74 } | 78 } |
75 | 79 |
76 void ResetPageBitmap(SkBitmap* bitmap) { | 80 void ResetPageBitmap(SkBitmap* bitmap) { |
77 PP_Rect plugin_rect = renderer_view_data_.rect; | 81 PP_Rect plugin_rect = renderer_view_data_.rect; |
78 int width = plugin_rect.point.x + plugin_rect.size.width; | 82 int width = plugin_rect.point.x + plugin_rect.size.width; |
79 int height = plugin_rect.point.y + plugin_rect.size.height; | 83 int height = plugin_rect.point.y + plugin_rect.size.height; |
80 if (bitmap->isNull() || bitmap->width() != width || | 84 if (bitmap->isNull() || bitmap->width() != width || |
81 bitmap->height() != height) { | 85 bitmap->height() != height) { |
82 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 86 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
(...skipping 19 matching lines...) Expand all Loading... |
102 int x2; | 106 int x2; |
103 int y2; | 107 int y2; |
104 int w2; | 108 int w2; |
105 int h2; | 109 int h2; |
106 int dx1; | 110 int dx1; |
107 int dy1; | 111 int dy1; |
108 int dx2; | 112 int dx2; |
109 int dy2; | 113 int dy2; |
110 float scale; | 114 float scale; |
111 bool result; | 115 bool result; |
112 } tests[] = { | 116 } tests[] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, true}, |
113 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, true }, | 117 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.0, true}, |
114 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.0, true }, | 118 {0, 0, 4, 4, 0, 0, 2, 2, 0, 0, 0, 0, 0.5, true}, |
115 { 0, 0, 4, 4, 0, 0, 2, 2, 0, 0, 0, 0, 0.5, true }, | 119 {1, 1, 4, 4, 0, 0, 3, 3, 0, 0, 0, 0, 0.5, false}, |
116 { 1, 1, 4, 4, 0, 0, 3, 3, 0, 0, 0, 0, 0.5, false }, | 120 {53, 75, 100, 100, 53, 75, 100, 100, 0, 0, 0, 0, 1.0, true}, |
117 { 53, 75, 100, 100, 53, 75, 100, 100, 0, 0, 0, 0, 1.0, true }, | 121 {53, 75, 100, 100, 106, 150, 200, 200, 0, 0, 0, 0, 2.0, true}, |
118 { 53, 75, 100, 100, 106, 150, 200, 200, 0, 0, 0, 0, 2.0, true }, | 122 {53, 75, 100, 100, 26, 37, 51, 51, 0, 0, 0, 0, 0.5, false}, |
119 { 53, 75, 100, 100, 26, 37, 51, 51, 0, 0, 0, 0, 0.5, false }, | 123 {53, 74, 100, 100, 26, 37, 51, 50, 0, 0, 0, 0, 0.5, false}, |
120 { 53, 74, 100, 100, 26, 37, 51, 50, 0, 0, 0, 0, 0.5, false }, | 124 {-1, -1, 100, 100, -1, -1, 51, 51, 0, 0, 0, 0, 0.5, false}, |
121 { -1, -1, 100, 100, -1, -1, 51, 51, 0, 0, 0, 0, 0.5, false }, | 125 {-2, -2, 100, 100, -1, -1, 50, 50, 4, -4, 2, -2, 0.5, true}, |
122 { -2, -2, 100, 100, -1, -1, 50, 50, 4, -4, 2, -2, 0.5, true }, | 126 {-101, -100, 50, 50, -51, -50, 26, 25, 0, 0, 0, 0, 0.5, false}, |
123 { -101, -100, 50, 50, -51, -50, 26, 25, 0, 0, 0, 0, 0.5, false }, | 127 {10, 10, 20, 20, 5, 5, 10, 10, 0, 0, 0, 0, 0.5, true}, |
124 { 10, 10, 20, 20, 5, 5, 10, 10, 0, 0, 0, 0, 0.5, true }, | 128 // Cannot scroll due to partial coverage on sides |
125 // Cannot scroll due to partial coverage on sides | 129 {11, 10, 20, 20, 5, 5, 11, 10, 0, 0, 0, 0, 0.5, false}, |
126 { 11, 10, 20, 20, 5, 5, 11, 10, 0, 0, 0, 0, 0.5, false }, | 130 // Can scroll since backing store is actually smaller/scaling up |
127 // Can scroll since backing store is actually smaller/scaling up | 131 {11, 20, 100, 100, 22, 40, 200, 200, 7, 3, 14, 6, 2.0, true}, |
128 { 11, 20, 100, 100, 22, 40, 200, 200, 7, 3, 14, 6, 2.0, true }, | 132 // Can scroll due to delta and bounds being aligned |
129 // Can scroll due to delta and bounds being aligned | 133 {10, 10, 20, 20, 5, 5, 10, 10, 6, 4, 3, 2, 0.5, true}, |
130 { 10, 10, 20, 20, 5, 5, 10, 10, 6, 4, 3, 2, 0.5, true }, | 134 // Cannot scroll due to dx |
131 // Cannot scroll due to dx | 135 {10, 10, 20, 20, 5, 5, 10, 10, 5, 4, 2, 2, 0.5, false}, |
132 { 10, 10, 20, 20, 5, 5, 10, 10, 5, 4, 2, 2, 0.5, false }, | 136 // Cannot scroll due to dy |
133 // Cannot scroll due to dy | 137 {10, 10, 20, 20, 5, 5, 10, 10, 6, 3, 3, 1, 0.5, false}, |
134 { 10, 10, 20, 20, 5, 5, 10, 10, 6, 3, 3, 1, 0.5, false }, | 138 // Cannot scroll due to top |
135 // Cannot scroll due to top | 139 {10, 11, 20, 20, 5, 5, 10, 11, 6, 4, 3, 2, 0.5, false}, |
136 { 10, 11, 20, 20, 5, 5, 10, 11, 6, 4, 3, 2, 0.5, false }, | 140 // Cannot scroll due to left |
137 // Cannot scroll due to left | 141 {7, 10, 20, 20, 3, 5, 11, 10, 6, 4, 3, 2, 0.5, false}, |
138 { 7, 10, 20, 20, 3, 5, 11, 10, 6, 4, 3, 2, 0.5, false }, | 142 // Cannot scroll due to width |
139 // Cannot scroll due to width | 143 {10, 10, 21, 20, 5, 5, 11, 10, 6, 4, 3, 2, 0.5, false}, |
140 { 10, 10, 21, 20, 5, 5, 11, 10, 6, 4, 3, 2, 0.5, false }, | 144 // Cannot scroll due to height |
141 // Cannot scroll due to height | 145 {10, 10, 20, 51, 5, 5, 10, 26, 6, 4, 3, 2, 0.5, false}, |
142 { 10, 10, 20, 51, 5, 5, 10, 26, 6, 4, 3, 2, 0.5, false }, | 146 // Check negative scroll deltas |
143 // Check negative scroll deltas | 147 {10, 10, 20, 20, 5, 5, 10, 10, -6, -4, -3, -2, 0.5, true}, |
144 { 10, 10, 20, 20, 5, 5, 10, 10, -6, -4, -3, -2, 0.5, true }, | 148 {10, 10, 20, 20, 5, 5, 10, 10, -6, -3, -3, -1, 0.5, false}, }; |
145 { 10, 10, 20, 20, 5, 5, 10, 10, -6, -3, -3, -1, 0.5, false }, | |
146 }; | |
147 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 149 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
148 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 150 gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
149 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 151 gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
150 gfx::Rect orig = r1; | 152 gfx::Rect orig = r1; |
151 gfx::Point delta(tests[i].dx1, tests[i].dy1); | 153 gfx::Point delta(tests[i].dx1, tests[i].dy1); |
152 bool res = ConvertToLogicalPixels(tests[i].scale, &r1, &delta); | 154 bool res = ConvertToLogicalPixels(tests[i].scale, &r1, &delta); |
153 EXPECT_EQ(r2.ToString(), r1.ToString()); | 155 EXPECT_EQ(r2.ToString(), r1.ToString()); |
154 EXPECT_EQ(res, tests[i].result); | 156 EXPECT_EQ(res, tests[i].result); |
155 if (res) { | 157 if (res) { |
156 EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2)); | 158 EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2)); |
157 } | 159 } |
158 // Reverse the scale and ensure all the original pixels are still inside | 160 // Reverse the scale and ensure all the original pixels are still inside |
159 // the result. | 161 // the result. |
160 ConvertToLogicalPixels(1.0f / tests[i].scale, &r1, NULL); | 162 ConvertToLogicalPixels(1.0f / tests[i].scale, &r1, NULL); |
161 EXPECT_TRUE(r1.Contains(orig)); | 163 EXPECT_TRUE(r1.Contains(orig)); |
162 } | 164 } |
163 } | 165 } |
164 | 166 |
165 } // namespace content | 167 } // namespace content |
OLD | NEW |