Can't able to understand the code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't able to understand the code

shawon58
I try to run the code which attached below. But i dont have idea what i need
to write on playground to run the code. can anyone explain what happen
actually using this class>>primImage: aFormat width: aWidth height:aHeight

<http://forum.world.st/file/t372453/prob.png>



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Can't able to understand the code

Pharo Smalltalk Users mailing list
Hi

What are you trying to do ? To use Athens ? Do you want to use it with Morphic ?

Renaud





Apr. 7, 2020, 08:59 by [hidden email]:
I try to run the code which attached below. But i dont have idea what i need
to write on playground to run the code. can anyone explain what happen
actually using this class>>primImage: aFormat width: aWidth height:aHeight

<http://forum.world.st/file/t372453/prob.png>



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Can't able to understand the code

shawon58
actually i am just exploring UFFI from the pdf "Calling Foreign Functions
with Pharo" there one section is for external objects so i cant understand
that code what i attach as screenshot above. can u able to explain what
actually happen here ??



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: Can't able to understand the code

Guillermo Polito
Hi Shawon,

where did you get the docs?

Have you tried the latest version (january/february this year)


?

El 8 abr 2020, a las 4:44, shawon58 <[hidden email]> escribió:

actually i am just exploring UFFI from the pdf "Calling Foreign Functions
with Pharo" there one section is for external objects so i cant understand
that code what i attach as screenshot above. can u able to explain what
actually happen here ??



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html


Reply | Threaded
Open this post in threaded view
|

Re: Can't able to understand the code

Pharo Smalltalk Users mailing list
In reply to this post by shawon58
Hi

I'm not a FFI expert, and you code may not be the latest FFI version. However, If I look at it from Pharo side:
When you want to use Athens with Cairo backend, you have to initialize its surface using a call like:

surface := AthensCairoSurface extent: self extent
Note that I'm calling a class method of AthensCairoSurface.
In this example, 'self extent' will give you the size of the rectangle used by Morph for its bounds size.

This, in turn, will call
AthensCairoSurface class >> extent: anExtent
  ^self extent: anExtent format: CAIRO_FORMAT_ARGB32

and you reach:
AthensCairoSurface class >> extent: anExtent format: aFormat
^ ( self primImage: aFormat width: anExtent x height: anExtent y + 1) initialize

Which lead you to:
primImage: aFormat width: aWidth height: aHeight
^ self ffiCall: #(AthensCairoSurface cairo_image_surface_create (int aFormat,
                                                         int aWidth,
                                                         int aHeight) )

From there, you have linked your pharo code done to initialize a Cairo surface.
This will do a C call like:

cairo_image_surface_create(CAIRO_FORMAT_ARGB32, aWidth, aHeight)

Through the magic of FFI, It'll return an instance of AthensCairoSurface you''ll be able to use directly in your Pharo code.

You can have a look to AthensFlakeDemo in Athens-Demo for a full working example.

Renaud






Apr. 7, 2020, 22:44 by [hidden email]:
actually i am just exploring UFFI from the pdf "Calling Foreign Functions
with Pharo" there one section is for external objects so i cant understand
that code what i attach as screenshot above. can u able to explain what
actually happen here ??



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html