Derek Sollenberger | c0f2657 | 2009-07-16 11:38:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009, The Android Open Source Project |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 24 | */ |
| 25 | |
| 26 | #include "SurfacePlugin.h" |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <sys/time.h> |
| 30 | #include <time.h> |
| 31 | #include <math.h> |
| 32 | #include <string.h> |
| 33 | |
| 34 | extern NPNetscapeFuncs* browser; |
| 35 | extern ANPLogInterfaceV0 gLogI; |
| 36 | extern ANPPaintInterfaceV0 gPaintI; |
| 37 | extern ANPSurfaceInterfaceV0 gSurfaceI; |
| 38 | extern ANPTypefaceInterfaceV0 gTypefaceI; |
| 39 | extern ANPWindowInterfaceV0 gWindowI; |
| 40 | |
| 41 | /////////////////////////////////////////////////////////////////////////////// |
| 42 | |
| 43 | SurfacePlugin::SurfacePlugin(NPP inst, ANPSurfaceType surfaceType) : SubPlugin(inst) { |
| 44 | |
| 45 | m_surface = gSurfaceI.newSurface(inst, surfaceType); |
| 46 | |
| 47 | if(!m_surface) |
| 48 | gLogI.log(inst, kError_ANPLogType, "----%p Unable to create surface (%d)", inst, surfaceType); |
| 49 | } |
| 50 | |
| 51 | SurfacePlugin::~SurfacePlugin() { |
| 52 | if (m_surface) |
| 53 | gSurfaceI.deleteSurface(m_surface); |
| 54 | } |
| 55 | |
| 56 | bool SurfacePlugin::supportsDrawingModel(ANPDrawingModel model) { |
| 57 | return (model == kSurface_ANPDrawingModel); |
| 58 | } |
| 59 | |
| 60 | void SurfacePlugin::draw() { |
| 61 | NPP instance = this->inst(); |
| 62 | PluginObject *obj = (PluginObject*) instance->pdata; |
| 63 | |
| 64 | ANPBitmap bitmap; |
| 65 | |
| 66 | bool value = gSurfaceI.lock(m_surface, &bitmap, NULL); |
| 67 | gLogI.log(instance, kDebug_ANPLogType, "----%p locking: %b", instance, value); |
| 68 | gSurfaceI.unlock(m_surface); |
| 69 | } |
| 70 | |
| 71 | int16 SurfacePlugin::handleEvent(const ANPEvent* evt) { |
| 72 | NPP instance = this->inst(); |
| 73 | |
| 74 | switch (evt->eventType) { |
| 75 | case kDraw_ANPEventType: |
| 76 | switch (evt->data.draw.model) { |
| 77 | case kSurface_ANPDrawingModel: |
| 78 | if (m_surface) |
| 79 | draw(); |
| 80 | return 1; |
| 81 | default: |
| 82 | break; // unknown drawing model |
| 83 | } |
| 84 | default: |
| 85 | break; |
| 86 | } |
| 87 | return 0; // unknown or unhandled event |
| 88 | } |