summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/canvas.cc
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@theqtcompany.com>2014-12-05 15:04:29 +0100
committerAndras Becsi <andras.becsi@theqtcompany.com>2014-12-09 10:49:28 +0100
commitaf6588f8d723931a298c995fa97259bb7f7deb55 (patch)
tree060ca707847ba1735f01af2372e0d5e494dc0366 /chromium/ui/gfx/canvas.cc
parent2fff84d821cc7b1c785f6404e0f8091333283e74 (diff)
downloadqtwebengine-chromium-af6588f8d723931a298c995fa97259bb7f7deb55.tar.gz
BASELINE: Update chromium to 40.0.2214.28 and ninja to 1.5.3.
Change-Id: I759465284fd64d59ad120219cbe257f7402c4181 Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/ui/gfx/canvas.cc')
-rw-r--r--chromium/ui/gfx/canvas.cc39
1 files changed, 22 insertions, 17 deletions
diff --git a/chromium/ui/gfx/canvas.cc b/chromium/ui/gfx/canvas.cc
index db8b28fc0a9..7508e689708 100644
--- a/chromium/ui/gfx/canvas.cc
+++ b/chromium/ui/gfx/canvas.cc
@@ -12,7 +12,10 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/gfx/font_list.h"
+#include "ui/gfx/geometry/rect_conversions.h"
+#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/rect.h"
+#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/transform.h"
@@ -89,12 +92,12 @@ void Canvas::SizeStringInt(const base::string16& text,
int* height,
int line_height,
int flags) {
- float fractional_width = *width;
- float factional_height = *height;
+ float fractional_width = static_cast<float>(*width);
+ float factional_height = static_cast<float>(*height);
SizeStringFloat(text, font_list, &fractional_width,
&factional_height, line_height, flags);
- *width = std::ceil(fractional_width);
- *height = std::ceil(factional_height);
+ *width = ToCeiledInt(fractional_width);
+ *height = ToCeiledInt(factional_height);
}
// static
@@ -131,6 +134,8 @@ ImageSkiaRep Canvas::ExtractImageRep() const {
}
void Canvas::DrawDashedRect(const Rect& rect, SkColor color) {
+ if (rect.IsEmpty())
+ return;
// Create a 2D bitmap containing alternating on/off pixels - we do this
// so that you never get two pixels of the same color around the edges
// of the focus rect (this may mean that opposing edges of the rect may
@@ -207,9 +212,12 @@ bool Canvas::IsClipEmpty() const {
bool Canvas::GetClipBounds(Rect* bounds) {
SkRect out;
- bool has_non_empty_clip = canvas_->getClipBounds(&out);
- bounds->SetRect(out.left(), out.top(), out.width(), out.height());
- return has_non_empty_clip;
+ if (canvas_->getClipBounds(&out)) {
+ *bounds = ToEnclosingRect(SkRectToRectF(out));
+ return true;
+ }
+ *bounds = gfx::Rect();
+ return false;
}
void Canvas::Translate(const Vector2d& offset) {
@@ -340,14 +348,13 @@ void Canvas::DrawImageInt(const ImageSkia& image,
const SkBitmap& bitmap = image_rep.sk_bitmap();
float bitmap_scale = image_rep.scale();
- canvas_->save();
+ ScopedCanvas scoper(this);
canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
SkFloatToScalar(1.0f / bitmap_scale));
canvas_->drawBitmap(bitmap,
SkFloatToScalar(x * bitmap_scale),
SkFloatToScalar(y * bitmap_scale),
&paint);
- canvas_->restore();
}
void Canvas::DrawImageInt(const ImageSkia& image,
@@ -409,13 +416,14 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image,
// Ensure that the direction of the x and y scales is preserved. This is
// important for RTL layouts.
- matrix.getScaleX() > 0 ? matrix.setScaleX(1.0f) : matrix.setScaleX(-1.0f);
- matrix.getScaleY() > 0 ? matrix.setScaleY(1.0f) : matrix.setScaleY(-1.0f);
+ matrix.setScaleX(matrix.getScaleX() > 0 ? 1.0f : -1.0f);
+ matrix.setScaleY(matrix.getScaleY() > 0 ? 1.0f : -1.0f);
- matrix.setTranslateX(SkScalarRoundToInt(matrix.getTranslateX()));
- matrix.setTranslateY(SkScalarRoundToInt(matrix.getTranslateY()));
+ // Floor so that we get consistent rounding.
+ matrix.setTranslateX(SkScalarFloorToScalar(matrix.getTranslateX()));
+ matrix.setTranslateY(SkScalarFloorToScalar(matrix.getTranslateY()));
- Save();
+ ScopedCanvas scoper(this);
canvas_->setMatrix(matrix);
@@ -432,9 +440,6 @@ void Canvas::DrawImageIntInPixel(const ImageSkia& image,
paint,
image_scale_,
true);
-
- // Restore the state of the canvas.
- Restore();
}
void Canvas::DrawImageInPath(const ImageSkia& image,