Tuesday, December 13, 2011

OwnPtr and PassOwnPtr

I am just trying to jot down my understandings of OwnPtr/PassOwnPtr smart pointer class that is used in WebKit project. There is a good blog explaining the usage of RefPtr and PassRefPtr smart pointers (Refer to http://www.webkit.org/coding/RefPtr.html)

OwnPtr is a simple smart pointer class in which there is only one owner for a pointer created/assigned to OwnPtr.
What it means is that you cannot assign a OwnPtr to another.
But there is a way to transfer the ownership using the PassOwnPtr.
By calling a release on a OwnPtr you get a PassOwnPtr which can be assigned to a OwnPtr.
It can get slightly confusing now OwnPtr is not really a singleton... A Singleton class does not determine the ownership of object created and also OwnPtr does not really prevent one from creating more instances of class.

So how do we create a OwnPtr ->
call adoptPtr(new A) this will give a PassOwnPtr. You can assign this to a OwnPtr and work with it.
How to work between pointers and OwnPtr/PassOwnPtr->
A release on OwnPtr gives you a PassOwnPtr
A leakPtr on OwnPtr gives you Raw Pointer
A leakPtr on PassOwnPtr gives you a Raw Pointer

Saturday, June 11, 2011

Guidelines to port webkit

As i write this blog the webkit is ported to at least 8 platforms like gtk,qt,mac,symbian,haiku,wince,android,efl and many more to come..
If some one is new to webkit and wants to know where to start porting from I will try and put some basic guidelines to follow.
First and foremost see if you have what is needed to port on your platform:
i) Threading -> pthread equivalent API's if you want multi-threading (ENABLE_JSC_MULTIPLE_THREADS turn it OFF if you do not have one)
ii) Timers -> any platform would have this so it should be fine
iii) Drawing surface/Graphics Library
iv) Way to integrate widgets with your drawing surface; put it another way how to provide input to your webpage. Gtk has clean way of doing this, can be followed
v) Theme for widgets
vi) Define API layer -> follow QT/GTK/MAC/Android port for defining one.
vii) Porting JSCore by defining classes PageAllocation/Reservation
viii) Some other classes/functions are needed like random number function, date etc;
ix) I am keeping it very brief but you need a way to take care of plugins
-) Plugin Creation
-) Plugin Drawing Surface
x) Networking component like curl,soup
xi) Need to port the WebCoreSupport classes again follow GTK/QT port for ease
xii) Image decoders
After checking if you have got everything { only v) is not mandatory ix) is not mandatory if you do not want plugins}

Now after getting the first step right second thing to do is getting your build set up:
Start with javascriptcore, you need to build the source and generate derivedsources and see if you can get it built right. To do this you have to port some functions as I mentioned earlier.
To test if you got the build right you can run the javscriptcore tests.

Once this is done you can replicate the same for Webcore, you need to create the stub files/functions for port. Follow one port like GTK/QT for this like create files in WebCore/platform/xyz folder;

Once this is ready, you need to get this port back into open source as later sync up with the open source is necessity. Follow http://trac.webkit.org/wiki/SuccessfulPortHowTo for creating DRT, automation tests which is needed for getting code back into trunk.



Sunday, June 5, 2011

WebKit Build Issues

Steps to build webkit gtk port (I am doing this on Ubunty Natty )are :
Installing dependencies ->
sudo apt-get install build-essential vim subversion libglib2.0-dev gtk-doc-tools bison flex gperf libicu-dev libjpeg62-dev libpng12-dev libxml2-dev libpango1.0-dev libgail-dev libxt-dev libsoup2.4-dev libsqlite3-dev libxslt1-dev libgstreamer-plugins-base-0.10-dev

you can enable/disable different features by passing the parameters to autogen.sh
like -> sh autogen.sh --enable-3d-transforms=yes
NOTE that if some feature is turned OFF by default and you enable it then there is no guarantee that your build will go through; that feature could be work in progress or an unstable one.

for default build options
sh autogen.sh && make

but there are times when it is not as simple as that..some of the errors you might get i will list them down and their fixes:

If you get this error while building gtk port of webkit

error: webkitmarshal.h: No such file or directory..
work around to fix this is
touch ./Source/WebKit/gtk/webkitmarshal.list

if you get an error like
ld terminated by signal 9 ..you need to increase swap space do the below:
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
sudo mkswap /swapfile
If you want to have this change after reboot as well, add below line at the end to /etc/fstab
/swapfile none swap sw 0 0

sudo swapon -a to turn on the swap space

Saturday, May 21, 2011

WebKit

I have been working on WebKit for quite some time and here are some basics which can help people to get around the code base. I will be talking about the gtk port and working on ubuntu 11.04. Some one was asking what is the debugger to use it is GDB.
So first to start with webkit.org will give you the code , either download the nightly builds if you are just interested in using it or checkout the code from svn or git if you want to be the tip of tree and/or contribute patches to webkit.

The directory structure of webkit has gone through quite a few modifications.
The current code base has following directories of interest in the root directory->
Source =>has the entire code base
Tools =>has the sample applications like WinLauncher,GtkLauncher etc; scripts folder has many perl scripts for building, updating,create patches and run webkit tests to name a few
Inside Source
WebCore => has the code for html parser,tokenizer, css parser, loader,graphics,svg rendering,html rendering,websockets, webworkers and any new rendering engine related features code will be found here.
JavaScriptCore => has the code for javascript parser,interpreter/runtime compiler.
There are two other important folders WebKit and WebKit2 these are basically port dependent glue code and they have the API layer that is exposed to the applications.
The essential difference between WebKit and WebKit2 is that WebKit2 is a new API layer for WebKit designed to support a split process model, where the rendering engine runs in a separate process from the application UI.
In the next few posts i will try and take up each path and explain in detail..leave me comments if you want to know about some thing in specific

Friday, May 20, 2011

Hands on with OpenGL

I started working with OpenGL and thought it is worthwhile to document stuff I learn.
Development environment is Ubuntu 11.04 and im using mesa3d gl and freeglut3-dev libs for opengl libs.
how to compile:
if you have a sample program you want to compile do it as
gcc file.c -lglut -lGLU -o output

Friday, April 1, 2011

GIT CheatSheet

If you are looking for a cheat sheet which would help you in working around with git, see the commands below. Alternatively you could use TortoiseGIT which gives a GUI and makes life simple.

GIT commands:
To clone the project:
git clone url (example: git clone git://anongit.freedesktop.org/git/pixman.git)
This would create pixman directory with a .git folder inside it.
to create branch
git branch -b images_gifdecoder_mynameiskhan
 or
git branch branch_name
git checkout branch_name
NOTE: branch naming convention -- feature_details_name - this will help to 
have unique branch names
List of branches on your repository
git branch  ----------------> '*' indicates the current branch
List of branches on server repository as well
git branch -a
Delete a branch
git branch -d branch_name
Track a remote branch
git branch --track pixman_naiem_trial remotes/origin/pixman_naiem_trial
Know the status
git status
Reset all changes:
git checkout -f
See most recent commit
git show
Commit only few files:
git commit path/to/some/files
Merge
git merge branchname
merge branchname to current branch
Resolving a merge
git status
edit the files with problem and then do staging by git add
Stashing changes
git stash "work in progress for foo feature"
git stash apply
Revert changes
git reset --hard