The rendering task. More...
#include <pdf_render_task.h>
Public Member Functions | |
PDFRenderTask (int page_num, const PDFRenderAttributes &attr, PDFController *ctrl, PluginRenderResultImpl *render_res, int id=PRERENDER_REF_ID) | |
PDFRenderTask (PagePtr p, const PDFRenderAttributes &attr, PDFController *ctrl, PluginRenderResultImpl *render_res, int id=PRERENDER_REF_ID) | |
virtual | ~PDFRenderTask () |
void | execute () |
execute the rendering task | |
void * | get_user_data () |
get the pointer of PDFController intance | |
unsigned int | get_id () |
get render id |
The rendering task.
Definition at line 38 of file pdf_render_task.h.
pdf::PDFRenderTask::PDFRenderTask | ( | int | page_num, | |
const PDFRenderAttributes & | attr, | |||
PDFController * | ctrl, | |||
PluginRenderResultImpl * | render_res, | |||
int | id = PRERENDER_REF_ID | |||
) |
Definition at line 35 of file pdf_render_task.cpp.
References pdf::TASK_RENDER, and pdf::Task::type.
00038 : page(0) 00039 , page_number(page_num) 00040 , page_render_attr(attr) 00041 , doc_ctrl(ctrl) 00042 , ref_id(id) 00043 , render_result(render_res) 00044 { 00045 type = TASK_RENDER; 00046 }
pdf::PDFRenderTask::PDFRenderTask | ( | PagePtr | p, | |
const PDFRenderAttributes & | attr, | |||
PDFController * | ctrl, | |||
PluginRenderResultImpl * | render_res, | |||
int | id = PRERENDER_REF_ID | |||
) |
Definition at line 48 of file pdf_render_task.cpp.
References pdf::TASK_RENDER, and pdf::Task::type.
00051 : page(p) 00052 , page_number(page->get_page_num()) 00053 , page_render_attr(attr) 00054 , doc_ctrl(ctrl) 00055 , ref_id(id) 00056 , render_result(render_res) 00057 { 00058 type = TASK_RENDER; 00059 }
pdf::PDFRenderTask::~PDFRenderTask | ( | ) | [virtual] |
Definition at line 61 of file pdf_render_task.cpp.
void pdf::PDFRenderTask::execute | ( | void | ) | [virtual] |
execute the rendering task
Implements pdf::Task.
Definition at line 65 of file pdf_render_task.cpp.
References ERRORPRINTF, pdf::PDFRenderer::gen_page(), pdf::PDFPage::get_content_area(), pdf::PDFController::get_page(), pdf::PDFController::get_page_crop_height(), pdf::PDFController::get_page_crop_width(), pdf::PDFRenderAttributes::get_real_zoom_value(), pdf::PDFPage::get_render_attr(), pdf::PDFPage::get_render_status(), pdf::PDFController::get_renderer(), pdf::PDFRenderer::handle_page_ready(), pdf::PDFLibrary::instance(), pdf::Task::is_aborted(), pdf::PDFPage::length(), LOGPRINTF, PLUGIN_ZOOM_TO_CROP_BY_PAGE, PLUGIN_ZOOM_TO_CROP_BY_WIDTH, pdf::PDFPage::RENDER_DONE, pdf::PDFPage::render_splash_map(), pdf::PDFPage::RENDER_STOP, pdf::PDFPage::render_text(), pdf::PluginRenderResultImpl::set_discard(), pdf::PluginRenderResultImpl::set_page(), pdf::PDFPage::set_ref_id(), pdf::PDFPage::set_render_attr(), pdf::TASK_RENDER_DONE, pdf::TASK_RENDER_OOM, and WARNPRINTF.
00066 { 00067 // don't execute the prerender task if the page is out of date 00068 if (is_page_out_of_date()) 00069 { 00070 return; 00071 } 00072 00073 PDFRenderer *renderer = doc_ctrl->get_renderer(); 00074 00075 // estimate whether the page has been cached 00076 // it is necessary here although there is same estimation 00077 // in main thread, because the same page might be constructed 00078 // in other tasks. 00079 if (page == 0) 00080 { 00081 page = doc_ctrl->get_page(page_number); 00082 00083 if (page == 0) 00084 { 00085 page = renderer->gen_page(page_number, page_render_attr); 00086 } 00087 } 00088 00089 //assert(page); 00090 if (page == 0) 00091 { 00092 ERRORPRINTF("Cannot Create New Page"); 00093 return; 00094 } 00095 00096 // set the reference id, this operation is thread-safe now 00097 // NOTE: this function must be called before setting render attributes 00098 // because the main thread would update the ref id if the render attributes 00099 // changes. 00100 page->set_ref_id(ref_id); 00101 00102 // if it is ZOOM_AUTO_CROP mode, it means it is necessary to get the content 00103 // area of the page 00104 double real_zoom = page_render_attr.get_real_zoom_value(); 00105 if (real_zoom == PLUGIN_ZOOM_TO_CROP_BY_PAGE || 00106 real_zoom == PLUGIN_ZOOM_TO_CROP_BY_WIDTH) 00107 { 00108 RenderArea content_area; 00109 if (!page->get_content_area(renderer, content_area)) 00110 { 00111 ERRORPRINTF("Cannot get content area of page:%d", page_number); 00112 return; 00113 } 00114 PDFRenderAttributes origin_attr = page_render_attr; 00115 renderer->calc_real_zoom(page_number, origin_attr, page_render_attr); 00116 real_zoom = page_render_attr.get_real_zoom_value(); 00117 } 00118 00119 // if the page is cached and the bitmap has been rendered 00120 // calculate the delta value. Becuase the old bitmap would 00121 // be destroyed and new one is going to be rendered in the following 00122 // step 00123 int page_len = static_cast<int>(page->length()); 00124 00125 page_len = static_cast<int>(PDFPage::try_calc_length(real_zoom, 00126 doc_ctrl->get_page_crop_width(page_number), 00127 doc_ctrl->get_page_crop_height(page_number))) - 00128 page_len; 00129 00130 PDFPage::RenderStatus cur_status = page->get_render_status(); 00131 if (!(page->get_render_attr() == page_render_attr)) 00132 { 00133 // if the render attributes change, re-render the page 00134 // DO NOT update the render setting here, because it might 00135 // change the length of page 00136 // DO NOT change the status of page at this moment 00137 cur_status = PDFPage::RENDER_STOP; 00138 } 00139 00140 bool render_done = true; 00141 00142 // render bitmap 00143 if (cur_status != PDFPage::RENDER_DONE) 00144 { 00145 LOGPRINTF("Task, Render Page:%d, Ref ID:%d, Current Task:%p", page_number, ref_id, this); 00146 // update the page cache to make sure there is enough memory 00147 // if page_len < 0, it means the page is going to shrink, the memory 00148 // must be enough 00149 // TODO. Add the page number as one parameter for making enough memory 00150 // The pages with lower priorites would be released. 00151 if (page_len > 0 && 00152 !PDFLibrary::instance().make_enough_memory(doc_ctrl, 00153 page_number, 00154 page_len)) 00155 { 00156 WARNPRINTF("Cannot make enough memory to implement rendering"); 00157 00158 // notify uds that it is out of memory that the page rendering 00159 // is aborted 00160 renderer->handle_page_ready(render_result, page, TASK_RENDER_OOM); 00161 return; 00162 } 00163 00164 // update the render status 00165 page->set_render_status(cur_status); 00166 00167 // only set the render attributes 00168 page->set_render_attr(page_render_attr); 00169 00170 render_done = page->render_splash_map(renderer 00171 , static_cast<void*>(this)); 00172 00173 // render the text page when the render is done 00174 if (render_done) 00175 { 00176 page->render_text(renderer); 00177 } 00178 } 00179 00180 if (render_done) 00181 { 00182 // set the render status at last 00183 page->set_render_status(PDFPage::RENDER_DONE); 00184 00185 if (render_result != 0) 00186 { 00187 // set the page into render result 00188 render_result->set_page(page); 00189 } 00190 00191 // notify uds that the page is ready 00192 renderer->handle_page_ready(render_result, page, TASK_RENDER_DONE); 00193 } 00194 else 00195 { 00196 if (render_result != 0 && is_aborted()) 00197 { 00198 // if the task is aborted, set the render result to "Discard" 00199 render_result->set_discard(true); 00200 } 00201 else 00202 { 00203 renderer->handle_page_ready(render_result, page, TASK_RENDER_OOM); 00204 } 00205 } 00206 00207 }
unsigned int pdf::PDFRenderTask::get_id | ( | ) | [virtual] |
void * pdf::PDFRenderTask::get_user_data | ( | ) | [virtual] |
get the pointer of PDFController intance
Implements pdf::Task.
Definition at line 233 of file pdf_render_task.cpp.
Referenced by pdf::PDFRenderer::post_render_task().