Commit Graph

111 Commits

Author SHA1 Message Date
Jean-Philippe Andre 1513007815 evas/cserve2: Merge Glyph_Data and mempool index
Glyphs were previously using 3 shared buffers, now reduce to 2:
- Memory pool (mempool) containing the glyph drawable data
- Index table (Shared_Index / array) containing only the
  indexes of the buffers in the mempool
- Glyph_Data table (array) containing the glyphs descriptors
  AS WELL as the buffer indexes.

So, we just merge the two index tables into one by using directly
objects of type Glyph_Data for the referencing of the mempool
buffers.
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre 7b62d77cf5 evas/cserve2: Add debug and reduce number of GLYPHS_USED messages
One socket message was sent per each glyph used ... which means
a LOT of messages when text is being redrawn.

Reduce this flow of messages by triggering send() only when
50+ items are being used.
Btw, USED is a bit useless as there is no UNUSED equivalent.

Also, slightly improve debug logs.
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre 745b4d4acc evas/cserve2: catch only SIGINT from cserve2
SIGTERM and SIGQUIT don't need to be caught.
the proper signal to ask cserve2 to exit cleanly is SIGINT.

enlightenment_start (or systemd) should be responsible for
restarting in case of crash / unexpected termination.

cserve2 will not restart if killed with signal SIGINT,
as it will then exit with return code 0 (normal)
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre cd702b3785 evas/cserve2: Reduce repacking and resizing of SHM
These operations have tons of side effects and it's a lot
easier to just avoid doing them. Now, repacking will always
need to happen as applications will add/delete strings and
items, but the less frequent, the better :)

Also, align most arrays & mempools to 32K instead of the
default page size (4K). This will also reduce resizes.
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre c8e6f9e5f9 evas/cserve2: Fix font reloading after cserve2 restart.
Well it LOOKS like it's working properly.
Clients can safely keep running after cserve2 crashed and
restarted.
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre 660ad6e4a4 evas/cserve2: Add PID to shm filenames
This will help identify new memory pools in case cserve2
restarts and reloads the same glyphs for instance.
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre e74cac57e4 evas/cserve2: Reconnect to cserve2 in case of server crash
Try to reconnect to cserve2 if the socket connection was lost.
Resend some messages if necessary.

Images reload seems to be working.
Actually, the images don't change over time, so the clients just
keep the previous references to their images.

FONT RELOAD IS NOT WORKING:
- Crashes
- Invalid glyph data
- Infinite loop in _glyph_map_remap_check()

Root cause:
When new glyphs are requested from the server, they are added to
the mempool. So it is necessary to remap the font.
Unfortunately, in case of server reboot, we did not keep the mempool
so the old glyphs that were not requested again will not be valid.
2013-10-28 15:47:16 +09:00
Jean-Philippe Andre 6f485d2a12 evas/cserve2: Fix reload of image without load_opts
Problem: Images opened without load_opts are reopened
multiple times.
Solution: Use empty load opts when looking for the key.
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 74080fba22 evas/cserve2: Fix scaling error (server side)
This causes crashes in the client also...
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre f18b71d515 evas/cserve2: Fix invalid file referencing in client
Fixes elementary_test "Bg Image":
 - Various load_opts (jpeg geometry) where not handled properly
   by the client.
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre c5ecf6e5d1 evas/cserve2: Fix scaling options
Be more careful when selecting the original image for scaling.
Most load opts must remain the same, only smooth can be toyed with.
Also, fix alpha when scaling.
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 25d71f8236 evas/cserve2: Add alpha flag to Image_data 2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 1e82480c9a evas/cserve2: Use scalecache with cserve2
Let's reuse the logic from scalecache and call cserve2
functions when the scalecache should be used.
So, now, cserve2 server will not scale any image... This is
too computationally intensive for the server's main thread.

This is not optimal but makes a hell of a lot more sense for
the moment. (since cserve2 manages the SHM segments)
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 0d506a7b73 evas/cserve2: Fix images indexing (File_Entry stuff)
High-level problem:
cserve2 does not support load_opts properly when opening an image.
As a result, when (pre)loading a JPEG file with specific load
options (eg. w, h, region and orientation), the image buffer might
have the wrong dimensions.

So, we need to use load_opts when computing file hash key.
And, pass these load options to the loader slave,
and use them while OPENING the image. This will set
properly the geometry.

Fixes test "Preload and Prescale" in elementary_test.
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 85cd382725 evas/cserve2: Drop pre-emptive load of large images
When the image is too large, let's not preload it unless
specifically requested by the application.

Value 320x320 is completely arbitrary.
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 97d9fab704 evas/cserve2: Fallback to normal cache for animated gifs
Pass around "animated" flag for images that can be animated.
Fallback to local cache if the image is animated.
Implementing support for animated images in cserve2 does
not seem to make a lot of sense considering each frame must
be requested independently in real time,... and to be honest
there doesn't seem to be any valid use case anyway :)
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 808c20f989 evas/cserve2: Fix font hinting
cserve2 was not handling font hints properly in the server side
Add some consistency checks and separate glyphs per hinting value
2013-10-28 15:47:15 +09:00
Jean-Philippe Andre 94f0e1b3e1 evas/cserve2: Fix segfault in cserve2 slave
Slaves always crash when loading SVG images.
The svg module was simply not a dynamic module.
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 50be9145a1 evas/cserve2: Small performance fixes 2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 877532e000 evas/cserve2: Repack strings index when too fragmented 2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 74d399ab81 evas/cserve2: Fix NULL vs. empty string
Server side: Some strings were NULL, some other were empty.
Client side was looking for NULL, but the shared index contained
empty key.
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 3f30fae818 evas/cserve2: Remap indexes when count is wrong
When advertised count is wrong, try to remap the index.
This will avoid errors with string_get().
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 8b39c443fe evas/cserve2: Fix lag with invalid font glyphs 2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 9d2400af8b evas/cserve2: Add valid flag on Image_Data and File_Data
Images and Files can be discovered by the client scanner before they
are valid (aka. loaded or opened). We want clients to ignore all
shared objects that are not ready yet, as they are in an undefined
state (values and memory might be invalid).
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 743e204763 evas/cserve2: Optimize shared strings
Shared string indexes are not repacked, since they live in a
memory pool (where the indexes can be reused).
So, the index in the table is equal to their ID. Add initial
test to check if the item at index n has the ID n.
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 71fdd0d342 evas/cserve2: Add SHM debug tool (CLI)
Prints out the content or the shared index.
Does not need any socket connection to the server, read-only.
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre bc7b337fc0 evas/cserve2: Add glyph shm names to Font_Data 2013-10-28 15:47:14 +09:00
Jean-Philippe Andre b5ca88027d evas/cserve2: Remove dead code. 2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 4f5c48236f evas/cserve2: Add proper tags to shm arrays
Use tags such as INDX, FONT, IMAG, FILE.
These can help debugging and for robustness, as they will
be visible in the memory dump.

Update generation_id after repack as well
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 1e4ee656a0 evas/cserve2: Fix cserve2_usage tool
Also, print shared arrays usage as it is sent as first message
upon connection to the server.

Add fonts to LRU and flush LRU as needed.
Seems to work okay. Could probably be finetuned a bit.
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 467b1b1739 evas/cserve2: Store Glyph_Data in shared mempools
- Create one Glyph_Data array per Font_Entry
- Copy Font_Source descriptors in shared array
- Copy font entries in shared index
- Send font index path over socket
- Merge Font_Source and Font_Data in shared memory
- Send font index path on client connect
- Repack font index after free
- Pass font shm name to clients
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre c7515f3300 evas/cserve2: Add mempool_buffer_offset_get() api 2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 7ebda2d123 evas/cserve2: Store glyphs in shared arrays
Also, change the internal structure of glyph listing:
 - Use lists instead of inlists

Switch to use Glyph_Data instead of Glyph_Entry
2013-10-28 15:47:14 +09:00
Jean-Philippe Andre 28a5c6f587 evas/cserve2: Add compile-time log level flag for cserve2
DBG and INF messages pollute the logs and performance reports
from valgrind, let's disable them at build-time for better
benchmarking.

Fix other compilation warnings and clean code a bit
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre 9d731364c1 evas/cserve2: Optimize cserve2_shared_string_del()
eina_hash_del_by_data is very expensive, so let's delete by key
since we can get the original data.
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre e95bd7755e evas/cserve2: Add binary search in server side 2013-10-28 15:47:13 +09:00
Jean-Philippe Andre f5fee255de evas/cserve2: Fix race condition on font load / socket fail
If the client exits while the server is loading fonts,
the font entry objects are accessed after being freed.

Note: This is not a proper fix. The race condition should still
be fixed, but delaying client deletion a bit might help for a while...
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre 88ef4131a0 evas/cserve2: Share paths of index tables with clients
- Send paths to all connected clients
- Send paths upon connection from a new client

- Client side:
 - Fast find opened images
 - Fast find loaded images
 - Optimize load by skipping socket wait

Also, remap indexes when needed (file size changed)
When index file grows, the clients are not notified, so they
must constantly check that their mapping matches the current array
size.
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre 47be3a2b81 evas/cserve2: Prepare shared indexes in clients
- Move required struct definitions to common evas_cs2.h

- Open/close shm and map arrays to memory
Pretty stupid for now as it will close & reopen the shm files
even when unchanged.

- Check shm size and array header consistency

- Implement message send

- Send messages from server when calling repack()
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre c0bb73c775 evas/cserve2: Fix image load premultiplication
There was a color problem in elementary_test since elm
sets premul to 0 while expedite sets it to 1 during image load.
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre db66f69104 evas/cserve2: _cserve2_cache_fast_scaling_check()
Adapt function to new Data/Entry model.
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre ee74562bf0 evas/cserve2: Simplify error logs 2013-10-28 15:47:13 +09:00
Jean-Philippe Andre 64e7d48296 evas/cserve2: Store Image_Data in shared array
Split image entries into Image_Data and Image_Entry.
Store, find and use Image_Data descriptors from shared array.
Fix some wrong hash table usages.
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre 315c2fd161 evas/cserve2: binary search in Shared_Array 2013-10-28 15:47:13 +09:00
Jean-Philippe Andre d0e647fee3 evas/cserve2: Repack File_Data shared array 2013-10-28 15:47:13 +09:00
Jean-Philippe Andre acae35b4d1 evas/cserve2: Use Shared_Array storage for File_Data
File_Entry and File_Data are now two different types,
one being stored in the shared array, the other one
is only a reference counting entry.
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre c57a319df3 evas/cserve2: Rename File_Data pointers to fd
The name fe is also used by Font_Entry, slightly confusing
2013-10-28 15:47:13 +09:00
Jean-Philippe Andre 12deed8073 evas/cserve2: Use unique id counter
Merge file id and image id into a single entry id.
2013-10-28 15:47:12 +09:00
Jean-Philippe Andre 07fb7172d5 evas/cserve2: Implement shared index and buffers
Only import the C file for now.
Implement the following features:

- Shared Arrays
Store arrays of elements of fixed size in shm.

- Shared Mempool
Store random sized buffers in shm.
These buffers are indexed in a Shared Array and are
referred to using their index only.

- Shared Strings
Store strings in a shm in a way similar to Eina_Stringshare
(except strings are referred to using an int index).

- Include evas_cserve2_index.c to the compilation.
- Declare shared index functions in header file.
- Call init() and shutdown() on the shared index subsystem.
- Add find and foreach functions
2013-10-28 15:47:12 +09:00
Jean-Philippe Andre deb8776de5 evas/cserve2: Add functions to resize shm files
- cserve2_shm_segment_request()
Creates a new shm segment (Shm_Handle) from an existing file,
without changing the current mmap.

- cserve2_shm_resize()
Grows the file and remaps in memory (new virtual address).

- cserve2_shm_id_get()
Returns the shm creation ID.
2013-10-28 15:47:12 +09:00