Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "content/renderer/pepper/gfx_conversion.h" | 11 #include "content/renderer/pepper/gfx_conversion.h" |
| 12 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" | 12 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" |
| 13 #include "content/renderer/pepper/ppb_image_data_impl.h" | 13 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 14 #include "ppapi/shared_impl/ppb_view_shared.h" | 14 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 15 #include "ppapi/shared_impl/proxy_lock.h" | 15 #include "ppapi/shared_impl/proxy_lock.h" |
| 16 #include "ppapi/shared_impl/test_globals.h" | 16 #include "ppapi/shared_impl/test_globals.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebCanvas.h" | |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 22 | 21 |
| 23 using blink::WebCanvas; | |
| 24 | |
| 25 namespace content { | 22 namespace content { |
| 26 | 23 |
| 27 class PepperGraphics2DHostTest : public testing::Test { | 24 class PepperGraphics2DHostTest : public testing::Test { |
| 28 public: | 25 public: |
| 29 static bool ConvertToLogicalPixels(float scale, | 26 static bool ConvertToLogicalPixels(float scale, |
| 30 gfx::Rect* op_rect, | 27 gfx::Rect* op_rect, |
| 31 gfx::Point* delta) { | 28 gfx::Point* delta) { |
| 32 return PepperGraphics2DHost::ConvertToLogicalPixels(scale, op_rect, delta); | 29 return PepperGraphics2DHost::ConvertToLogicalPixels(scale, op_rect, delta); |
| 33 } | 30 } |
| 34 | 31 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 64 } | 61 } |
| 65 | 62 |
| 66 void Flush() { | 63 void Flush() { |
| 67 ppapi::host::HostMessageContext context( | 64 ppapi::host::HostMessageContext context( |
| 68 ppapi::proxy::ResourceMessageCallParams(host_->pp_resource(), 0)); | 65 ppapi::proxy::ResourceMessageCallParams(host_->pp_resource(), 0)); |
| 69 host_->OnHostMsgFlush(&context); | 66 host_->OnHostMsgFlush(&context); |
| 70 host_->ViewInitiatedPaint(); | 67 host_->ViewInitiatedPaint(); |
| 71 host_->SendOffscreenFlushAck(); | 68 host_->SendOffscreenFlushAck(); |
| 72 } | 69 } |
| 73 | 70 |
| 74 void PaintToWebCanvas(SkBitmap* bitmap) { | |
|
enne (OOO)
2017/03/14 17:50:10
I went to change this to SkiaPaintCanvas, but it a
ncarter (slow)
2017/03/14 18:00:33
Even better.
| |
| 75 std::unique_ptr<WebCanvas> canvas(new WebCanvas(*bitmap)); | |
| 76 gfx::Rect plugin_rect(PP_ToGfxRect(renderer_view_data_.rect)); | |
| 77 host_->Paint(canvas.get(), | |
| 78 plugin_rect, | |
| 79 gfx::Rect(0, 0, plugin_rect.width(), plugin_rect.height())); | |
| 80 } | |
| 81 | |
| 82 void ResetPageBitmap(SkBitmap* bitmap) { | 71 void ResetPageBitmap(SkBitmap* bitmap) { |
| 83 PP_Rect plugin_rect = renderer_view_data_.rect; | 72 PP_Rect plugin_rect = renderer_view_data_.rect; |
| 84 int width = plugin_rect.point.x + plugin_rect.size.width; | 73 int width = plugin_rect.point.x + plugin_rect.size.width; |
| 85 int height = plugin_rect.point.y + plugin_rect.size.height; | 74 int height = plugin_rect.point.y + plugin_rect.size.height; |
| 86 if (bitmap->isNull() || bitmap->width() != width || | 75 if (bitmap->isNull() || bitmap->width() != width || |
| 87 bitmap->height() != height) { | 76 bitmap->height() != height) { |
| 88 bitmap->allocN32Pixels(width, height); | 77 bitmap->allocN32Pixels(width, height); |
| 89 } | 78 } |
| 90 bitmap->eraseColor(0); | 79 bitmap->eraseColor(0); |
| 91 } | 80 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2)); | 148 EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2)); |
| 160 } | 149 } |
| 161 // Reverse the scale and ensure all the original pixels are still inside | 150 // Reverse the scale and ensure all the original pixels are still inside |
| 162 // the result. | 151 // the result. |
| 163 ConvertToLogicalPixels(1.0f / tests[i].scale, &r1, NULL); | 152 ConvertToLogicalPixels(1.0f / tests[i].scale, &r1, NULL); |
| 164 EXPECT_TRUE(r1.Contains(orig)); | 153 EXPECT_TRUE(r1.Contains(orig)); |
| 165 } | 154 } |
| 166 } | 155 } |
| 167 | 156 |
| 168 } // namespace content | 157 } // namespace content |
| OLD | NEW |