OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "base/scoped_ptr.h" | 41 #include "base/scoped_ptr.h" |
42 | 42 |
43 #import <Cocoa/Cocoa.h> | 43 #import <Cocoa/Cocoa.h> |
44 #include <Carbon/Carbon.h> | 44 #include <Carbon/Carbon.h> |
45 #include <OpenGL/OpenGL.h> | 45 #include <OpenGL/OpenGL.h> |
46 #include <AGL/agl.h> | 46 #include <AGL/agl.h> |
47 #include <AGL/aglRenderers.h> | 47 #include <AGL/aglRenderers.h> |
48 | 48 |
49 #include "core/cross/event.h" | 49 #include "core/cross/event.h" |
50 #include "statsreport/metrics.h" | 50 #include "statsreport/metrics.h" |
| 51 #include "plugin/cross/config.h" |
51 #include "plugin/cross/plugin_logging.h" | 52 #include "plugin/cross/plugin_logging.h" |
52 #include "plugin/cross/plugin_metrics.h" | 53 #include "plugin/cross/plugin_metrics.h" |
53 #include "plugin/cross/o3d_glue.h" | 54 #include "plugin/cross/o3d_glue.h" |
54 #include "plugin/cross/out_of_memory.h" | 55 #include "plugin/cross/out_of_memory.h" |
55 #include "plugin/cross/whitelist.h" | 56 #include "plugin/cross/whitelist.h" |
56 #include "plugin/mac/plugin_mac.h" | 57 #include "plugin/mac/plugin_mac.h" |
57 #include "plugin/mac/graphics_utils_mac.h" | 58 #include "plugin/mac/graphics_utils_mac.h" |
| 59 #import "plugin/mac/o3d_layer.h" |
| 60 |
58 | 61 |
59 #if !defined(O3D_INTERNAL_PLUGIN) | 62 #if !defined(O3D_INTERNAL_PLUGIN) |
60 o3d::PluginLogging* g_logger = NULL; | 63 o3d::PluginLogging* g_logger = NULL; |
61 bool g_logging_initialized = false; | 64 bool g_logging_initialized = false; |
62 #endif | 65 #endif |
63 | 66 |
64 using glue::_o3d::PluginObject; | 67 using glue::_o3d::PluginObject; |
65 using glue::StreamManager; | 68 using glue::StreamManager; |
66 using o3d::Bitmap; | 69 using o3d::Bitmap; |
67 using o3d::DisplayWindowMac; | 70 using o3d::DisplayWindowMac; |
68 using o3d::Event; | 71 using o3d::Event; |
69 using o3d::Renderer; | 72 using o3d::Renderer; |
70 | 73 |
71 namespace { | 74 namespace { |
72 // We would normally make this a stack variable in main(), but in a | 75 // We would normally make this a stack variable in main(), but in a |
73 // plugin, that's not possible, so we make it a global. When the DLL is loaded | 76 // plugin, that's not possible, so we make it a global. When the DLL is loaded |
74 // this it gets constructed and when it is unlooaded it is destructed. Note | 77 // this it gets constructed and when it is unlooaded it is destructed. Note |
75 // that this cannot be done in NP_Initialize and NP_Shutdown because those | 78 // that this cannot be done in NP_Initialize and NP_Shutdown because those |
76 // calls do not necessarily signify the DLL being loaded and unloaded. If the | 79 // calls do not necessarily signify the DLL being loaded and unloaded. If the |
77 // DLL is not unloaded then the values of global variables are preserved. | 80 // DLL is not unloaded then the values of global variables are preserved. |
78 base::AtExitManager g_at_exit_manager; | 81 base::AtExitManager g_at_exit_manager; |
79 | 82 |
80 #define CFTIMER | 83 #define CFTIMER |
81 // #define DEFERRED_DRAW_ON_NULLEVENTS | 84 // #define DEFERRED_DRAW_ON_NULLEVENTS |
82 | 85 |
| 86 |
| 87 // Helper that extracts the O3DLayer obj c object from the PluginObject |
| 88 // and coerces it to the right type. The code can't live in the PluginObject |
| 89 // since it's c++ code and doesn't know about objective c types, and it saves |
| 90 // lots of casts elsewhere in the code. |
| 91 static O3DLayer* ObjO3DLayer(PluginObject* obj) { |
| 92 return static_cast<O3DLayer*>(obj ? obj->gl_layer_ : nil); |
| 93 } |
| 94 |
83 void DrawPlugin(PluginObject* obj, bool send_callback, CGContextRef context) { | 95 void DrawPlugin(PluginObject* obj, bool send_callback, CGContextRef context) { |
84 obj->client()->RenderClient(send_callback); | 96 obj->client()->RenderClient(send_callback); |
85 Renderer* renderer = obj->renderer(); | 97 Renderer* renderer = obj->renderer(); |
86 if (obj->IsOffscreenRenderingEnabled() && renderer && context) { | 98 if (obj->IsOffscreenRenderingEnabled() && renderer && context) { |
87 DCHECK_EQ(obj->drawing_model_, NPDrawingModelCoreGraphics); | 99 DCHECK_EQ(obj->drawing_model_, NPDrawingModelCoreGraphics); |
88 DCHECK(obj->mac_cgl_pbuffer_); | 100 DCHECK(obj->mac_cgl_pbuffer_); |
89 // We need to read back the framebuffer and draw it to the screen using | 101 // We need to read back the framebuffer and draw it to the screen using |
90 // CoreGraphics. | 102 // CoreGraphics. |
91 renderer->StartRendering(); | 103 renderer->StartRendering(); |
92 Bitmap::Ref bitmap = obj->GetOffscreenBitmap(); | 104 Bitmap::Ref bitmap = obj->GetOffscreenBitmap(); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 WindowRef fullscreen_window = obj->GetFullscreenMacWindow(); | 473 WindowRef fullscreen_window = obj->GetFullscreenMacWindow(); |
462 bool handled = false; | 474 bool handled = false; |
463 | 475 |
464 if (g_logger) g_logger->UpdateLogging(); | 476 if (g_logger) g_logger->UpdateLogging(); |
465 | 477 |
466 obj->MacEventReceived(); | 478 obj->MacEventReceived(); |
467 switch (the_event->type) { | 479 switch (the_event->type) { |
468 case NPCocoaEventDrawRect: | 480 case NPCocoaEventDrawRect: |
469 // We need to call the render callback from here if we are rendering | 481 // We need to call the render callback from here if we are rendering |
470 // off-screen because it doesn't get called anywhere else. | 482 // off-screen because it doesn't get called anywhere else. |
471 DrawPlugin(obj, | 483 if (obj->drawing_model_ == NPDrawingModelCoreAnimation) { |
472 obj->IsOffscreenRenderingEnabled(), | 484 O3DLayer* layer = ObjO3DLayer(obj); |
473 the_event->data.draw.context); | 485 if (layer) { |
| 486 [layer setNeedsDisplay]; |
| 487 } |
| 488 } else { |
| 489 DrawPlugin(obj, |
| 490 obj->IsOffscreenRenderingEnabled(), |
| 491 the_event->data.draw.context); |
| 492 } |
474 handled = true; | 493 handled = true; |
475 break; | 494 break; |
476 case NPCocoaEventMouseDown: | 495 case NPCocoaEventMouseDown: |
477 case NPCocoaEventMouseUp: | 496 case NPCocoaEventMouseUp: |
478 case NPCocoaEventMouseMoved: | 497 case NPCocoaEventMouseMoved: |
479 case NPCocoaEventMouseDragged: | 498 case NPCocoaEventMouseDragged: |
480 case NPCocoaEventMouseEntered: | 499 case NPCocoaEventMouseEntered: |
481 case NPCocoaEventMouseExited: | 500 case NPCocoaEventMouseExited: |
482 case NPCocoaEventScrollWheel: | 501 case NPCocoaEventScrollWheel: |
483 HandleCocoaMouseEvent(obj, the_event); | 502 HandleCocoaMouseEvent(obj, the_event); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 logging::APPEND_TO_OLD_LOG_FILE); | 596 logging::APPEND_TO_OLD_LOG_FILE); |
578 | 597 |
579 DLOG(INFO) << "NP_Initialize"; | 598 DLOG(INFO) << "NP_Initialize"; |
580 | 599 |
581 o3d::SetupOutOfMemoryHandler(); | 600 o3d::SetupOutOfMemoryHandler(); |
582 #endif // O3D_INTERNAL_PLUGIN | 601 #endif // O3D_INTERNAL_PLUGIN |
583 | 602 |
584 return NPERR_NO_ERROR; | 603 return NPERR_NO_ERROR; |
585 } | 604 } |
586 | 605 |
| 606 // When to prefer Core Animation, currently that's only on Safari and 10.6+ |
| 607 // but that will change as we use this model in more browsers. |
| 608 static bool PreferCoreAnimation() { |
| 609 bool isSafari = o3d::metric_browser_type.value() == o3d::BROWSER_NAME_SAFARI; |
| 610 return (o3d::IsMacOSTenSixOrHigher() && isSafari); |
| 611 } |
| 612 |
587 // Negotiates the best plugin event model, sets the browser to use that, | 613 // Negotiates the best plugin event model, sets the browser to use that, |
588 // and updates the PluginObject so we can remember which one we chose. | 614 // and updates the PluginObject so we can remember which one we chose. |
589 // We favor the newer Cocoa-based model, but can cope with browsers that | 615 // We favor the newer Cocoa-based model, but can cope with browsers that |
590 // only support the original event model, or indeed can't even understand | 616 // only support the original event model, or indeed can't even understand |
591 // what we are asking for. | 617 // what we are asking for. |
592 // However, right at the minute, we shun the Cocoa event model because its | 618 // However, right at the minute, we shun the Cocoa event model because its |
593 // NPP_SetWindow messages don't contain a WindowRef or NSWindow so we would | 619 // NPP_SetWindow messages don't contain a WindowRef or NSWindow so we would |
594 // not get enough info to create our AGL context. We'll go back to | 620 // not get enough info to create our AGL context. We'll go back to |
595 // preferring Cocoa once we have worked out how to deal with that. | 621 // preferring Cocoa once we have worked out how to deal with that. |
596 // Cannot actually fail - | 622 // Cannot actually fail - |
(...skipping 24 matching lines...) Expand all Loading... |
621 // Now we've collected our data, the decision phase begins. | 647 // Now we've collected our data, the decision phase begins. |
622 | 648 |
623 // If we didn't successfully get TRUE for either question, the browser | 649 // If we didn't successfully get TRUE for either question, the browser |
624 // just does not know about the new switchable event models, so must only | 650 // just does not know about the new switchable event models, so must only |
625 // support the old Carbon event model. | 651 // support the old Carbon event model. |
626 if (!(supportsCocoaEventModel || supportsCarbonEventModel)) { | 652 if (!(supportsCocoaEventModel || supportsCarbonEventModel)) { |
627 supportsCarbonEventModel = TRUE; | 653 supportsCarbonEventModel = TRUE; |
628 obj->event_model_ = NPEventModelCarbon; | 654 obj->event_model_ = NPEventModelCarbon; |
629 } | 655 } |
630 | 656 |
631 // Default to Carbon event model, because the new version of the | 657 |
632 // Cocoa event model spec does not supply sufficient window | 658 if (PreferCoreAnimation()) { |
633 // information in its Cocoa NPP_SetWindow calls for us to bind an | 659 // If we're building for Core Animation then we prefer the Cocoa event |
634 // AGL context to the browser window. | 660 // model. |
635 model_to_use = | 661 model_to_use = |
636 (supportsCarbonEventModel) ? NPEventModelCarbon : NPEventModelCocoa; | 662 (supportsCocoaEventModel) ? NPEventModelCocoa : NPEventModelCarbon; |
637 if (o3d::gIsChrome) { | 663 NPN_SetValue(instance, NPPVpluginEventModel, |
638 if (supportsCocoaEventModel) { | 664 reinterpret_cast<void*>(model_to_use)); |
639 model_to_use = NPEventModelCocoa; | 665 } else { |
| 666 // Default to Carbon event model, because the new version of the |
| 667 // Cocoa event model spec does not supply sufficient window |
| 668 // information in its Cocoa NPP_SetWindow calls for us to bind an |
| 669 // AGL context to the browser window. |
| 670 model_to_use = |
| 671 (supportsCarbonEventModel) ? NPEventModelCarbon : NPEventModelCocoa; |
| 672 if (o3d::gIsChrome) { |
| 673 if (supportsCocoaEventModel) { |
| 674 model_to_use = NPEventModelCocoa; |
| 675 } |
640 } | 676 } |
641 } | 677 } |
642 NPN_SetValue(instance, NPPVpluginEventModel, | 678 NPN_SetValue(instance, NPPVpluginEventModel, |
643 reinterpret_cast<void*>(model_to_use)); | 679 reinterpret_cast<void*>(model_to_use)); |
| 680 |
| 681 |
644 obj->event_model_ = model_to_use; | 682 obj->event_model_ = model_to_use; |
645 } | 683 } |
646 | 684 |
647 | 685 |
648 // Negotiates the best plugin drawing model, sets the browser to use that, | 686 // Negotiates the best plugin drawing model, sets the browser to use that, |
649 // and updates the PluginObject so we can remember which one we chose. | 687 // and updates the PluginObject so we can remember which one we chose. |
650 // Returns NPERR_NO_ERROR (0) if successful, otherwise an NPError code. | 688 // Returns NPERR_NO_ERROR (0) if successful, otherwise an NPError code. |
651 NPError Mac_SetBestDrawingModel(NPP instance, PluginObject* obj) { | 689 NPError Mac_SetBestDrawingModel(NPP instance, PluginObject* obj) { |
652 NPError err = NPERR_NO_ERROR; | 690 NPError err = NPERR_NO_ERROR; |
653 NPBool supportsCoreGraphics = FALSE; | 691 NPBool supportsCoreGraphics = FALSE; |
654 NPBool supportsOpenGL = FALSE; | |
655 NPBool supportsQuickDraw = FALSE; | 692 NPBool supportsQuickDraw = FALSE; |
| 693 NPBool supportsCoreAnimation = FALSE; |
656 NPDrawingModel drawing_model = NPDrawingModelQuickDraw; | 694 NPDrawingModel drawing_model = NPDrawingModelQuickDraw; |
657 | 695 |
658 // test for direct OpenGL support | |
659 err = NPN_GetValue(instance, | |
660 NPNVsupportsOpenGLBool, | |
661 &supportsOpenGL); | |
662 if (err != NPERR_NO_ERROR) | |
663 supportsOpenGL = FALSE; | |
664 | |
665 // test for QuickDraw support | 696 // test for QuickDraw support |
666 err = NPN_GetValue(instance, | 697 err = NPN_GetValue(instance, |
667 NPNVsupportsQuickDrawBool, | 698 NPNVsupportsQuickDrawBool, |
668 &supportsQuickDraw); | 699 &supportsQuickDraw); |
669 if (err != NPERR_NO_ERROR) | 700 if (err != NPERR_NO_ERROR) |
670 supportsQuickDraw = FALSE; | 701 supportsQuickDraw = FALSE; |
671 | 702 |
672 // Test for Core Graphics support | 703 // Test for Core Graphics support |
673 err = NPN_GetValue(instance, | 704 err = NPN_GetValue(instance, |
674 NPNVsupportsCoreGraphicsBool, | 705 NPNVsupportsCoreGraphicsBool, |
675 &supportsCoreGraphics); | 706 &supportsCoreGraphics); |
676 if (err != NPERR_NO_ERROR) | 707 if (err != NPERR_NO_ERROR) |
677 supportsCoreGraphics = FALSE; | 708 supportsCoreGraphics = FALSE; |
678 | 709 |
| 710 err = NPN_GetValue(instance, |
| 711 NPNVsupportsCoreAnimationBool, |
| 712 &supportsCoreAnimation); |
| 713 if (err != NPERR_NO_ERROR) |
| 714 supportsCoreAnimation = FALSE; |
| 715 |
| 716 // In order of preference. Preference is now determined by compatibility, |
| 717 // not by modernity, and so is the opposite of the order I first used. |
| 718 if (supportsQuickDraw && !(obj->event_model_ == NPEventModelCocoa)) { |
| 719 drawing_model = NPDrawingModelQuickDraw; |
| 720 } else if (supportsCoreAnimation && PreferCoreAnimation()) { |
| 721 drawing_model = NPDrawingModelCoreAnimation; |
679 // In the Chrome browser we currently want to prefer the CoreGraphics | 722 // In the Chrome browser we currently want to prefer the CoreGraphics |
680 // drawing model, read back the frame buffer into system memory and draw | 723 // drawing model, read back the frame buffer into system memory and draw |
681 // the results to the screen using CG. | 724 // the results to the screen using CG. |
682 // | 725 // |
683 // TODO(maf): Once support for the CoreAnimation drawing model is | 726 } else if (o3d::gIsChrome && supportsCoreGraphics) { |
684 // integrated into O3D, we will want to revisit this logic. | |
685 if (o3d::gIsChrome && supportsCoreGraphics) { | |
686 drawing_model = NPDrawingModelCoreGraphics; | 727 drawing_model = NPDrawingModelCoreGraphics; |
687 } else { | 728 } else { |
688 // In order of preference. Preference is now determined by compatibility, | 729 if (supportsCoreGraphics) { |
689 // not by modernity, and so is the opposite of the order I first used. | |
690 if (supportsQuickDraw && !(obj->event_model_ == NPEventModelCocoa)) { | |
691 drawing_model = NPDrawingModelQuickDraw; | |
692 } else if (supportsCoreGraphics) { | |
693 drawing_model = NPDrawingModelCoreGraphics; | 730 drawing_model = NPDrawingModelCoreGraphics; |
694 } else if (supportsOpenGL) { | |
695 drawing_model = NPDrawingModelOpenGL; | |
696 } else { | 731 } else { |
697 // This case is for browsers that didn't even understand the question | 732 // This case is for browsers that didn't even understand the question |
698 // eg FF2, so drawing models are not supported, just assume QuickDraw. | 733 // eg FF2, so drawing models are not supported, just assume QuickDraw. |
699 obj->drawing_model_ = NPDrawingModelQuickDraw; | 734 obj->drawing_model_ = NPDrawingModelQuickDraw; |
700 return NPERR_NO_ERROR; | 735 return NPERR_NO_ERROR; |
701 } | 736 } |
702 } | 737 } |
703 | 738 |
704 err = NPN_SetValue(instance, NPPVpluginDrawingModel, | 739 err = NPN_SetValue(instance, NPPVpluginDrawingModel, |
705 reinterpret_cast<void*>(drawing_model)); | 740 reinterpret_cast<void*>(drawing_model)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 807 |
773 o3d::ShutdownBreakpad(); | 808 o3d::ShutdownBreakpad(); |
774 #endif // O3D_INTERNAL_PLUGIN | 809 #endif // O3D_INTERNAL_PLUGIN |
775 | 810 |
776 return NPERR_NO_ERROR; | 811 return NPERR_NO_ERROR; |
777 } | 812 } |
778 | 813 |
779 } // namespace o3d / extern "C" | 814 } // namespace o3d / extern "C" |
780 | 815 |
781 | 816 |
| 817 |
782 namespace o3d { | 818 namespace o3d { |
783 | 819 |
784 NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) { | 820 NPError PlatformNPPGetValue(NPP instance, NPPVariable variable, void *value) { |
| 821 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
| 822 |
| 823 switch (variable) { |
| 824 case NPPVpluginCoreAnimationLayer: |
| 825 if (!ObjO3DLayer(obj)) { |
| 826 // Setup layer |
| 827 O3DLayer* gl_layer = [[[O3DLayer alloc] init] retain]; |
| 828 |
| 829 gl_layer.autoresizingMask = |
| 830 kCALayerWidthSizable + kCALayerHeightSizable; |
| 831 obj->gl_layer_ = gl_layer; |
| 832 |
| 833 [gl_layer setPluginObject:obj]; |
| 834 } |
| 835 // Make sure to return a retained layer |
| 836 *(CALayer**)value = ObjO3DLayer(obj); |
| 837 return NPERR_NO_ERROR; |
| 838 break; |
| 839 default: |
| 840 return NPERR_INVALID_PARAM; |
| 841 } |
| 842 |
785 return NPERR_INVALID_PARAM; | 843 return NPERR_INVALID_PARAM; |
786 } | 844 } |
787 | 845 |
788 bool HandleMacEvent(EventRecord* the_event, NPP instance) { | 846 bool HandleMacEvent(EventRecord* the_event, NPP instance) { |
789 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); | 847 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
790 bool handled = false; | 848 bool handled = false; |
791 WindowRef fullscreen_window = obj->GetFullscreenMacWindow(); | 849 WindowRef fullscreen_window = obj->GetFullscreenMacWindow(); |
792 | 850 |
793 if (g_logger) g_logger->UpdateLogging(); | 851 if (g_logger) g_logger->UpdateLogging(); |
794 | 852 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 } | 934 } |
877 | 935 |
878 NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, | 936 NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, |
879 char* argn[], char* argv[], NPSavedData* saved) { | 937 char* argn[], char* argv[], NPSavedData* saved) { |
880 HANDLE_CRASHES; | 938 HANDLE_CRASHES; |
881 | 939 |
882 NPError err = NPERR_NO_ERROR; | 940 NPError err = NPERR_NO_ERROR; |
883 | 941 |
884 #if !defined(O3D_INTERNAL_PLUGIN) | 942 #if !defined(O3D_INTERNAL_PLUGIN) |
885 if (!g_logging_initialized) { | 943 if (!g_logging_initialized) { |
886 GetUserAgentMetrics(instance); | 944 o3d::GetUserAgentMetrics(instance); |
887 GetUserConfigMetrics(); | 945 GetUserConfigMetrics(); |
888 // Create usage stats logs object | 946 // Create usage stats logs object |
889 g_logger = o3d::PluginLogging::InitializeUsageStatsLogging(); | 947 g_logger = o3d::PluginLogging::InitializeUsageStatsLogging(); |
890 g_logging_initialized = true; | 948 g_logging_initialized = true; |
891 } | 949 } |
892 #endif // O3D_INTERNAL_PLUGIN | 950 #endif // O3D_INTERNAL_PLUGIN |
893 | 951 |
894 if (!IsDomainAuthorized(instance)) { | 952 if (!IsDomainAuthorized(instance)) { |
895 return NPERR_INVALID_URL; | 953 return NPERR_INVALID_URL; |
896 } | 954 } |
897 | 955 |
898 PluginObject* pluginObject = glue::_o3d::PluginObject::Create( | 956 PluginObject* pluginObject = glue::_o3d::PluginObject::Create( |
899 instance); | 957 instance); |
900 instance->pdata = pluginObject; | 958 instance->pdata = pluginObject; |
901 glue::_o3d::InitializeGlue(instance); | 959 glue::_o3d::InitializeGlue(instance); |
902 pluginObject->Init(argc, argn, argv); | 960 pluginObject->Init(argc, argn, argv); |
903 | 961 |
904 Mac_SetBestEventModel(instance, | 962 Mac_SetBestEventModel(instance, |
905 static_cast<PluginObject*>(instance->pdata)); | 963 static_cast<PluginObject*>(instance->pdata)); |
906 | 964 |
907 err = Mac_SetBestDrawingModel( | 965 err = Mac_SetBestDrawingModel( |
908 instance, static_cast<PluginObject*>(instance->pdata)); | 966 instance, static_cast<PluginObject*>(instance->pdata)); |
909 if (err != NPERR_NO_ERROR) | 967 if (err != NPERR_NO_ERROR) |
910 return err; | 968 return err; |
| 969 #ifdef CFTIMER |
| 970 if (pluginObject->drawing_model_ == NPDrawingModelCoreAnimation) { |
| 971 o3d::gRenderTimer.AddInstance(instance); |
| 972 } |
| 973 #endif |
911 return NPERR_NO_ERROR; | 974 return NPERR_NO_ERROR; |
912 } | 975 } |
913 | 976 |
914 NPError NPP_Destroy(NPP instance, NPSavedData** save) { | 977 NPError NPP_Destroy(NPP instance, NPSavedData** save) { |
915 HANDLE_CRASHES; | 978 HANDLE_CRASHES; |
916 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); | 979 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
917 if (obj) { | 980 if (obj) { |
918 #if defined(CFTIMER) | 981 #if defined(CFTIMER) |
919 o3d::gRenderTimer.RemoveInstance(instance); | 982 o3d::gRenderTimer.RemoveInstance(instance); |
920 #endif | 983 #endif |
(...skipping 11 matching lines...) Expand all Loading... |
932 } | 995 } |
933 | 996 |
934 NPError NPP_SetWindow(NPP instance, NPWindow* window) { | 997 NPError NPP_SetWindow(NPP instance, NPWindow* window) { |
935 HANDLE_CRASHES; | 998 HANDLE_CRASHES; |
936 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); | 999 PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
937 WindowRef new_window = NULL; | 1000 WindowRef new_window = NULL; |
938 | 1001 |
939 assert(window != NULL); | 1002 assert(window != NULL); |
940 | 1003 |
941 if (window->window == NULL && | 1004 if (window->window == NULL && |
942 obj->drawing_model_ != NPDrawingModelCoreGraphics) | 1005 obj->drawing_model_ != NPDrawingModelCoreGraphics && |
| 1006 obj->drawing_model_!= NPDrawingModelCoreAnimation) { |
943 return NPERR_NO_ERROR; | 1007 return NPERR_NO_ERROR; |
| 1008 } |
944 | 1009 |
945 obj->last_plugin_loc_.h = window->x; | 1010 obj->last_plugin_loc_.h = window->x; |
946 obj->last_plugin_loc_.v = window->y; | 1011 obj->last_plugin_loc_.v = window->y; |
947 | 1012 |
948 switch (obj->drawing_model_) { | 1013 switch (obj->drawing_model_) { |
949 case NPDrawingModelOpenGL: { | 1014 case NPDrawingModelCoreAnimation: { |
950 NP_GLContext* np_gl = reinterpret_cast<NP_GLContext*>(window->window); | 1015 O3DLayer* o3dLayer = ObjO3DLayer(obj); |
951 if (obj->event_model_ == NPEventModelCocoa) { | 1016 [o3dLayer setWidth: window->width height: window->height]; |
952 NSWindow * ns_window = reinterpret_cast<NSWindow*>(np_gl->window); | 1017 return NPERR_NO_ERROR; |
953 new_window = reinterpret_cast<WindowRef>([ns_window windowRef]); | |
954 } else { | |
955 new_window = np_gl->window; | |
956 } | |
957 obj->mac_2d_context_ = NULL; | |
958 obj->mac_cgl_context_ = np_gl->context; | |
959 break; | |
960 } | 1018 } |
961 case NPDrawingModelCoreGraphics: { | 1019 case NPDrawingModelCoreGraphics: { |
962 // Safari 4 sets window->window to NULL when in Cocoa event mode. | 1020 // Safari 4 sets window->window to NULL when in Cocoa event mode. |
963 if (window->window != NULL) { | 1021 if (window->window != NULL) { |
964 NP_CGContext* np_cg = reinterpret_cast<NP_CGContext*>(window->window); | 1022 NP_CGContext* np_cg = reinterpret_cast<NP_CGContext*>(window->window); |
965 if (obj->event_model_ == NPEventModelCocoa) { | 1023 if (obj->event_model_ == NPEventModelCocoa) { |
966 NSWindow * ns_window = reinterpret_cast<NSWindow*>(np_cg->window); | 1024 NSWindow * ns_window = reinterpret_cast<NSWindow*>(np_cg->window); |
967 new_window = reinterpret_cast<WindowRef>([ns_window windowRef]); | 1025 new_window = reinterpret_cast<WindowRef>([ns_window windowRef]); |
968 } else { | 1026 } else { |
969 new_window = static_cast<OpaqueWindowPtr*>(np_cg->window); | 1027 new_window = static_cast<OpaqueWindowPtr*>(np_cg->window); |
(...skipping 24 matching lines...) Expand all Loading... |
994 bool window_changed = new_window != obj->mac_window_; | 1052 bool window_changed = new_window != obj->mac_window_; |
995 | 1053 |
996 // Whether we already had a window before this call. | 1054 // Whether we already had a window before this call. |
997 bool had_a_window = obj->mac_window_ != NULL; | 1055 bool had_a_window = obj->mac_window_ != NULL; |
998 | 1056 |
999 // Whether we already had a pbuffer before this call. | 1057 // Whether we already had a pbuffer before this call. |
1000 bool had_a_pbuffer = obj->mac_cgl_pbuffer_ != NULL; | 1058 bool had_a_pbuffer = obj->mac_cgl_pbuffer_ != NULL; |
1001 | 1059 |
1002 obj->mac_window_ = new_window; | 1060 obj->mac_window_ = new_window; |
1003 | 1061 |
1004 if (obj->drawing_model_ == NPDrawingModelOpenGL) { | 1062 if (obj->drawing_model_ == NPDrawingModelCoreAnimation) { |
1005 CGLSetCurrentContext(obj->mac_cgl_context_); | 1063 if (obj->mac_cgl_context_) { |
| 1064 CGLSetCurrentContext(obj->mac_cgl_context_); |
| 1065 } |
1006 } else if (obj->drawing_model_ == NPDrawingModelCoreGraphics && | 1066 } else if (obj->drawing_model_ == NPDrawingModelCoreGraphics && |
1007 o3d::gIsChrome && | 1067 o3d::gIsChrome && |
1008 obj->mac_cgl_pbuffer_ == NULL) { | 1068 obj->mac_cgl_pbuffer_ == NULL) { |
1009 // This code path is only taken for Chrome. We initialize things with a | 1069 // This code path is only taken for Chrome. We initialize things with a |
1010 // CGL context rendering to a 1x1 pbuffer. Later we use the O3D | 1070 // CGL context rendering to a 1x1 pbuffer. Later we use the O3D |
1011 // RenderSurface APIs to set up the framebuffer object which is used | 1071 // RenderSurface APIs to set up the framebuffer object which is used |
1012 // for rendering. | 1072 // for rendering. |
1013 static const CGLPixelFormatAttribute attribs[] = { | 1073 static const CGLPixelFormatAttribute attribs[] = { |
1014 (CGLPixelFormatAttribute) kCGLPFAPBuffer, | 1074 (CGLPixelFormatAttribute) kCGLPFAPBuffer, |
1015 (CGLPixelFormatAttribute) 0 | 1075 (CGLPixelFormatAttribute) 0 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 // Renderer is already initialized from a previous call to this function, | 1292 // Renderer is already initialized from a previous call to this function, |
1233 // just update size and position and return. | 1293 // just update size and position and return. |
1234 if (had_a_window) { | 1294 if (had_a_window) { |
1235 if (obj->renderer()) { | 1295 if (obj->renderer()) { |
1236 obj->renderer()->SetClientOriginOffset(gl_x_origin, gl_y_origin); | 1296 obj->renderer()->SetClientOriginOffset(gl_x_origin, gl_y_origin); |
1237 obj->Resize(window->width, window->height); | 1297 obj->Resize(window->width, window->height); |
1238 } | 1298 } |
1239 return NPERR_NO_ERROR; | 1299 return NPERR_NO_ERROR; |
1240 } | 1300 } |
1241 | 1301 |
| 1302 if (obj->renderer()) |
| 1303 return NPERR_NO_ERROR; |
| 1304 |
1242 // Create and assign the graphics context. | 1305 // Create and assign the graphics context. |
1243 o3d::DisplayWindowMac default_display; | 1306 o3d::DisplayWindowMac default_display; |
1244 default_display.set_agl_context(obj->mac_agl_context_); | 1307 default_display.set_agl_context(obj->mac_agl_context_); |
1245 default_display.set_cgl_context(obj->mac_cgl_context_); | 1308 default_display.set_cgl_context(obj->mac_cgl_context_); |
1246 | 1309 |
1247 obj->CreateRenderer(default_display); | 1310 obj->CreateRenderer(default_display); |
1248 | 1311 |
1249 // if the renderer cannot be created (maybe the features are not supported) | 1312 // if the renderer cannot be created (maybe the features are not supported) |
1250 // then we can proceed no further | 1313 // then we can proceed no further |
1251 if (!obj->renderer()) { | 1314 if (!obj->renderer()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 if (obj->event_model_ == NPEventModelCarbon) { | 1364 if (obj->event_model_ == NPEventModelCarbon) { |
1302 EventRecord* theEvent = static_cast<EventRecord*>(event); | 1365 EventRecord* theEvent = static_cast<EventRecord*>(event); |
1303 return HandleMacEvent(theEvent, instance) ? 1 : 0; | 1366 return HandleMacEvent(theEvent, instance) ? 1 : 0; |
1304 } else if (obj->event_model_ == NPEventModelCocoa){ | 1367 } else if (obj->event_model_ == NPEventModelCocoa){ |
1305 return HandleCocoaEvent(instance, (NPCocoaEvent*)event) ? 1 : 0; | 1368 return HandleCocoaEvent(instance, (NPCocoaEvent*)event) ? 1 : 0; |
1306 } | 1369 } |
1307 return 0; | 1370 return 0; |
1308 } | 1371 } |
1309 | 1372 |
1310 } // namespace o3d | 1373 } // namespace o3d |
OLD | NEW |