From affe4b09575b297747e66bd0b807d2b1b04822fe Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 23 Feb 2016 16:04:59 -0500 Subject: Remove FXSYS_Div. This is just a wrapper for (a) / (b). Inline the divide. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1727793002 . --- core/include/fxcrt/fx_system.h | 1 - core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 9 +++--- .../fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 32 ++++++++++++---------- core/src/fxcodec/codec/fx_codec_progress.cpp | 6 ++-- core/src/fxge/agg/src/fx_agg_driver.cpp | 4 +-- core/src/fxge/dib/fx_dib_engine.cpp | 10 +++---- core/src/fxge/ge/fx_ge_path.cpp | 6 ++-- core/src/fxge/win32/fx_win32_gdipext.cpp | 5 ++-- core/src/fxge/win32/fx_win32_print.cpp | 3 +- third_party/agg23/agg_clip_liang_barsky.h | 14 +++++----- third_party/agg23/agg_math_stroke.h | 11 ++++---- xfa/src/fxgraphics/src/fx_graphics.cpp | 14 +++++----- xfa/src/fxgraphics/src/fx_path_generator.cpp | 4 +-- 13 files changed, 59 insertions(+), 60 deletions(-) diff --git a/core/include/fxcrt/fx_system.h b/core/include/fxcrt/fx_system.h index 4eb217a094..920c821916 100644 --- a/core/include/fxcrt/fx_system.h +++ b/core/include/fxcrt/fx_system.h @@ -269,7 +269,6 @@ int64_t FXSYS_atoi64(const FX_CHAR* str); int64_t FXSYS_wtoi64(const FX_WCHAR* str); const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix); int FXSYS_round(FX_FLOAT f); -#define FXSYS_Div(a, b) ((a) / (b)) #define FXSYS_MulDiv(a, b, c) ((a) * (b) / (c)) #define FXSYS_sqrt2(a, b) (FX_FLOAT) FXSYS_sqrt((a) * (a) + (b) * (b)) #ifdef __cplusplus diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index 81cf92ee05..d589d5809f 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -752,11 +752,10 @@ void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, y2 = yPos; break; } - display_matrix.Set(FXSYS_Div((FX_FLOAT)(x2 - x0), m_PageWidth), - FXSYS_Div((FX_FLOAT)(y2 - y0), m_PageWidth), - FXSYS_Div((FX_FLOAT)(x1 - x0), m_PageHeight), - FXSYS_Div((FX_FLOAT)(y1 - y0), m_PageHeight), (FX_FLOAT)x0, - (FX_FLOAT)y0); + display_matrix.Set( + ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, + ((FX_FLOAT)(x1 - x0)) / m_PageHeight, + ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); matrix = m_PageMatrix; matrix.Concat(display_matrix); } diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index b9ff9f4750..43ce995f05 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -83,8 +83,8 @@ static void DrawAxialShading(CFX_DIBitmap* pBitmap, for (int column = 0; column < width; column++) { FX_FLOAT x = (FX_FLOAT)column, y = (FX_FLOAT)row; matrix.Transform(x, y); - FX_FLOAT scale = FXSYS_Div( - ((x - start_x) * x_span) + ((y - start_y) * y_span), axis_len_square); + FX_FLOAT scale = (((x - start_x) * x_span) + ((y - start_y) * y_span)) / + axis_len_square; int index = (int32_t)(scale * (SHADING_STEPS - 1)); if (index < 0) { if (!bStartExtend) { @@ -189,7 +189,7 @@ static void DrawRadialShading(CFX_DIBitmap* pBitmap, ((y - start_y) * (y - start_y)) - (start_r * start_r); FX_FLOAT s; if (a == 0) { - s = FXSYS_Div(-c, b); + s = -c / b; } else { FX_FLOAT b2_4ac = (b * b) - 4 * (a * c); if (b2_4ac < 0) { @@ -198,11 +198,11 @@ static void DrawRadialShading(CFX_DIBitmap* pBitmap, FX_FLOAT root = FXSYS_sqrt(b2_4ac); FX_FLOAT s1, s2; if (a > 0) { - s1 = FXSYS_Div(-b - root, 2 * a); - s2 = FXSYS_Div(-b + root, 2 * a); + s1 = (-b - root) / (2 * a); + s2 = (-b + root) / (2 * a); } else { - s2 = FXSYS_Div(-b - root, 2 * a); - s1 = FXSYS_Div(-b + root, 2 * a); + s2 = (-b - root) / (2 * a); + s1 = (-b + root) / (2 * a); } if (bDecreasing) { if (s1 >= 0 || bStartExtend) { @@ -1044,14 +1044,16 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, mtDevice2Pattern.SetReverse(mtPattern2Device); CFX_FloatRect clip_box_p(clip_box); clip_box_p.Transform(&mtDevice2Pattern); - min_col = (int)FXSYS_ceil( - FXSYS_Div(clip_box_p.left - pPattern->m_BBox.right, pPattern->m_XStep)); - max_col = (int)FXSYS_floor( - FXSYS_Div(clip_box_p.right - pPattern->m_BBox.left, pPattern->m_XStep)); - min_row = (int)FXSYS_ceil( - FXSYS_Div(clip_box_p.bottom - pPattern->m_BBox.top, pPattern->m_YStep)); - max_row = (int)FXSYS_floor( - FXSYS_Div(clip_box_p.top - pPattern->m_BBox.bottom, pPattern->m_YStep)); + + min_col = (int)FXSYS_ceil((clip_box_p.left - pPattern->m_BBox.right) / + pPattern->m_XStep); + max_col = (int)FXSYS_floor((clip_box_p.right - pPattern->m_BBox.left) / + pPattern->m_XStep); + min_row = (int)FXSYS_ceil((clip_box_p.bottom - pPattern->m_BBox.top) / + pPattern->m_YStep); + max_row = (int)FXSYS_floor((clip_box_p.top - pPattern->m_BBox.bottom) / + pPattern->m_YStep); + if (width > clip_box.Width() || height > clip_box.Height() || width * height > clip_box.Width() * clip_box.Height()) { CPDF_GraphicStates* pStates = NULL; diff --git a/core/src/fxcodec/codec/fx_codec_progress.cpp b/core/src/fxcodec/codec/fx_codec_progress.cpp index 2e9b1dce3e..1b46c4eb22 100644 --- a/core/src/fxcodec/codec/fx_codec_progress.cpp +++ b/core/src/fxcodec/codec/fx_codec_progress.cpp @@ -18,7 +18,7 @@ void CFXCODEC_WeightTable::Calc(int dest_len, FX_Free(m_pWeightTables); } double scale, base; - scale = FXSYS_Div((FX_FLOAT)(src_len), (FX_FLOAT)(dest_len)); + scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; if (dest_len < 0) { base = (FX_FLOAT)(src_len); } else { @@ -88,8 +88,8 @@ void CFXCODEC_WeightTable::Calc(int dest_len, pixel_weights.m_SrcStart = start_i; pixel_weights.m_SrcEnd = end_i; for (int j = start_i; j <= end_i; j++) { - double dest_start = FXSYS_Div((FX_FLOAT)(j)-base, scale); - double dest_end = FXSYS_Div((FX_FLOAT)(j + 1) - base, scale); + double dest_start = ((FX_FLOAT)j - base) / scale; + double dest_end = ((FX_FLOAT)(j + 1) - base) / scale; if (dest_start > dest_end) { double temp = dest_start; dest_start = dest_end; diff --git a/core/src/fxge/agg/src/fx_agg_driver.cpp b/core/src/fxge/agg/src/fx_agg_driver.cpp index 50062541b1..8b0e3f94f4 100644 --- a/core/src/fxge/agg/src/fx_agg_driver.cpp +++ b/core/src/fxge/agg/src/fx_agg_driver.cpp @@ -144,8 +144,8 @@ static void RasterizeStroke(agg::rasterizer_scanline_aa& rasterizer, FX_FLOAT width = pGraphState->m_LineWidth * scale; FX_FLOAT unit = 1.f; if (pObject2Device) { - unit = FXSYS_Div( - 1.0f, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2); + unit = + 1.0f / ((pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2); } if (width < unit) { width = unit; diff --git a/core/src/fxge/dib/fx_dib_engine.cpp b/core/src/fxge/dib/fx_dib_engine.cpp index 47fca79846..322040539e 100644 --- a/core/src/fxge/dib/fx_dib_engine.cpp +++ b/core/src/fxge/dib/fx_dib_engine.cpp @@ -20,7 +20,7 @@ void CWeightTable::Calc(int dest_len, FX_Free(m_pWeightTables); m_pWeightTables = NULL; double scale, base; - scale = FXSYS_Div((FX_FLOAT)(src_len), (FX_FLOAT)(dest_len)); + scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; if (dest_len < 0) { base = (FX_FLOAT)(src_len); } else { @@ -188,8 +188,8 @@ void CWeightTable::Calc(int dest_len, pixel_weights.m_SrcStart = start_i; pixel_weights.m_SrcEnd = end_i; for (int j = start_i; j <= end_i; j++) { - double dest_start = FXSYS_Div((FX_FLOAT)(j)-base, scale); - double dest_end = FXSYS_Div((FX_FLOAT)(j + 1) - base, scale); + double dest_start = ((FX_FLOAT)j - base) / scale; + double dest_end = ((FX_FLOAT)(j + 1) - base) / scale; if (dest_start > dest_end) { double temp = dest_start; dest_start = dest_end; @@ -270,8 +270,8 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, m_Flags |= FXDIB_DOWNSAMPLE; } } - double scale_x = FXSYS_Div((FX_FLOAT)(m_SrcWidth), (FX_FLOAT)(m_DestWidth)); - double scale_y = FXSYS_Div((FX_FLOAT)(m_SrcHeight), (FX_FLOAT)(m_DestHeight)); + double scale_x = (FX_FLOAT)m_SrcWidth / (FX_FLOAT)m_DestWidth; + double scale_y = (FX_FLOAT)m_SrcHeight / (FX_FLOAT)m_DestHeight; double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth); double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight); double src_left = scale_x * ((FX_FLOAT)(clip_rect.left) + base_x); diff --git a/core/src/fxge/ge/fx_ge_path.cpp b/core/src/fxge/ge/fx_ge_path.cpp index 0084f092d1..0c24c0ff64 100644 --- a/core/src/fxge/ge/fx_ge_path.cpp +++ b/core/src/fxge/ge/fx_ge_path.cpp @@ -263,14 +263,14 @@ static void _UpdateLineJoinPoints(CFX_FloatRect& rect, return; } if (!bStartVert) { - start_k = FXSYS_Div(middle_y - start_y, middle_x - start_x); + start_k = (middle_y - start_y) / (middle_x - start_x); start_c = middle_y - (start_k * middle_x); start_len = FXSYS_sqrt2(start_x - middle_x, start_y - middle_y); start_dc = (FX_FLOAT)FXSYS_fabs( FXSYS_MulDiv(half_width, start_len, start_x - middle_x)); } if (!bEndVert) { - end_k = FXSYS_Div(end_y - middle_y, end_x - middle_x); + end_k = (end_y - middle_y) / (end_x - middle_x); end_c = middle_y - (end_k * middle_x); end_len = FXSYS_sqrt2(end_x - middle_x, end_y - middle_y); end_dc = (FX_FLOAT)FXSYS_fabs( @@ -331,7 +331,7 @@ static void _UpdateLineJoinPoints(CFX_FloatRect& rect, } else { end_outside_c -= end_dc; } - FX_FLOAT join_x = FXSYS_Div(end_outside_c - start_outside_c, start_k - end_k); + FX_FLOAT join_x = (end_outside_c - start_outside_c) / (start_k - end_k); FX_FLOAT join_y = (start_k * join_x) + start_outside_c; rect.UpdateRect(join_x, join_y); } diff --git a/core/src/fxge/win32/fx_win32_gdipext.cpp b/core/src/fxge/win32/fx_win32_gdipext.cpp index ce280948d7..e71d94d310 100644 --- a/core/src/fxge/win32/fx_win32_gdipext.cpp +++ b/core/src/fxge/win32/fx_win32_gdipext.cpp @@ -973,9 +973,8 @@ static GpPen* _GdipCreatePen(const CFX_GraphStateData* pGraphState, FX_FLOAT width = pGraphState ? pGraphState->m_LineWidth : 1.0f; if (!bTextMode) { FX_FLOAT unit = - pMatrix - ? FXSYS_Div(1.0f, (pMatrix->GetXUnit() + pMatrix->GetYUnit()) / 2) - : 1.0f; + pMatrix ? 1.0f / ((pMatrix->GetXUnit() + pMatrix->GetYUnit()) / 2) + : 1.0f; if (width < unit) { width = unit; } diff --git a/core/src/fxge/win32/fx_win32_print.cpp b/core/src/fxge/win32/fx_win32_print.cpp index 4816c03e2c..6c262d83dc 100644 --- a/core/src/fxge/win32/fx_win32_print.cpp +++ b/core/src/fxge/win32/fx_win32_print.cpp @@ -149,8 +149,7 @@ static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc, uint8_t* src_buf = pSrcBitmap->GetBuffer(); FX_DWORD src_pitch = pSrcBitmap->GetPitch(); FX_FLOAT dest_area = pDestMatrix->GetUnitArea(); - FX_FLOAT area_scale = - FXSYS_Div((FX_FLOAT)(src_width * src_height), dest_area); + FX_FLOAT area_scale = ((FX_FLOAT)(src_width * src_height)) / dest_area; FX_FLOAT size_scale = FXSYS_sqrt(area_scale); CFX_Matrix adjusted_matrix(*pDestMatrix); adjusted_matrix.Scale(size_scale, size_scale); diff --git a/third_party/agg23/agg_clip_liang_barsky.h b/third_party/agg23/agg_clip_liang_barsky.h index 13e4ab9e30..db6ca97505 100644 --- a/third_party/agg23/agg_clip_liang_barsky.h +++ b/third_party/agg23/agg_clip_liang_barsky.h @@ -50,7 +50,7 @@ inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2, xin = (FX_FLOAT)clip_box.x2; xout = (FX_FLOAT)clip_box.x1; } - FX_FLOAT tinx = FXSYS_Div(xin - x1, deltax); + FX_FLOAT tinx = (xin - x1) / deltax; if(deltay == 0) { deltay = (y1 > clip_box.y1) ? -nearzero : nearzero; } @@ -62,7 +62,7 @@ inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2, yin = (FX_FLOAT)clip_box.y2; yout = (FX_FLOAT)clip_box.y1; } - FX_FLOAT tiny = FXSYS_Div(yin - y1, deltay); + FX_FLOAT tiny = (yin - y1) / deltay; FX_FLOAT tin1, tin2; if (tinx < tiny) { tin1 = tinx; @@ -78,10 +78,10 @@ inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2, ++np; } if(tin2 <= 1.0f) { - FX_FLOAT toutx = FXSYS_Div(xout - x1, deltax); - FX_FLOAT touty = FXSYS_Div(yout - y1, deltay); - FX_FLOAT tout1 = (toutx < touty) ? toutx : touty; - if(tin2 > 0 || tout1 > 0) { + FX_FLOAT toutx = (xout - x1) / deltax; + FX_FLOAT touty = (yout - y1) / deltay; + FX_FLOAT tout1 = (toutx < touty) ? toutx : touty; + if (tin2 > 0 || tout1 > 0) { if(tin2 <= tout1) { if(tin2 > 0) { if(tinx > tiny) { @@ -116,7 +116,7 @@ inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2, } ++np; } - } + } } } return np; diff --git a/third_party/agg23/agg_math_stroke.h b/third_party/agg23/agg_math_stroke.h index ff42b2291e..402028ba67 100644 --- a/third_party/agg23/agg_math_stroke.h +++ b/third_party/agg23/agg_math_stroke.h @@ -58,7 +58,7 @@ void stroke_calc_arc(VertexConsumer& out_vertices, if(width < 0) { width = -width; } - da = FXSYS_acos(FXSYS_Div(width, width + FXSYS_Div(1.0f / 8, approximation_scale))) * 2; + da = FXSYS_acos(width / (width + ((1.0f / 8) / approximation_scale))) * 2; out_vertices.add(coord_type(x + dx1, y + dy1)); if(!ccw) { if(a1 > a2) { @@ -152,8 +152,8 @@ void stroke_calc_cap(VertexConsumer& out_vertices, { typedef typename VertexConsumer::value_type coord_type; out_vertices.remove_all(); - FX_FLOAT dx1 = FXSYS_Div(v1.y - v0.y, len); - FX_FLOAT dy1 = FXSYS_Div(v1.x - v0.x, len); + FX_FLOAT dx1 = (v1.y - v0.y) / len; + FX_FLOAT dy1 = (v1.x - v0.x) / len; FX_FLOAT dx2 = 0; FX_FLOAT dy2 = 0; dx1 = dx1 * width; @@ -168,8 +168,9 @@ void stroke_calc_cap(VertexConsumer& out_vertices, } else { FX_FLOAT a1 = FXSYS_atan2(dy1, -dx1); FX_FLOAT a2 = a1 + FX_PI; - FX_FLOAT da = FXSYS_acos(FXSYS_Div(width, width + - FXSYS_Div(1.0f / 8, approximation_scale))) * 2; + FX_FLOAT da = + FXSYS_acos(width / (width + ((1.0f / 8) / approximation_scale))) * + 2; out_vertices.add(coord_type(v0.x - dx1, v0.y + dy1)); a1 += da; a2 -= da / 4; diff --git a/xfa/src/fxgraphics/src/fx_graphics.cpp b/xfa/src/fxgraphics/src/fx_graphics.cpp index 2ad7cd5d0c..792f517a09 100644 --- a/xfa/src/fxgraphics/src/fx_graphics.cpp +++ b/xfa/src/fxgraphics/src/fx_graphics.cpp @@ -978,8 +978,8 @@ FX_ERR CFX_Graphics::FillPathWithShading(CFX_Path* path, FX_FLOAT x = (FX_FLOAT)(column); FX_FLOAT y = (FX_FLOAT)(row); FX_FLOAT scale = - FXSYS_Div(((x - start_x) * x_span) + ((y - start_y) * y_span), - axis_len_square); + (((x - start_x) * x_span) + ((y - start_y) * y_span)) / + axis_len_square; if (scale < 0) { if (!_info._fillColor->_shading->_isExtendedBegin) { continue; @@ -1016,7 +1016,7 @@ FX_ERR CFX_Graphics::FillPathWithShading(CFX_Path* path, ((y - start_y) * (y - start_y)) - (start_r * start_r); FX_FLOAT s; if (a == 0) { - s = (FXSYS_Div(-c, b)); + s = -c / b; } else { FX_FLOAT b2_4ac = (b * b) - 4 * (a * c); if (b2_4ac < 0) { @@ -1025,11 +1025,11 @@ FX_ERR CFX_Graphics::FillPathWithShading(CFX_Path* path, FX_FLOAT root = (FXSYS_sqrt(b2_4ac)); FX_FLOAT s1, s2; if (a > 0) { - s1 = FXSYS_Div(-b - root, 2 * a); - s2 = FXSYS_Div(-b + root, 2 * a); + s1 = (-b - root) / (2 * a); + s2 = (-b + root) / (2 * a); } else { - s2 = FXSYS_Div(-b - root, 2 * a); - s1 = FXSYS_Div(-b + root, 2 * a); + s2 = (-b - root) / (2 * a); + s1 = (-b + root) / (2 * a); } if (s2 <= 1.0f || _info._fillColor->_shading->_isExtendedEnd) { s = (s2); diff --git a/xfa/src/fxgraphics/src/fx_path_generator.cpp b/xfa/src/fxgraphics/src/fx_path_generator.cpp index c9e20b35d2..b37105fae8 100644 --- a/xfa/src/fxgraphics/src/fx_path_generator.cpp +++ b/xfa/src/fxgraphics/src/fx_path_generator.cpp @@ -119,8 +119,8 @@ void CFX_PathGenerator::ArcTo(FX_FLOAT x, FX_FLOAT sweep_angle) { FX_FLOAT x0 = FXSYS_cos(sweep_angle / 2); FX_FLOAT y0 = FXSYS_sin(sweep_angle / 2); - FX_FLOAT tx = FXSYS_Div((1.0f - x0) * 4, 3 * 1.0f); - FX_FLOAT ty = y0 - FXSYS_Div(tx * x0, y0); + FX_FLOAT tx = ((1.0f - x0) * 4) / (3 * 1.0f); + FX_FLOAT ty = y0 - ((tx * x0) / y0); FX_FLOAT px[3], py[3]; px[0] = x0 + tx; py[0] = -ty; -- cgit v1.2.3