OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "webkit/tools/pepper_test_plugin/plugin_object.h" | 26 #include "webkit/tools/pepper_test_plugin/plugin_object.h" |
27 | 27 |
| 28 #include <stdio.h> |
28 #include <string> | 29 #include <string> |
29 | 30 |
30 #include "base/logging.h" | 31 #include "base/logging.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "third_party/skia/include/core/SkCanvas.h" | 33 #include "third_party/skia/include/core/SkCanvas.h" |
33 #include "third_party/skia/include/effects/SkGradientShader.h" | 34 #include "third_party/skia/include/effects/SkGradientShader.h" |
34 #include "webkit/tools/pepper_test_plugin/test_object.h" | 35 #include "webkit/tools/pepper_test_plugin/test_object.h" |
35 | 36 |
36 NPNetscapeFuncs* browser; | 37 NPNetscapeFuncs* browser; |
37 | 38 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 SkPoint grad_points[2]; | 217 SkPoint grad_points[2]; |
217 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 218 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); |
218 grad_points[1].set(SkIntToScalar(0), SkIntToScalar(height)); | 219 grad_points[1].set(SkIntToScalar(0), SkIntToScalar(height)); |
219 paint.setShader(SkGradientShader::CreateLinear( | 220 paint.setShader(SkGradientShader::CreateLinear( |
220 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)) | 221 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)) |
221 ->safeUnref(); | 222 ->safeUnref(); |
222 | 223 |
223 canvas.drawPath(path, paint); | 224 canvas.drawPath(path, paint); |
224 } | 225 } |
225 | 226 |
226 NPInitializeRenderContextPtr initialize_render_context = NULL; | 227 NPPepperExtensions* pepper = NULL; |
227 NPFlushRenderContextPtr flush_render_context = NULL; | |
228 | 228 |
229 void FlushCallback(NPRenderContext* context, void* user_data) { | 229 void FlushCallback(NPRenderContext* context, void* user_data) { |
230 } | 230 } |
231 | 231 |
232 } // namespace | 232 } // namespace |
233 | 233 |
234 | 234 |
235 // PluginObject ---------------------------------------------------------------- | 235 // PluginObject ---------------------------------------------------------------- |
236 | 236 |
237 PluginObject::PluginObject(NPP npp) | 237 PluginObject::PluginObject(NPP npp) |
238 : npp_(npp), | 238 : npp_(npp), |
239 test_object_(browser->createobject(npp, GetTestClass())) { | 239 test_object_(browser->createobject(npp, GetTestClass())) { |
240 if (!initialize_render_context || !flush_render_context) { | 240 if (!pepper) { |
241 NPPepperExtensions* extensions; | |
242 browser->getvalue(npp_, NPNVPepperExtensions, | 241 browser->getvalue(npp_, NPNVPepperExtensions, |
243 reinterpret_cast<void*>(&extensions)); | 242 reinterpret_cast<void*>(&pepper)); |
244 CHECK(extensions); | 243 CHECK(pepper); |
245 initialize_render_context = extensions->initializeRender; | |
246 CHECK(initialize_render_context); | |
247 flush_render_context = extensions->flushRender; | |
248 CHECK(flush_render_context); | |
249 } | 244 } |
250 } | 245 } |
251 | 246 |
252 PluginObject::~PluginObject() { | 247 PluginObject::~PluginObject() { |
253 browser->releaseobject(test_object_); | 248 browser->releaseobject(test_object_); |
254 } | 249 } |
255 | 250 |
256 // static | 251 // static |
257 NPClass* PluginObject::GetPluginClass() { | 252 NPClass* PluginObject::GetPluginClass() { |
258 return &plugin_class; | 253 return &plugin_class; |
259 } | 254 } |
260 | 255 |
261 void PluginObject::SetWindow(const NPWindow& window) { | 256 void PluginObject::SetWindow(const NPWindow& window) { |
| 257 // File test |
| 258 /* TODO(brettw): remove this when the file stuff is complete. This code is for |
| 259 testing the OpenFileInSandbox function which is not complete. |
| 260 { |
| 261 void* handle = (void*)112358; |
| 262 NPError err = pepper->openFile(npp_, |
| 263 "q:\\prj\\src2\\src\\webkit\\tools\\pepper_test_plugin\\README", |
| 264 &handle); |
| 265 CHECK(err == NPERR_NO_ERROR); |
| 266 |
| 267 char buf[256]; |
| 268 sprintf(buf, "Got the handle %d", (int)handle); |
| 269 ::MessageBoxA(NULL, buf, "pepper", 0); |
| 270 }*/ |
| 271 |
262 size_.set_width(window.width); | 272 size_.set_width(window.width); |
263 size_.set_height(window.height); | 273 size_.set_height(window.height); |
264 | 274 |
265 NPRenderContext context; | 275 NPRenderContext context; |
266 initialize_render_context(npp_, NPRenderGraphicsRGBA, &context); | 276 pepper->initializeRender(npp_, NPRenderGraphicsRGBA, &context); |
267 | 277 |
268 SkBitmap bitmap; | 278 SkBitmap bitmap; |
269 bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); | 279 bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); |
270 bitmap.setPixels(context.u.graphicsRgba.region); | 280 bitmap.setPixels(context.u.graphicsRgba.region); |
271 | 281 |
272 SkCanvas canvas(bitmap); | 282 SkCanvas canvas(bitmap); |
273 DrawSampleBitmap(canvas, window.width, window.height); | 283 DrawSampleBitmap(canvas, window.width, window.height); |
274 | 284 |
275 // TODO(brettw) figure out why this cast is necessary, the functions seem to | 285 // TODO(brettw) figure out why this cast is necessary, the functions seem to |
276 // match. Could be a calling convention mismatch? | 286 // match. Could be a calling convention mismatch? |
277 NPFlushRenderContextCallbackPtr callback = | 287 NPFlushRenderContextCallbackPtr callback = |
278 reinterpret_cast<NPFlushRenderContextCallbackPtr>(&FlushCallback); | 288 reinterpret_cast<NPFlushRenderContextCallbackPtr>(&FlushCallback); |
279 flush_render_context(npp_, &context, callback, NULL); | 289 pepper->flushRender(npp_, &context, callback, NULL); |
280 } | 290 } |
OLD | NEW |