Attachment #435627: Windowless ImageSurface rendering API + IPC implementation for bug #554270

View | Details | Raw Unified | Return to bug 554270
Collapse All | Expand All

(-)a/dom/plugins/Makefile.in (+1 lines)
Line     Link Here 
 Lines 61-70   EXPORTS_mozilla/plugins = \ Link Here 
61
  ChildAsyncCall.h \
61
  ChildAsyncCall.h \
62
  ChildTimer.h \
62
  ChildTimer.h \
63
  NPEventOSX.h \
63
  NPEventOSX.h \
64
  NPEventWindows.h \
64
  NPEventWindows.h \
65
  NPEventX11.h \
65
  NPEventX11.h \
66
  NPEventMem.h \
66
  PluginIdentifierChild.h \
67
  PluginIdentifierChild.h \
67
  PluginIdentifierParent.h \
68
  PluginIdentifierParent.h \
68
  PluginInstanceChild.h \
69
  PluginInstanceChild.h \
69
  PluginInstanceParent.h \
70
  PluginInstanceParent.h \
70
  PluginMessageUtils.h \
71
  PluginMessageUtils.h \
(-)ca3038f38f65 (+92 lines)
Added Link Here 
Added Link Here 
1
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
2
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
3
/* ***** BEGIN LICENSE BLOCK *****
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version
7
 * 1.1 (the "License"); you may not use this file except in compliance with
8
 * the License. You may obtain a copy of the License at
9
 * http://www.mozilla.org/MPL/
10
 *
11
 * Software distributed under the License is distributed on an "AS IS" basis,
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 * for the specific language governing rights and limitations under the
14
 * License.
15
 *
16
 * The Original Code is Mozilla Plugin App.
17
 *
18
 * The Initial Developer of the Original Code is
19
 *   The Mozilla Foundation.
20
 * Portions created by the Initial Developer are Copyright (C) 2010
21
 * the Initial Developer. All Rights Reserved.
22
 *
23
 * Contributor(s):
24
 *   Oleg Romashin <romaxa@gmail.com>
25
 *
26
 * Alternatively, the contents of this file may be used under the terms of
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
30
 * of those above. If you wish to allow use of your version of this file only
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
32
 * use your version of this file under the terms of the MPL, indicate your
33
 * decision by deleting the provisions above and replace them with the notice
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
35
 * the provisions above, a recipient may use your version of this file under
36
 * the terms of any one of the MPL, the GPL or the LGPL.
37
 *
38
 * ***** END LICENSE BLOCK ***** */
39
40
#ifndef mozilla_dom_plugins_NPEventMem_h
41
#define mozilla_dom_plugins_NPEventMem_h 1
42
43
#include "npapi.h"
44
45
namespace mozilla {
46
47
namespace plugins {
48
49
struct NPRemoteMemEvent {
50
    NPImageExpose event;
51
};
52
53
}
54
55
}
56
57
namespace IPC {
58
59
template <>
60
struct ParamTraits<mozilla::plugins::NPRemoteMemEvent>     // synonym for XEvent
61
{
62
    typedef mozilla::plugins::NPRemoteMemEvent paramType;
63
64
    static void Write(Message* aMsg, const paramType& aParam)
65
    {
66
        aMsg->WriteBytes(&aParam, sizeof(paramType));
67
    }
68
69
    static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
70
    {
71
        const char* bytes = 0;
72
73
        if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
74
            return false;
75
        }
76
77
        memcpy(aResult, bytes, sizeof(paramType));
78
        return true;
79
    }
80
81
    static void Log(const paramType& aParam, std::wstring* aLog)
82
    {
83
        // TODO
84
        aLog->append(L"(MemEvent)");
85
    }
86
87
};
88
89
} // namespace IPC
90
91
92
#endif // ifndef mozilla_dom_plugins_NPEventMem_h
(-)a/dom/plugins/PPluginInstance.ipdl (+6 lines)
Line     Link Here 
 Lines 46-55   include protocol "PStreamNotify.ipdl"; Link Here 
46
include "mozilla/plugins/PluginMessageUtils.h";
46
include "mozilla/plugins/PluginMessageUtils.h";
47
47
48
using NPError;
48
using NPError;
49
using NPRemoteWindow;
49
using NPRemoteWindow;
50
using NPRemoteEvent;
50
using NPRemoteEvent;
51
using NPRemoteMemEvent;
51
using NPRect;
52
using NPRect;
52
using NPNURLVariable;
53
using NPNURLVariable;
53
using NPCoordinateSpace;
54
using NPCoordinateSpace;
54
using mozilla::plugins::NativeWindowHandle;
55
using mozilla::plugins::NativeWindowHandle;
55
56
 Lines 71-90   child: Link Here 
71
  rpc NPP_SetWindow(NPRemoteWindow window);
72
  rpc NPP_SetWindow(NPRemoteWindow window);
72
73
73
  // this message is not used on non-X platforms
74
  // this message is not used on non-X platforms
74
  rpc NPP_GetValue_NPPVpluginNeedsXEmbed()
75
  rpc NPP_GetValue_NPPVpluginNeedsXEmbed()
75
    returns (bool value, NPError result);
76
    returns (bool value, NPError result);
77
  rpc NPP_GetValue_NPPVpluginWindowlessLocalBool()
78
    returns (bool value, NPError result);
76
  rpc NPP_GetValue_NPPVpluginScriptableNPObject()
79
  rpc NPP_GetValue_NPPVpluginScriptableNPObject()
77
    returns (nullable PPluginScriptableObject value, NPError result);
80
    returns (nullable PPluginScriptableObject value, NPError result);
78
81
79
  rpc NPP_SetValue_NPNVprivateModeBool(bool value) returns (NPError result);
82
  rpc NPP_SetValue_NPNVprivateModeBool(bool value) returns (NPError result);
80
83
81
  rpc NPP_HandleEvent(NPRemoteEvent event)
84
  rpc NPP_HandleEvent(NPRemoteEvent event)
82
    returns (int16_t handled);
85
    returns (int16_t handled);
83
  // special cases where we need to a shared memory buffer
86
  // special cases where we need to a shared memory buffer
84
  rpc NPP_HandleEvent_Shmem(NPRemoteEvent event, Shmem buffer)
87
  rpc NPP_HandleEvent_Shmem(NPRemoteEvent event, Shmem buffer)
85
    returns (int16_t handled, Shmem rtnbuffer);
88
    returns (int16_t handled, Shmem rtnbuffer);
89
  // special cases where we need to a shared memory buffer maemo
90
  rpc NPP_HandleEvent_ShmemDirect(NPRemoteMemEvent eventMem, Shmem buffer)
91
    returns (int16_t handled, Shmem rtnbuffer);
86
  // special cases of HandleEvent to make mediating races simpler
92
  // special cases of HandleEvent to make mediating races simpler
87
  rpc Paint(NPRemoteEvent event)
93
  rpc Paint(NPRemoteEvent event)
88
    returns (int16_t handled);
94
    returns (int16_t handled);
89
  // this is only used on windows to forward WM_WINDOWPOSCHANGE
95
  // this is only used on windows to forward WM_WINDOWPOSCHANGE
90
  async WindowPosChanged(NPRemoteEvent event);
96
  async WindowPosChanged(NPRemoteEvent event);
(-)a/dom/plugins/PluginInstanceChild.cpp (+71 lines)
Line     Link Here 
 Lines 449-458   PluginInstanceChild::AnswerNPP_GetValue_ Link Here 
449
449
450
#endif
450
#endif
451
}
451
}
452
452
453
bool
453
bool
454
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginWindowlessLocalBool(
455
    bool* needs, NPError* rv)
456
{
457
    AssertPluginThread();
458
459
    PRBool winlessLocal = 0;
460
    if (!mPluginIface->getvalue) {
461
        *rv = NPERR_GENERIC_ERROR;
462
    }
463
    else {
464
        *rv = mPluginIface->getvalue(GetNPP(), NPPVpluginWindowlessLocalBool,
465
                                     &winlessLocal);
466
    }
467
    *needs = winlessLocal;
468
    return true;
469
}
470
471
bool
454
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
472
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
455
                                          PPluginScriptableObjectChild** aValue,
473
                                          PPluginScriptableObjectChild** aValue,
456
                                          NPError* aResult)
474
                                          NPError* aResult)
457
{
475
{
458
    AssertPluginThread();
476
    AssertPluginThread();
 Lines 628-637   PluginInstanceChild::AnswerNPP_HandleEve Link Here 
628
    *rtnmem = mem;
646
    *rtnmem = mem;
629
    return true;
647
    return true;
630
}
648
}
631
#endif
649
#endif
632
650
651
#ifdef MOZ_PLATFORM_MAEMO
652
bool
653
PluginInstanceChild::AnswerNPP_HandleEvent_ShmemDirect(const NPRemoteMemEvent& eventMem,
654
                                                       Shmem& mem,
655
                                                       int16_t* handled,
656
                                                       Shmem* rtnmem)
657
{
658
    PLUGIN_LOG_DEBUG_FUNCTION;
659
    AssertPluginThread();
660
661
    NPImageExpose imageExpose = eventMem.event;
662
    imageExpose.data = (char*)mem.get<char>();
663
664
    // Wrap NPImageExpose due to missing HandlePaintEvent(NPImageExpose*) NPAPI
665
    NPEvent xEvent;
666
    XGraphicsExposeEvent& exposeEvent = xEvent.xgraphicsexpose;
667
    exposeEvent.drawable = (Drawable)&imageExpose;
668
    exposeEvent.display = 0;
669
    exposeEvent.type = GraphicsExpose;
670
    exposeEvent.x = imageExpose.x;
671
    exposeEvent.y = imageExpose.y;
672
    exposeEvent.width = imageExpose.width;
673
    exposeEvent.height = imageExpose.height;
674
    exposeEvent.count = 0;
675
    // information not set:
676
    exposeEvent.serial = 0;
677
    exposeEvent.send_event = False;
678
    exposeEvent.major_code = 0;
679
    exposeEvent.minor_code = 0;
680
681
    if (!mPluginIface->event) {
682
        *handled = false;
683
    } else {
684
        *handled = mPluginIface->event(&mData, reinterpret_cast<void*>(&xEvent));
685
    }
686
687
    *rtnmem = mem;
688
    return true;
689
}
690
#else
691
bool
692
PluginInstanceChild::AnswerNPP_HandleEvent_ShmemDirect(const NPRemoteMemEvent& event,
693
                                                       Shmem& mem,
694
                                                       int16_t* handled,
695
                                                       Shmem* rtnmem)
696
{
697
    NS_RUNTIMEABORT("not reached.");
698
    *rtnmem = mem;
699
    return true;
700
}
701
702
#endif
703
633
bool
704
bool
634
PluginInstanceChild::RecvWindowPosChanged(const NPRemoteEvent& event)
705
PluginInstanceChild::RecvWindowPosChanged(const NPRemoteEvent& event)
635
{
706
{
636
#ifdef OS_WIN
707
#ifdef OS_WIN
637
    int16_t dontcare;
708
    int16_t dontcare;
(-)a/dom/plugins/PluginInstanceChild.h (+7 lines)
Line     Link Here 
 Lines 77-86   class PluginInstanceChild : public PPlug Link Here 
77
protected:
77
protected:
78
    virtual bool AnswerNPP_SetWindow(const NPRemoteWindow& window);
78
    virtual bool AnswerNPP_SetWindow(const NPRemoteWindow& window);
79
79
80
    virtual bool
80
    virtual bool
81
    AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(bool* needs, NPError* rv);
81
    AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(bool* needs, NPError* rv);
82
83
    virtual bool
84
    AnswerNPP_GetValue_NPPVpluginWindowlessLocalBool(bool* needs, NPError* rv);
85
82
    virtual bool
86
    virtual bool
83
    AnswerNPP_GetValue_NPPVpluginScriptableNPObject(PPluginScriptableObjectChild** value,
87
    AnswerNPP_GetValue_NPPVpluginScriptableNPObject(PPluginScriptableObjectChild** value,
84
                                                    NPError* result);
88
                                                    NPError* result);
85
89
86
    virtual bool
90
    virtual bool
 Lines 88-97   protected: Link Here 
88
92
89
    virtual bool
93
    virtual bool
90
    AnswerNPP_HandleEvent(const NPRemoteEvent& event, int16_t* handled);
94
    AnswerNPP_HandleEvent(const NPRemoteEvent& event, int16_t* handled);
91
    virtual bool
95
    virtual bool
92
    AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event, Shmem& mem, int16_t* handled, Shmem* rtnmem);
96
    AnswerNPP_HandleEvent_Shmem(const NPRemoteEvent& event, Shmem& mem, int16_t* handled, Shmem* rtnmem);
97
    virtual bool
98
    AnswerNPP_HandleEvent_ShmemDirect(const NPRemoteMemEvent& eventMem, Shmem& mem,
99
                                      int16_t* handled, Shmem* rtnmem);
93
100
94
    NS_OVERRIDE
101
    NS_OVERRIDE
95
    virtual bool
102
    virtual bool
96
    AnswerPaint(const NPRemoteEvent& event, int16_t* handled)
103
    AnswerPaint(const NPRemoteEvent& event, int16_t* handled)
97
    {
104
    {
(-)a/dom/plugins/PluginInstanceParent.cpp (-12 / +106 lines)
Line     Link Here 
 Lines 43-52    Link Here 
43
#include "PluginModuleParent.h"
43
#include "PluginModuleParent.h"
44
#include "PluginStreamParent.h"
44
#include "PluginStreamParent.h"
45
#include "StreamNotifyParent.h"
45
#include "StreamNotifyParent.h"
46
#include "npfunctions.h"
46
#include "npfunctions.h"
47
#include "nsAutoPtr.h"
47
#include "nsAutoPtr.h"
48
#include "gfxContext.h"
49
#include "gfxImageSurface.h"
48
50
49
#if defined(OS_WIN)
51
#if defined(OS_WIN)
50
#include <windowsx.h>
52
#include <windowsx.h>
51
53
52
// Plugin focus event for widget.
54
// Plugin focus event for widget.
 Lines 75-87   PluginInstanceParent::PluginInstancePare Link Here 
75
#if defined(OS_WIN)
77
#if defined(OS_WIN)
76
    , mPluginHWND(NULL)
78
    , mPluginHWND(NULL)
77
    , mPluginWndProc(NULL)
79
    , mPluginWndProc(NULL)
78
    , mNestedEventState(false)
80
    , mNestedEventState(false)
79
#endif // defined(XP_WIN)
81
#endif // defined(XP_WIN)
80
#if defined(XP_MACOSX)
82
#if defined(XP_MACOSX) || (MOZ_PLATFORM_MAEMO == 6)
81
    , mShWidth(0)
83
    , mShWidth(0)
82
    , mShHeight(0)
84
    , mShHeight(0)
85
    , mShBpx(0)
83
#endif
86
#endif
84
{
87
{
85
}
88
}
86
89
87
PluginInstanceParent::~PluginInstanceParent()
90
PluginInstanceParent::~PluginInstanceParent()
 Lines 468-498   PluginInstanceParent::NPP_SetWindow(cons Link Here 
468
    window.height = aWindow->height;
471
    window.height = aWindow->height;
469
    window.clipRect = aWindow->clipRect; // MacOS specific
472
    window.clipRect = aWindow->clipRect; // MacOS specific
470
    window.type = aWindow->type;
473
    window.type = aWindow->type;
471
#endif
474
#endif
472
475
473
#if defined(XP_MACOSX)
476
    int bpx = 4;
474
    if (mShWidth * mShHeight != window.width * window.height) {
477
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
478
    const NPSetWindowCallbackStruct* ws_info =
479
      static_cast<NPSetWindowCallbackStruct*>(aWindow->ws_info);
480
    window.visualID = ws_info->visual ? ws_info->visual->visualid : None;
481
    window.colormap = ws_info->colormap;
482
    bpx = ws_info->depth == 16 ? 2 : 4;
483
#endif
484
485
#if defined(XP_MACOSX) || defined(MOZ_PLATFORM_MAEMO)
486
    if (mShWidth * mShHeight != window.width * window.height || mShBpx != bpx) {
475
        // XXX: benwa: OMG MEMORY LEAK! 
487
        // XXX: benwa: OMG MEMORY LEAK! 
476
        //      There is currently no way dealloc the shmem
488
        //      There is currently no way dealloc the shmem
477
        //      so for now we will leak the memory and will fix this ASAP!
489
        //      so for now we will leak the memory and will fix this ASAP!
478
        if (!AllocShmem(window.width * window.height * 4, &mShSurface)) {
490
        if (!AllocShmem(window.width * window.height * bpx, &mShSurface)) {
479
            PLUGIN_LOG_DEBUG(("Shared memory could not be allocated."));
491
            PLUGIN_LOG_DEBUG(("Shared memory could not be allocated."));
480
            return NPERR_GENERIC_ERROR;
492
            return NPERR_GENERIC_ERROR;
481
        }
493
        }
482
        mShWidth = window.width;
494
        mShWidth = window.width;
483
        mShHeight = window.height;
495
        mShHeight = window.height;
496
        mShBpx = bpx;
484
    }
497
    }
485
#endif
498
#endif
486
499
487
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
488
    const NPSetWindowCallbackStruct* ws_info =
489
      static_cast<NPSetWindowCallbackStruct*>(aWindow->ws_info);
490
    window.visualID = ws_info->visual ? ws_info->visual->visualid : None;
491
    window.colormap = ws_info->colormap;
492
#endif
493
494
    if (!CallNPP_SetWindow(window))
500
    if (!CallNPP_SetWindow(window))
495
        return NPERR_GENERIC_ERROR;
501
        return NPERR_GENERIC_ERROR;
496
502
497
    return NPERR_NO_ERROR;
503
    return NPERR_NO_ERROR;
498
}
504
}
 Lines 517-526   PluginInstanceParent::NPP_GetValue(NPPVa Link Here 
517
        }
523
        }
518
524
519
        (*(NPBool*)_retval) = needsXEmbed;
525
        (*(NPBool*)_retval) = needsXEmbed;
520
        return NPERR_NO_ERROR;
526
        return NPERR_NO_ERROR;
521
    }
527
    }
528
529
    case NPPVpluginWindowlessLocalBool: {
530
        bool winlessLocal;
531
        NPError rv;
532
533
        if (!CallNPP_GetValue_NPPVpluginWindowlessLocalBool(&winlessLocal, &rv)) {
534
            return NPERR_GENERIC_ERROR;
535
        }
536
537
        if (NPERR_NO_ERROR != rv) {
538
            return rv;
539
        }
540
541
        (*(NPBool*)_retval) = winlessLocal;
542
        return NPERR_NO_ERROR;
543
    }
544
522
#endif
545
#endif
523
546
524
    case NPPVpluginScriptableNPObject: {
547
    case NPPVpluginScriptableNPObject: {
525
        PPluginScriptableObjectParent* actor;
548
        PPluginScriptableObjectParent* actor;
526
        NPError rv;
549
        NPError rv;
 Lines 637-647   PluginInstanceParent::NPP_HandleEvent(vo Link Here 
637
            break;
660
            break;
638
        }
661
        }
639
    }
662
    }
640
#endif
663
#endif
641
664
642
#if defined(MOZ_X11)
665
#if defined(MOZ_PLATFORM_MAEMO)
666
    if (npevent->type == GraphicsExpose && !npevent->xgraphicsexpose.display) {
667
        XGraphicsExposeEvent& exposeEvent = npevent->xgraphicsexpose;
668
669
        if (mShWidth == 0 && mShHeight == 0 && mShBpx == 0) {
670
            PLUGIN_LOG_DEBUG(("NPHandleEvent Expose on window of size 0."));
671
            return false;
672
        }
673
674
        if (!mShSurface.IsReadable()) {
675
            PLUGIN_LOG_DEBUG(("Shmem is not readable."));
676
            return false;
677
        }
678
679
        NPRemoteMemEvent npremotememevent;
680
        // Take NPImageExpose structure from hacked XEvent drawable
681
        NPImageExpose *imgExp = (NPImageExpose*)npevent->xgraphicsexpose.drawable;
682
683
        // Prepare remote NPImageExpose event for temporary shm buffer
684
        npremotememevent.event = *imgExp;
685
        // We should provide option for plugins to render directly into
686
        //   target context (imgExp->data)
687
        // But for now we will render into temporary buffer
688
        npremotememevent.event.stride = mShWidth * mShBpx;
689
        npremotememevent.event.dataSize.width = mShWidth;
690
        npremotememevent.event.dataSize.height = mShHeight;
691
        npremotememevent.event.translateX = 0;
692
        npremotememevent.event.translateY = 0;
693
        npremotememevent.event.scaleX = 1;
694
        npremotememevent.event.scaleY = 1;
695
696
        if (!CallNPP_HandleEvent_ShmemDirect(npremotememevent, mShSurface, &handled, &mShSurface)) {
697
            return false; // no good way to handle errors here...
698
        }
699
700
        if (!mShSurface.IsReadable()) {
701
            PLUGIN_LOG_DEBUG(("Shmem not returned. Either the plugin crashed or we have a bug."));
702
            return false;
703
        }
704
705
        // Init Image Format
706
        gfxASurface::gfxImageFormat imageFormat = gfxASurface::ImageFormatRGB24;
707
        if (imgExp->depth == 16) imageFormat = gfxASurface::ImageFormatRGB16;
708
        if (imgExp->depth == 32) imageFormat = gfxASurface::ImageFormatARGB32;
709
        // Get target gfx Context
710
        nsRefPtr<gfxImageSurface> surface =
711
           new gfxImageSurface((unsigned char*)imgExp->data,
712
                               gfxIntSize(imgExp->dataSize.width,
713
                                          imgExp->dataSize.height),
714
                               imgExp->stride,
715
                               imageFormat);
716
        nsRefPtr<gfxContext> ctx = new gfxContext(surface);
717
718
        // Get temp shm buffer image surface context
719
        nsRefPtr<gfxImageSurface> buffer =
720
           new gfxImageSurface((unsigned char*)mShSurface.get<unsigned char>(),
721
                               gfxIntSize(mShWidth, mShHeight),
722
                               mShWidth * mShBpx,
723
                               imageFormat);
724
        // Paint shm buffer to target surface
725
        ctx->Translate(gfxPoint(imgExp->translateX, imgExp->translateY));
726
        ctx->Scale(imgExp->scaleX, imgExp->scaleY);
727
        ctx->SetSource(buffer);
728
        ctx->Rectangle(gfxRect(imgExp->x, imgExp->y, imgExp->width, imgExp->height));
729
        ctx->Clip();
730
        ctx->Paint();
731
732
        return handled;
733
    }
734
#endif
735
736
#ifdef MOZ_X11
643
    switch (npevent->type) {
737
    switch (npevent->type) {
644
    case GraphicsExpose:
738
    case GraphicsExpose:
645
        PLUGIN_LOG_DEBUG(("  schlepping drawable 0x%lx across the pipe\n",
739
        PLUGIN_LOG_DEBUG(("  schlepping drawable 0x%lx across the pipe\n",
646
                          npevent->xgraphicsexpose.drawable));
740
                          npevent->xgraphicsexpose.drawable));
647
        // Make sure the X server has created the Drawable and completes any
741
        // Make sure the X server has created the Drawable and completes any
(-)a/dom/plugins/PluginInstanceParent.h (-2 / +3 lines)
Line     Link Here 
 Lines 278-293   private: Link Here 
278
    nsIntRect          mSharedSize;
278
    nsIntRect          mSharedSize;
279
    HWND               mPluginHWND;
279
    HWND               mPluginHWND;
280
    WNDPROC            mPluginWndProc;
280
    WNDPROC            mPluginWndProc;
281
    bool               mNestedEventState;
281
    bool               mNestedEventState;
282
#endif // defined(XP_WIN)
282
#endif // defined(XP_WIN)
283
#if defined(OS_MACOSX)
283
#if defined(OS_MACOSX) || defined(MOZ_PLATFORM_MAEMO)
284
private:
284
private:
285
    Shmem mShSurface; 
285
    Shmem mShSurface; 
286
    size_t mShWidth;
286
    size_t mShWidth;
287
    size_t mShHeight;
287
    size_t mShHeight;
288
#endif // definied(OS_MACOSX)
288
    int mShBpx;
289
#endif // definied(OS_MACOSX) || defined(MOZ_PLATFORM_MAEMO)
289
};
290
};
290
291
291
292
292
} // namespace plugins
293
} // namespace plugins
293
} // namespace mozilla
294
} // namespace mozilla
(-)a/dom/plugins/PluginMessageUtils.h (+3 lines)
Line     Link Here 
 Lines 162-171   NPPVariableToString(NPPVariable aVar) Link Here 
162
#ifdef XP_MACOSX
162
#ifdef XP_MACOSX
163
        VARSTR(NPPVpluginDrawingModel);
163
        VARSTR(NPPVpluginDrawingModel);
164
        VARSTR(NPPVpluginEventModel);
164
        VARSTR(NPPVpluginEventModel);
165
#endif
165
#endif
166
166
167
        VARSTR(NPPVpluginWindowlessLocalBool);
168
167
    default: return "???";
169
    default: return "???";
168
    }
170
    }
169
}
171
}
170
172
171
inline const char*
173
inline const char*
 Lines 712-721   struct ParamTraits<NPCoordinateSpace> Link Here 
712
// intricate depending on the platform.  So for readability we split it
714
// intricate depending on the platform.  So for readability we split it
713
// into separate files and have the only macro crud live here.
715
// into separate files and have the only macro crud live here.
714
// 
716
// 
715
// NB: these guards are based on those where struct NPEvent is defined
717
// NB: these guards are based on those where struct NPEvent is defined
716
// in npapi.h.  They should be kept in sync.
718
// in npapi.h.  They should be kept in sync.
719
#  include "mozilla/plugins/NPEventMem.h"
717
#if defined(XP_MACOSX)
720
#if defined(XP_MACOSX)
718
#  include "mozilla/plugins/NPEventOSX.h"
721
#  include "mozilla/plugins/NPEventOSX.h"
719
#elif defined(XP_WIN)
722
#elif defined(XP_WIN)
720
#  include "mozilla/plugins/NPEventWindows.h"
723
#  include "mozilla/plugins/NPEventWindows.h"
721
#elif defined(XP_OS2)
724
#elif defined(XP_OS2)
(-)a/layout/generic/nsObjectFrame.cpp (+136 lines)
Line     Link Here 
 Lines 540-549   private: Link Here 
540
  void ReleaseXShm();
540
  void ReleaseXShm();
541
  void NativeImageDraw(NPRect* invalidRect = nsnull);
541
  void NativeImageDraw(NPRect* invalidRect = nsnull);
542
  PRBool UpdateVisibility(PRBool aVisible);
542
  PRBool UpdateVisibility(PRBool aVisible);
543
543
544
#endif
544
#endif
545
546
#ifdef MOZ_PLATFORM_MAEMO
547
  nsresult NativeDrawMemBuff(gfxContext *aContext,
548
                             NPWindow* mWindow,
549
                             const nsIntSize& mPluginSize,
550
                             const nsIntRect& mDirtyRect);
551
#endif
545
};
552
};
546
553
547
  // Mac specific code to fix up port position and clip
554
  // Mac specific code to fix up port position and clip
548
#ifdef XP_MACOSX
555
#ifdef XP_MACOSX
549
556
 Lines 5063-5072   void nsPluginInstanceOwner::Paint(gfxCon Link Here 
5063
5070
5064
  // Renderer::Draw() draws a rectangle with top-left at the aContext origin.
5071
  // Renderer::Draw() draws a rectangle with top-left at the aContext origin.
5065
  gfxContextAutoSaveRestore autoSR(aContext);
5072
  gfxContextAutoSaveRestore autoSR(aContext);
5066
  aContext->Translate(pluginRect.pos);
5073
  aContext->Translate(pluginRect.pos);
5067
5074
5075
#ifdef MOZ_PLATFORM_MAEMO
5076
  PRBool simpleImageRender = PR_FALSE;
5077
  mInstance->GetValueFromPlugin(NPPVpluginWindowlessLocalBool,
5078
                                &simpleImageRender);
5079
  if (simpleImageRender &&
5080
      aContext->OriginalSurface()->GetType() == gfxASurface::SurfaceTypeImage) {
5081
    NativeDrawMemBuff(aContext, window, pluginSize, pluginDirtyRect);
5082
    return;
5083
  }
5084
#endif
5085
5068
  Renderer renderer(window, mInstance, pluginSize, pluginDirtyRect);
5086
  Renderer renderer(window, mInstance, pluginSize, pluginDirtyRect);
5069
  renderer.Draw(aContext, window->width, window->height,
5087
  renderer.Draw(aContext, window->width, window->height,
5070
                rendererFlags, nsnull);
5088
                rendererFlags, nsnull);
5071
}
5089
}
5072
5090
 Lines 5365-5374   nsPluginInstanceOwner::NativeImageDraw(N Link Here 
5365
  XFlush(gdk_x11_get_default_xdisplay());
5383
  XFlush(gdk_x11_get_default_xdisplay());
5366
  return;
5384
  return;
5367
}
5385
}
5368
#endif
5386
#endif
5369
5387
5388
#ifdef MOZ_PLATFORM_MAEMO
5389
// NativeDrawMemBuff
5390
nsresult
5391
nsPluginInstanceOwner::NativeDrawMemBuff(gfxContext *aContext,
5392
                                         NPWindow* mWindow,
5393
                                         const nsIntSize& mPluginSize,
5394
                                         const nsIntRect& mDirtyRect)
5395
{
5396
  PRBool doupdatewindow = PR_FALSE;
5397
5398
  if (mWindow->x || mWindow->y) {
5399
    mWindow->x = 0;
5400
    mWindow->y = 0;
5401
    doupdatewindow = PR_TRUE;
5402
  }
5403
5404
  if (nsIntSize(mWindow->width, mWindow->height) != mPluginSize) {
5405
    mWindow->width = mPluginSize.width;
5406
    mWindow->height = mPluginSize.height;
5407
    doupdatewindow = PR_TRUE;
5408
  }
5409
5410
  // The clip rect is relative to drawable top-left.
5411
  nsIntRect clipRect;
5412
  clipRect.x = 0;
5413
  clipRect.y = 0;
5414
  clipRect.width  = mWindow->width;
5415
  clipRect.height = mWindow->height;
5416
5417
  NPRect newClipRect;
5418
  newClipRect.left = clipRect.x;
5419
  newClipRect.top = clipRect.y;
5420
  newClipRect.right = clipRect.XMost();
5421
  newClipRect.bottom = clipRect.YMost();
5422
  if (mWindow->clipRect.left    != newClipRect.left   ||
5423
      mWindow->clipRect.top     != newClipRect.top    ||
5424
      mWindow->clipRect.right   != newClipRect.right  ||
5425
      mWindow->clipRect.bottom  != newClipRect.bottom) {
5426
    mWindow->clipRect = newClipRect;
5427
    doupdatewindow = PR_TRUE;
5428
  }
5429
5430
  nsRefPtr<gfxImageSurface> surface = static_cast<gfxImageSurface*>(aContext->OriginalSurface());
5431
  NS_ENSURE_TRUE(surface, NS_ERROR_OUT_OF_MEMORY);
5432
5433
  PRUint32 surfaceDepth = 24;
5434
  if (surface->Format() == gfxASurface::ImageFormatRGB16)
5435
    surfaceDepth = 16;
5436
  if (surface->Format() == gfxASurface::ImageFormatARGB32)
5437
    surfaceDepth = 32;
5438
5439
  NPSetWindowCallbackStruct* ws_info =
5440
    static_cast<NPSetWindowCallbackStruct*>(mWindow->ws_info);
5441
  ws_info->visual = 0;
5442
  ws_info->colormap = 0;
5443
  if (ws_info->depth != surfaceDepth) {
5444
    ws_info->depth = surfaceDepth;
5445
    doupdatewindow = PR_TRUE;
5446
  }
5447
5448
  if (doupdatewindow)
5449
    mInstance->SetWindow(mWindow);
5450
5451
  // Until we don't have agreement about how to pass NPImageExpose structure to plugin
5452
  // it will be packed into XEvent.xgraphicsexpose.drawable member
5453
  // Probably we have to use something like HandleEvent2 API. see bug 477456 in BMO
5454
  // Translate the dirty rect to drawable coordinates.
5455
  nsIntRect dirtyRect = mDirtyRect;
5456
  // Intersect the dirty rect with the clip rect to ensure that it lies within
5457
  // the drawable.
5458
  if (!dirtyRect.IntersectRect(dirtyRect, clipRect))
5459
    return NS_OK;
5460
5461
  NPEvent pluginEvent;
5462
  NPImageExpose imageExpose;
5463
  XGraphicsExposeEvent& exposeEvent = pluginEvent.xgraphicsexpose;
5464
  // set the drawing info
5465
  exposeEvent.type = GraphicsExpose;
5466
  exposeEvent.display = 0;
5467
  // Store imageExpose structure pointer as drawable member
5468
  exposeEvent.drawable = (Drawable)&imageExpose;
5469
  exposeEvent.x = mDirtyRect.x;
5470
  exposeEvent.y = mDirtyRect.y;
5471
  exposeEvent.width = mDirtyRect.width;
5472
  exposeEvent.height = mDirtyRect.height;
5473
  exposeEvent.count = 0;
5474
  // information not set:
5475
  exposeEvent.serial = 0;
5476
  exposeEvent.send_event = False;
5477
  exposeEvent.major_code = 0;
5478
  exposeEvent.minor_code = 0;
5479
5480
  // Calculate src buffer pointer according to translation
5481
  // and set it as drawable member
5482
  gfxMatrix matr = aContext->CurrentMatrix();
5483
  gfxPoint pt = matr.GetTranslation();
5484
  imageExpose.depth = surfaceDepth;
5485
  imageExpose.x = mDirtyRect.x;
5486
  imageExpose.y = mDirtyRect.y;
5487
  imageExpose.width = mDirtyRect.width;
5488
  imageExpose.height = mDirtyRect.height;
5489
  // Setup temporary context scaled size
5490
  imageExpose.stride = surface->Stride();
5491
  imageExpose.data = (char *)surface->Data();
5492
  imageExpose.dataSize.width = surface->Width();
5493
  imageExpose.dataSize.height = surface->Height();
5494
  imageExpose.translateX = pt.x;
5495
  imageExpose.translateY = pt.y;
5496
  imageExpose.scaleX = matr.xx;
5497
  imageExpose.scaleY = matr.yy;
5498
  PRBool eventHandled = PR_FALSE;
5499
  // Get Image surface from original context
5500
  // Draw plugin content to temp surface
5501
  mInstance->HandleEvent(&pluginEvent, &eventHandled);
5502
  return NS_OK;
5503
}
5504
#endif
5505
5370
#if defined(MOZ_WIDGET_GTK2)
5506
#if defined(MOZ_WIDGET_GTK2)
5371
nsresult
5507
nsresult
5372
nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable, 
5508
nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable, 
5373
                                            short offsetX, short offsetY,
5509
                                            short offsetX, short offsetY,
5374
                                            GdkRectangle * clipRects, 
5510
                                            GdkRectangle * clipRects, 
(-)a/modules/plugin/base/public/npapi.h (-1 / +1 lines)
Line     Link Here 
 Lines 339-349   typedef enum { Link Here 
339
  , NPPVpluginEventModel = 1001
339
  , NPPVpluginEventModel = 1001
340
  /* In the NPDrawingModelCoreAnimation drawing model, the browser asks the plug-in for a Core Animation layer. */
340
  /* In the NPDrawingModelCoreAnimation drawing model, the browser asks the plug-in for a Core Animation layer. */
341
  , NPPVpluginCoreAnimationLayer = 1003
341
  , NPPVpluginCoreAnimationLayer = 1003
342
#endif
342
#endif
343
343
344
#if (MOZ_PLATFORM_MAEMO == 5)
344
#if defined(MOZ_PLATFORM_MAEMO)
345
  , NPPVpluginWindowlessLocalBool = 2002
345
  , NPPVpluginWindowlessLocalBool = 2002
346
#endif
346
#endif
347
} NPPVariable;
347
} NPPVariable;
348
348
349
/*
349
/*

Return to bug 554270