image_render_task.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
00070 renderer->notify_page_ready(ptr, ref_id, IMG_RENDER_OK, user_data);
00071 return;
00072 }
00073
00074
00075 ImageRenderStatus ret = renderer->can_render(anchor, attrs);
00076 ImagePage * image = 0;
00077 if (ret == IMG_RENDER_OK)
00078 {
00079
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
00093 renderer->notify_page_ready(0, ref_id, ret, user_data);
00094 delete image;
00095 return;
00096 }
00097
00098
00099 renderer->add_page(image);
00100
00101
00102 renderer->notify_page_ready(image, ref_id, ret, user_data);
00103 }
00104 };
00105
00106