image_render_task.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: image_render_task.cpp
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-images.
00007  *
00008  * uds-plugin-images is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-images is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #include <cassert>
00028 #include <iostream>
00029 
00030 #include "image_render_task.h"
00031 #include "log.h"
00032 
00033 namespace images
00034 {
00035     
00036 ImageRenderTask::ImageRenderTask(const std::string & page_anchor,
00037                                  const ImagePageAttrs & attributes,
00038                                  int reference_id,
00039                                  ImagesRenderer *p_renderer,
00040                                  void * p_user_data)
00041 : anchor(page_anchor)
00042 , ref_id(reference_id)
00043 , renderer(p_renderer)        
00044 , user_data(p_user_data)
00045 {
00046     LOGPRINTF("anchor[%s], ref_id[%d]", anchor.c_str(), ref_id);
00047 
00048     attrs = attributes;
00049 }
00050 
00051 ImageRenderTask::~ImageRenderTask(void)
00052 {
00053     LOGPRINTF("entry");
00054 }
00055 
00056 void ImageRenderTask::execute(void)
00057 { 
00058     LOGPRINTF("anchor[%s], zoom[%f], rotation[%d], reference_id[%d]",
00059                anchor.c_str(), attrs.zoom, attrs.rotation, ref_id );
00060 
00061     assert(renderer);
00062 
00063     // Check wether this page is already in pages_cache?
00064     ImagePage * ptr = renderer->get_page(anchor, attrs);
00065     if (ptr)
00066     {
00067         WARNPRINTF("Page %s already in pages cache!", anchor.c_str());
00068         
00069         // Notify renderer this page is ready now.
00070         renderer->notify_page_ready(ptr, ref_id, IMG_RENDER_OK, user_data);
00071         return;
00072     }
00073 
00074     // Check wether there's enough memory, then render this page.
00075     ImageRenderStatus ret = renderer->can_render(anchor, attrs);
00076     ImagePage * image = 0; 
00077     if (ret == IMG_RENDER_OK)
00078     {
00079         // Render the image
00080         image = new ImagePage(anchor, attrs); 
00081         assert(image);
00082         bool ok = image->render();
00083         if (!ok)
00084         {
00085             ret = IMG_RENDER_FAIL;
00086         }
00087     }
00088     if (ret != IMG_RENDER_OK)
00089     {
00090         WARNPRINTF("Can't render page %s. Error code: %d", anchor.c_str(), ret);
00091 
00092         // Notify renderer this page is not ready for some reason.
00093         renderer->notify_page_ready(0, ref_id, ret, user_data);
00094         delete image;
00095         return;
00096     }
00097     
00098     // Push the ImagePage into 'pages cache'
00099     renderer->add_page(image);
00100         
00101     // Notify renderer this page is ready.
00102     renderer->notify_page_ready(image, ref_id, ret, user_data);
00103 }
00104 };
00105 
00106 
Generated by  doxygen 1.6.2-20100208