images::ImagesRenderer Class Reference

#include <images_renderer.h>

Collaboration diagram for images::ImagesRenderer:
Collaboration graph
[legend]

Public Member Functions

 ImagesRenderer (ImagesDocument *document)
 ~ImagesRenderer (void)
ImageRenderStatus render (const std::string &anchor, const ImagePageAttrs &attrs, int ref_id, void *user_data)
void notify_page_ready (ImagePage *page, int ref_id, ImageRenderStatus status, void *user_data)
ImagePageget_page (const std::string &anchor, const ImagePageAttrs &attrs)
void add_page (ImagePage *page)
ImageRenderStatus can_render (const std::string &anchor, const ImagePageAttrs &attrs)
bool set_memory_limit (const int bytes)
void stop (void)

Data Fields

utils::Signal< ImagePage
*, const unsigned int,
ImageRenderStatus, void * > 
sig_page_ready

Detailed Description

Definition at line 51 of file images_renderer.h.


Constructor & Destructor Documentation

images::ImagesRenderer::ImagesRenderer ( ImagesDocument document  ) 

Definition at line 39 of file images_renderer.cpp.

References LOGPRINTF, and common::Thread::start().

00040 : doc(document)
00041 , render_thread()
00042 , pages_cache()
00043 , last_render_page(0)    
00044 {
00045     LOGPRINTF("%p", document);
00046 
00047     render_thread.start();
00048     
00049     //  Pre-render policy
00050     set_prerender_policy(2, 2);
00051 }

Here is the call graph for this function:

images::ImagesRenderer::~ImagesRenderer ( void   ) 

Definition at line 53 of file images_renderer.cpp.

References LOGPRINTF, and common::Thread::stop().

00054 {
00055     LOGPRINTF("entry");
00056 
00057     render_thread.stop();
00058     // pages_cache.clear();
00059 }

Here is the call graph for this function:


Member Function Documentation

void images::ImagesRenderer::add_page ( ImagePage page  ) 

Definition at line 136 of file images_renderer.cpp.

References images::PagesCache::add_page(), and LOGPRINTF.

Referenced by images::ImageRenderTask::execute().

00137 {
00138     LOGPRINTF("%p", page);
00139     
00140     if (page)
00141     {
00142         pages_cache.add_page(page);
00143     }
00144 }

Here is the call graph for this function:

Here is the caller graph for this function:

ImageRenderStatus images::ImagesRenderer::can_render ( const std::string &  anchor,
const ImagePageAttrs attrs 
)

Definition at line 148 of file images_renderer.cpp.

References images::ImagePage::estimate_length(), images::IMG_RENDER_FAIL, images::IMG_RENDER_INVALID, images::IMG_RENDER_OK, images::IMG_RENDER_OOM, LOGPRINTF, images::PagesCache::make_enough_memory(), images::MAX_ORIGINAL_IMAGE, images::ImagePageAttrs::original_height, images::ImagePageAttrs::original_width, and WARNPRINTF.

Referenced by images::ImageRenderTask::execute(), and render().

00150 {
00151     bool is_valid_image = false;
00152     if ((attrs.original_width > 0) && (attrs.original_height > 0))
00153     {
00154         is_valid_image = true;
00155     }        
00156 
00157     // Check whether the image is valid or not.
00158     if (!is_valid_image)
00159     {
00160         WARNPRINTF("Invalid image page %s.", anchor.c_str());            
00161         return IMG_RENDER_INVALID;
00162     }
00163 
00164     // Check for maximum image size.
00165     // The temporary memory used by gdk_pixbuf_load_at_scale() during rendering
00166     // cannot be estimated correctly but it depends partly on the image size.
00167     // To prevent memory overflows we accept images up to a maximum size only.
00168     if (attrs.original_width * attrs.original_height > MAX_ORIGINAL_IMAGE)
00169     {
00170         WARNPRINTF("Image too big: w [%d] h [%d] max [%d]", attrs.original_width, attrs.original_height, MAX_ORIGINAL_IMAGE);
00171         return IMG_RENDER_FAIL;
00172     }
00173 
00174     // Check whether there is enough memory to render.
00175     gint64 size = ImagePage::estimate_length(attrs);
00176     if (!pages_cache.make_enough_memory(size))
00177     {
00178         LOGPRINTF("Not enough memory to render page [%s]", anchor.c_str());
00179         return IMG_RENDER_OOM;
00180     }
00181     
00182     return IMG_RENDER_OK;
00183     
00184 }

Here is the call graph for this function:

Here is the caller graph for this function:

ImagePage * images::ImagesRenderer::get_page ( const std::string &  anchor,
const ImagePageAttrs attrs 
)

Definition at line 117 of file images_renderer.cpp.

References images::ImagePage::calc_key(), images::ImagePageAttrs::desired_height, images::ImagePageAttrs::desired_width, images::PagesCache::get_page(), LOGPRINTF, images::ImagePageAttrs::rotation, and images::ImagePageAttrs::zoom.

Referenced by images::ImageRenderTask::execute(), and render().

00119 {
00120     LOGPRINTF("%s zoom[%f] rotation[%d]", 
00121               anchor.c_str(), attrs.zoom, attrs.rotation);
00122 
00123     size_t key = ImagePage::calc_key(anchor, 
00124                                      attrs.desired_width, 
00125                                      attrs.desired_height,
00126                                      attrs.zoom,
00127                                      attrs.rotation);
00128     
00129     ImagePage * page = pages_cache.get_page(key);
00130    
00131     LOGPRINTF("return %p", page);
00132 
00133     return page;
00134 }

Here is the call graph for this function:

Here is the caller graph for this function:

void images::ImagesRenderer::notify_page_ready ( ImagePage page,
int  ref_id,
ImageRenderStatus  status,
void *  user_data 
)

Definition at line 280 of file images_renderer.cpp.

References utils::Signal< A1, A2, A3, A4, A5 >::broadcast(), images::PagesCache::lock(), LOGPRINTF, sig_page_ready, images::PagesCache::unlock(), and images::ImagePage::update_timestamp().

Referenced by images::ImageRenderTask::execute(), and render().

00284 {
00285     LOGPRINTF("%p %d", page, ref_id);
00286 
00287     pages_cache.lock();
00288 
00289     if (page)
00290     {
00291         page->update_timestamp();
00292     }
00293     
00294     if (ref_id != -1)
00295     {
00296         sig_page_ready.broadcast(page, ref_id, status, user_data);
00297     }
00298 
00299     pages_cache.unlock();
00300 }

Here is the call graph for this function:

Here is the caller graph for this function:

ImageRenderStatus images::ImagesRenderer::render ( const std::string &  anchor,
const ImagePageAttrs attrs,
int  ref_id,
void *  user_data 
)

Definition at line 61 of file images_renderer.cpp.

References can_render(), common::Thread::clear_all(), get_page(), images::ImagesDocument::get_position(), images::IMG_RENDER_OK, LOGPRINTF, notify_page_ready(), common::Thread::prepend_task(), images::ImagePageAttrs::rotation, WARNPRINTF, and images::ImagePageAttrs::zoom.

Referenced by main().

00065 {
00066     LOGPRINTF("%s, zoom[%f], rotation[%d], ref_id[%d]",
00067               anchor.c_str(), attrs.zoom, attrs.rotation, ref_id);
00068     
00069     // Return code.
00070     ImageRenderStatus ret = IMG_RENDER_OK;
00071     
00072     // Clear the old tasks.
00073     render_thread.clear_all();
00074 
00075     ImageRenderTask * task = 0;
00076     
00077     // Get the render result from 'pages cache'
00078     ImagePage * page = get_page(anchor, attrs);
00079     if (!page)
00080     {
00081         ret = can_render(anchor, attrs);
00082         if (ret == IMG_RENDER_OK)
00083         {
00084             // Prepend 'render task' to 'render_thread'
00085             task = new ImageRenderTask(anchor, attrs, ref_id, this, user_data);
00086             // Notes, The flag 'true' means aborting the current task.
00087             // But for images, the implementation of the task 
00088             // doesn't support aborting feature.
00089             render_thread.prepend_task(task, true);
00090         }
00091         else
00092         {
00093             // Notify renderer this page is not ready because of what. e.g OOM.
00094             notify_page_ready(0, ref_id, ret, user_data);
00095         }
00096     }
00097     else
00098     {
00099         WARNPRINTF("Page %s already in pages_cache!", anchor.c_str());
00100 
00101         // This requested page is already in 'pages_cache'.
00102         // Notify page is ready now.
00103         notify_page_ready(page, ref_id, IMG_RENDER_OK, user_data);
00104     }
00105 
00106     // Do pre_rendering.
00107     assert(doc);
00108     int page_num = doc->get_position(anchor);
00109 
00110     bool page_down = (last_render_page <= page_num) ? true : false;
00111     last_render_page = page_num;
00112     pre_render(page_num, attrs, page_down);
00113     
00114     return ret;
00115 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool images::ImagesRenderer::set_memory_limit ( const int  bytes  ) 

Definition at line 310 of file images_renderer.cpp.

References LOGPRINTF, and images::PagesCache::set_memory_limit().

00311 {
00312     LOGPRINTF("entry");
00313 
00314     return pages_cache.set_memory_limit(bytes);
00315 }

Here is the call graph for this function:

void images::ImagesRenderer::stop ( void   ) 

Definition at line 317 of file images_renderer.cpp.

References common::Thread::stop().

Referenced by images::PluginViewImpl::stop_renderer().

00318 {
00319     render_thread.stop();    
00320 }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

Definition at line 94 of file images_renderer.h.

Referenced by notify_page_ready(), and images::PluginViewImpl::PluginViewImpl().


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208