Library_merged.mk                                                              
              |    6 
 
android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
 |   90 +++++++---
 offapi/com/sun/star/awt/XToolkit2.idl                                          
              |    6 
 sal/inc/sal/ByteBufferWrapper.hxx                                              
              |   23 --
 toolkit/Library_tk.mk                                                          
              |    6 
 toolkit/inc/toolkit/awt/vclxtoolkit.hxx                                        
              |    2 
 toolkit/source/awt/vclxtoolkit.cxx                                             
              |    7 
 touch/Library_libotouch.mk                                                     
              |    4 
 touch/source/android/android.cxx                                               
              |   34 +++
 touch/source/uno/Document.cxx                                                  
              |    2 
 vcl/inc/vcl/virdev.hxx                                                         
              |    2 
 vcl/source/gdi/virdev.cxx                                                      
              |   17 -
 12 files changed, 140 insertions(+), 59 deletions(-)

New commits:
commit daaa550121a97d80e1ab43cbd5c73da6915e4ac4
Author: Tor Lillqvist <tlillqv...@suse.com>
Date:   Mon Jun 18 22:32:35 2012 +0300

    Pass also scale and offset to createScreenCompatibleDeviceUsingBuffer()
    
    Pass on to VirtualDevice where used to set the MapMode of the device
    appropriately. Adapt DocumentLoader, use to scale the page rendering
    to exactly fit the virtual device.
    
    Change-Id: I4b0bc67e12114d3d9d493ff1aca2ef5d2cc78912

diff --git a/Library_merged.mk b/Library_merged.mk
index d689e42..49c90cf 100644
--- a/Library_merged.mk
+++ b/Library_merged.mk
@@ -75,6 +75,12 @@ $(eval $(call gb_Library_use_libraries,merged,\
 ))
 endif
 
+ifeq ($(OS),ANDROID)
+$(eval $(call gb_Library_use_libraries,merged,\
+       libotouch \
+))
+endif
+
 ifeq ($(OS),MACOSX)
 $(eval $(call gb_Library_use_libraries,merged,\
     objc \
diff --git 
a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
 
b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
index a458d02..412c57d 100644
--- 
a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ 
b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -44,6 +44,7 @@ import android.widget.ViewFlipper;
 
 import com.polites.android.GestureImageView;
 
+import com.sun.star.awt.Size;
 import com.sun.star.awt.XBitmap;
 import com.sun.star.awt.XControl;
 import com.sun.star.awt.XDevice;
@@ -202,40 +203,75 @@ public class DocumentLoader
 
     ByteBuffer renderPage(int number)
     {
-        ByteBuffer bb;
-
-        bb = ByteBuffer.allocateDirect(1024*1024*4);
-        long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
-        Log.i(TAG, "bb is " + bb);
-        XDevice device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 
1024, wrapped_bb);
+        try {
+            // A small device with no scale of offset just to find out the 
paper size of this page
 
-        dumpUNOObject("device", device);
+            ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
+            long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
+            XDevice device = 
toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, 1, 1, 0, 0, 
wrapped_smallbb);
 
-        PropertyValue renderProps[] = new PropertyValue[3];
-        renderProps[0] = new PropertyValue();
-        renderProps[0].Name = "IsPrinter";
-        renderProps[0].Value = new Boolean(true);
-        renderProps[1] = new PropertyValue();
-        renderProps[1].Name = "RenderDevice";
-        renderProps[1].Value = device;
-        renderProps[2] = new PropertyValue();
-        renderProps[2].Name = "View";
-        renderProps[2].Value = new MyXController();
+            PropertyValue renderProps[] = new PropertyValue[3];
+            renderProps[0] = new PropertyValue();
+            renderProps[0].Name = "IsPrinter";
+            renderProps[0].Value = new Boolean(true);
+            renderProps[1] = new PropertyValue();
+            renderProps[1].Name = "RenderDevice";
+            renderProps[1].Value = device;
+            renderProps[2] = new PropertyValue();
+            renderProps[2].Name = "View";
+            renderProps[2].Value = new MyXController();
 
-        try {
+            // getRenderer returns a set of properties that include the 
PageSize
             long t0 = System.currentTimeMillis();
-            renderable.render(number, doc, renderProps);
+            PropertyValue rendererProps[] = renderable.getRenderer(number, 
doc, renderProps);
             long t1 = System.currentTimeMillis();
+            Log.i(TAG, "renderer properties: (took " + 
((t1-t0)-timingOverhead) + " ms)");
+
+            int pageWidth = 0, pageHeight = 0;
+            for (int i = 0; i < rendererProps.length; i++) {
+                if (rendererProps[i].Name.equals("PageSize")) {
+                    pageWidth = ((Size) rendererProps[i].Value).Width;
+                    pageHeight = ((Size) rendererProps[i].Value).Height;
+                    Log.i(TAG, "  PageSize: " + pageWidth + "x" + pageHeight);
+                }
+            }
+
+            // Create a new device with the correct scale and offset
+            ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024*4);
+            long wrapped_bb = Bootstrap.new_byte_buffer_wrapper(bb);
+
+            Log.i(TAG, "bb is " + bb);
+
+            if (pageWidth == 0) {
+                // Huh?
+                device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 
1024, 1, 1, 0, 0, wrapped_bb);
+            } else {
+                // Scale so that it fits our device which has a resolution of 
96/in (see
+                // SvpSalGraphics::GetResolution()). The page size returned 
from getRenderer() is in 1/mm * 100.
+                int scaleDenumerator = Math.max(pageWidth, pageHeight) / 2540 
* 96;
+                Log.i(TAG, "Scaling with 1024/" + scaleDenumerator);
+
+                device = toolkit.createScreenCompatibleDeviceUsingBuffer(1024, 
1024, 1024, scaleDenumerator, 0, 0, wrapped_bb);
+            }
+
+            // Update the property that points to the device
+            renderProps[1].Value = device;
+
+            t0 = System.currentTimeMillis();
+            renderable.render(number, doc, renderProps);
+            t1 = System.currentTimeMillis();
             Log.i(TAG, "Rendering page " + number + " took " + 
((t1-t0)-timingOverhead) + " ms");
+
+            Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
+
+            return bb;
         }
         catch (Exception e) {
             e.printStackTrace(System.err);
-            System.exit(1);
+            finish();
         }
 
-        Bootstrap.force_full_alpha_bb(bb, 0, 1024 * 1024 * 4);
-
-        return bb;
+        return null;
     }
 
     class Page
@@ -415,7 +451,7 @@ public class DocumentLoader
 
             ByteBuffer smallbb = ByteBuffer.allocateDirect(128*128*4);
             long wrapped_smallbb = Bootstrap.new_byte_buffer_wrapper(smallbb);
-            XDevice smalldevice = 
toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, wrapped_smallbb);
+            XDevice smalldevice = 
toolkit.createScreenCompatibleDeviceUsingBuffer(128, 128, 1, 1, 0, 0, 
wrapped_smallbb);
 
             PropertyValue renderProps[] = new PropertyValue[3];
             renderProps[0] = new PropertyValue();
@@ -428,8 +464,10 @@ public class DocumentLoader
             renderProps[2].Name = "View";
             renderProps[2].Value = new MyXController();
 
+            t0 = System.currentTimeMillis();
             pageCount = renderable.getRendererCount(doc, renderProps);
-            Log.i(TAG, "getRendererCount: " + pageCount);
+            t1 = System.currentTimeMillis();
+            Log.i(TAG, "getRendererCount: " + pageCount + ", took " + 
((t1-t0)-timingOverhead) + " ms");
 
             flipper = new ViewFlipper(this);
 
@@ -450,7 +488,7 @@ public class DocumentLoader
         }
         catch (Exception e) {
             e.printStackTrace(System.err);
-            System.exit(1);
+            finish();
         }
     }
 
diff --git a/offapi/com/sun/star/awt/XToolkit2.idl 
b/offapi/com/sun/star/awt/XToolkit2.idl
index c174d27..1c5327c 100644
--- a/offapi/com/sun/star/awt/XToolkit2.idl
+++ b/offapi/com/sun/star/awt/XToolkit2.idl
@@ -36,7 +36,11 @@ interface XToolkit2: XToolkit
 
   com::sun::star::awt::XDevice createScreenCompatibleDeviceUsingBuffer( [in] 
long Width,
                                                                         [in] 
long Height,
-                                                                        [in] 
hyper addressOfMemoryBufferForSharedArrayWrapper );
+                                                                        [in] 
long ScaleNumerator,
+                                                                        [in] 
long ScaleDenominator,
+                                                                        [in] 
long XOffset,
+                                                                        [in] 
long YOffset,
+                                                                        [in] 
hyper AddressOfMemoryBufferForSharedArrayWrapper );
 };
 
 }; }; }; };
diff --git a/toolkit/Library_tk.mk b/toolkit/Library_tk.mk
index 1ba1efd..ddcfa82 100644
--- a/toolkit/Library_tk.mk
+++ b/toolkit/Library_tk.mk
@@ -148,4 +148,10 @@ $(eval $(call gb_Library_use_libraries,tk,\
 endif
 endif
 
+ifeq ($(OS),ANDROID)
+$(eval $(call gb_Library_use_libraries,tk,\
+    libotouch \
+))
+endif
+
 # vim: set noet sw=4 ts=4:
diff --git a/toolkit/inc/toolkit/awt/vclxtoolkit.hxx 
b/toolkit/inc/toolkit/awt/vclxtoolkit.hxx
index dc085b8..6192f8f 100644
--- a/toolkit/inc/toolkit/awt/vclxtoolkit.hxx
+++ b/toolkit/inc/toolkit/awt/vclxtoolkit.hxx
@@ -129,7 +129,7 @@ public:
     ~VCLXToolkit();
 
     // ::com::sun::star::awt::XToolkit2
-    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice >      
SAL_CALL createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 
Height, sal_Int64 addressOfMemoryBufferForSharedArrayWrapper ) throw
+    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice >      
SAL_CALL createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, sal_Int32 
Height, sal_Int32 ScaleNumerator, sal_Int32 ScaleDenominator, sal_Int32 
XOffset, sal_Int32 YOffset, sal_Int64 
AddressOfMemoryBufferForSharedArrayWrapper ) throw
 (::com::sun::star::uno::RuntimeException);
 
     // ::com::sun::star::awt::XToolkit
diff --git a/toolkit/source/awt/vclxtoolkit.cxx 
b/toolkit/source/awt/vclxtoolkit.cxx
index c799393..e027b23 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -567,10 +567,10 @@ void SAL_CALL VCLXToolkit::disposing()
 
 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > 
VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) 
throw(::com::sun::star::uno::RuntimeException)
 {
-    return createScreenCompatibleDeviceUsingBuffer( Width, Height, 0 );
+    return createScreenCompatibleDeviceUsingBuffer( Width, Height, 1, 1, 0, 0, 
0 );
 }
 
-::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > 
VCLXToolkit::createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, 
sal_Int32 Height, sal_Int64 addressOfMemoryBufferForSharedArrayWrapper ) 
throw(::com::sun::star::uno::RuntimeException)
+::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > 
VCLXToolkit::createScreenCompatibleDeviceUsingBuffer( sal_Int32 Width, 
sal_Int32 Height, sal_Int32 ScaleNumerator, sal_Int32 ScaleDenominator, 
sal_Int32 XOffset, sal_Int32 YOffset, sal_Int64 
addressOfMemoryBufferForSharedArrayWrapper ) 
throw(::com::sun::star::uno::RuntimeException)
 {
     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
 
@@ -583,7 +583,8 @@ void SAL_CALL VCLXToolkit::disposing()
     if ( addressOfMemoryBufferForSharedArrayWrapper != 0 ) {
 #if defined(ANDROID)
         ByteBufferWrapper *bbw = (ByteBufferWrapper *) (intptr_t) 
addressOfMemoryBufferForSharedArrayWrapper;
-        pV->SetOutputSizePixelAndBuffer( Size( Width, Height ), 
basebmp::RawMemorySharedArray( bbw->pointer(), *bbw ));
+        pV->SetOutputSizePixelScaleOffsetAndBuffer( Size( Width, Height ), 
Fraction(ScaleNumerator, ScaleDenominator), Point( XOffset, YOffset), 
basebmp::RawMemorySharedArray( bbw->pointer(), *bbw ));
+#else
         OSL_FAIL( "rendering to a pre-allocated buffer not done yet for this 
OS" );
 #endif
     } else {
diff --git a/touch/source/uno/Document.cxx b/touch/source/uno/Document.cxx
index 5163ef4..506e4e5 100644
--- a/touch/source/uno/Document.cxx
+++ b/touch/source/uno/Document.cxx
@@ -216,7 +216,7 @@ public:
 
         selection <<= m_xComponent;
 
-        uno::Reference< awt::XDevice > device( 
m_xToolkit->createScreenCompatibleDeviceUsingBuffer( width, height, buffer ) );
+        uno::Reference< awt::XDevice > device( 
m_xToolkit->createScreenCompatibleDeviceUsingBuffer( width, height, 1, 1, 0, 0, 
buffer ) );
 
         beans::PropertyValues renderProps;
 
diff --git a/vcl/inc/vcl/virdev.hxx b/vcl/inc/vcl/virdev.hxx
index 32a3167..9a5b01d 100644
--- a/vcl/inc/vcl/virdev.hxx
+++ b/vcl/inc/vcl/virdev.hxx
@@ -106,7 +106,7 @@ public:
     virtual             ~VirtualDevice();
 
     sal_Bool                SetOutputSizePixel( const Size& rNewSize, sal_Bool 
bErase = sal_True );
-    sal_Bool                SetOutputSizePixelAndBuffer( const Size& rNewSize, 
const basebmp::RawMemorySharedArray &pBuffer );
+    sal_Bool                SetOutputSizePixelScaleOffsetAndBuffer( const 
Size& rNewSize, const Fraction& rScale, const Point& rNewOffset, const 
basebmp::RawMemorySharedArray &pBuffer );
     sal_Bool                SetOutputSize( const Size& rNewSize, sal_Bool 
bErase = sal_True )
                             { return SetOutputSizePixel( LogicToPixel( 
rNewSize ), bErase ); }
 
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 93aec4f..2c67355 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -368,16 +368,15 @@ sal_Bool VirtualDevice::SetOutputSizePixel( const Size& 
rNewSize, sal_Bool bEras
     return ImplSetOutputSizePixel( rNewSize, bErase, 
basebmp::RawMemorySharedArray() );
 }
 
-sal_Bool VirtualDevice::SetOutputSizePixelAndBuffer( const Size& rNewSize, 
const basebmp::RawMemorySharedArray &pBuffer )
+sal_Bool VirtualDevice::SetOutputSizePixelScaleOffsetAndBuffer( const Size& 
rNewSize, const Fraction& rScale, const Point& rNewOffset, const 
basebmp::RawMemorySharedArray &pBuffer )
 {
-    // Is this the place to put in scaling and offsetting, passed in as 
parameters from createScreenCompatibleDeviceUsingBuffer?
-    // Bogus test just to see that something happens:
-    // if (pBuffer) {
-    //    MapMode mm = GetMapMode();
-    //    mm.SetScaleX(Fraction(4, 1));
-    //    mm.SetScaleY(Fraction(4, 1));
-    //    SetMapMode(mm);
-    //}
+    if (pBuffer) {
+        MapMode mm = GetMapMode();
+        mm.SetOrigin( rNewOffset );
+        mm.SetScaleX( rScale );
+        mm.SetScaleY( rScale );
+        SetMapMode( mm );
+    }
     return ImplSetOutputSizePixel( rNewSize, sal_True, pBuffer);
 }
 
commit 8dd75128a5a7e068ae63f3d1cc6b41410f7d7122
Author: Tor Lillqvist <tlillqv...@suse.com>
Date:   Mon Jun 18 22:02:57 2012 +0300

    ByteBufferWrapper tweaks
    
    operator() gets called in a Java GC thread. A JNIEnv* saved in the
    constructor (which is called from the UI thread) is not valid in other
    threads (although for now, Dalvik notices, warns, and works around
    it). So don't bother keeping the JNIEnv*. Instead fetch one when
    needed. Move the method implementations from inline in the header to
    libotouch's android.cxx.
    
    Change-Id: I7de6fc54bb8d9a59146576d6e8c325fe917393ee

diff --git a/sal/inc/sal/ByteBufferWrapper.hxx 
b/sal/inc/sal/ByteBufferWrapper.hxx
index 954922d..63bb618 100644
--- a/sal/inc/sal/ByteBufferWrapper.hxx
+++ b/sal/inc/sal/ByteBufferWrapper.hxx
@@ -21,25 +21,14 @@ namespace org { namespace libreoffice { namespace touch {
 class ByteBufferWrapper
 {
 private:
-  JNIEnv *env;
-  jobject object;
+    jobject object;
 
 public:
-  ByteBufferWrapper(JNIEnv *e, jobject o) :
-    env(e)
-  {
-    object = env->NewGlobalRef(o);
-  }
-
-  sal_uInt8* pointer()
-  {
-    return (sal_uInt8 *) env->GetDirectBufferAddress(object);
-  }
-
-  void operator()(sal_uInt8 * /* p */)
-  {
-    env->DeleteGlobalRef(object);
-  }
+    ByteBufferWrapper(JNIEnv *env, jobject o);
+
+    sal_uInt8* pointer();
+
+    void operator()(sal_uInt8 *p);
 };
 
 }; }; };
diff --git a/touch/Library_libotouch.mk b/touch/Library_libotouch.mk
index 1e06db4..17d1f45 100644
--- a/touch/Library_libotouch.mk
+++ b/touch/Library_libotouch.mk
@@ -33,6 +33,10 @@ $(eval $(call gb_Library_add_exception_objects,libotouch,\
 
 ifeq ($(OS),ANDROID)
 
+$(eval $(call gb_Library_use_libraries,libotouch,\
+       lo-bootstrap \
+))
+
 $(eval $(call gb_Library_add_exception_objects,libotouch,\
        touch/source/android/android \
 ))
diff --git a/touch/source/android/android.cxx b/touch/source/android/android.cxx
index 06768c8..3a116b1 100644
--- a/touch/source/android/android.cxx
+++ b/touch/source/android/android.cxx
@@ -10,9 +10,43 @@
 #include <jni.h>
 
 #include <sal/ByteBufferWrapper.hxx>
+#include <osl/detail/android-bootstrap.h>
 
 using org::libreoffice::touch::ByteBufferWrapper;
 
+static JNIEnv *get_env()
+{
+    JavaVMAttachArgs args = {
+        JNI_VERSION_1_2,
+        NULL,
+        NULL
+    };
+
+    JavaVM *jvm = lo_get_javavm();
+    JNIEnv *env = NULL;
+
+    jvm->AttachCurrentThread(&env, &args);
+    return env;
+}
+
+__attribute__ ((visibility("default")))
+ByteBufferWrapper::ByteBufferWrapper(JNIEnv *env, jobject o)
+{
+    object = env->NewGlobalRef(o);
+}
+
+__attribute__ ((visibility("default")))
+sal_uInt8* ByteBufferWrapper::pointer()
+{
+    return (sal_uInt8 *) get_env()->GetDirectBufferAddress(object);
+}
+
+__attribute__ ((visibility("default")))
+void ByteBufferWrapper::operator()(sal_uInt8 * /* p */)
+{
+    get_env()->DeleteGlobalRef(object);
+}
+
 extern "C"
 __attribute__ ((visibility("default")))
 jlong
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to