| Index: ui/gfx/canvas_skia.cc
|
| ===================================================================
|
| --- ui/gfx/canvas_skia.cc (revision 82144)
|
| +++ ui/gfx/canvas_skia.cc (working copy)
|
| @@ -47,6 +47,12 @@
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // CanvasSkia, public:
|
|
|
| +CanvasSkia::CanvasSkia() {
|
| +}
|
| +
|
| +CanvasSkia::~CanvasSkia() {
|
| +}
|
| +
|
| // static
|
| int CanvasSkia::DefaultCanvasTextAlignment() {
|
| if (!base::i18n::IsRTL())
|
| @@ -54,8 +60,14 @@
|
| return gfx::Canvas::TEXT_ALIGN_RIGHT;
|
| }
|
|
|
| +bool CanvasSkia::Init(int width, int height, bool is_opaque) {
|
| + skia_canvas_.reset(skia::CreateBitmapCanvas(width, height, is_opaque));
|
| + return skia_canvas_.get() ? true : false;
|
| +}
|
| +
|
| SkBitmap CanvasSkia::ExtractBitmap() const {
|
| - const SkBitmap& device_bitmap = getDevice()->accessBitmap(false);
|
| + const SkBitmap& device_bitmap =
|
| + skia_canvas_->getDevice()->accessBitmap(false);
|
|
|
| // Make a bitmap to return, and a canvas to draw into it. We don't just want
|
| // to call extractSubset or the copy constructor, since we want an actual copy
|
| @@ -69,11 +81,11 @@
|
| // CanvasSkia, Canvas implementation:
|
|
|
| void CanvasSkia::Save() {
|
| - save();
|
| + skia_canvas_->save();
|
| }
|
|
|
| void CanvasSkia::SaveLayerAlpha(uint8 alpha) {
|
| - saveLayerAlpha(NULL, alpha);
|
| + skia_canvas_->saveLayerAlpha(NULL, alpha);
|
| }
|
|
|
|
|
| @@ -83,26 +95,26 @@
|
| SkIntToScalar(layer_bounds.y()),
|
| SkIntToScalar(layer_bounds.right()),
|
| SkIntToScalar(layer_bounds.bottom()));
|
| - saveLayerAlpha(&bounds, alpha);
|
| + skia_canvas_->saveLayerAlpha(&bounds, alpha);
|
| }
|
|
|
| void CanvasSkia::Restore() {
|
| - restore();
|
| + skia_canvas_->restore();
|
| }
|
|
|
| bool CanvasSkia::ClipRectInt(int x, int y, int w, int h) {
|
| SkRect new_clip;
|
| new_clip.set(SkIntToScalar(x), SkIntToScalar(y),
|
| SkIntToScalar(x + w), SkIntToScalar(y + h));
|
| - return clipRect(new_clip);
|
| + return skia_canvas_->clipRect(new_clip);
|
| }
|
|
|
| void CanvasSkia::TranslateInt(int x, int y) {
|
| - translate(SkIntToScalar(x), SkIntToScalar(y));
|
| + skia_canvas_->translate(SkIntToScalar(x), SkIntToScalar(y));
|
| }
|
|
|
| void CanvasSkia::ScaleInt(int x, int y) {
|
| - scale(SkIntToScalar(x), SkIntToScalar(y));
|
| + skia_canvas_->scale(SkIntToScalar(x), SkIntToScalar(y));
|
| }
|
|
|
| void CanvasSkia::FillRectInt(const SkColor& color, int x, int y, int w, int h) {
|
| @@ -149,7 +161,7 @@
|
|
|
| void CanvasSkia::DrawRectInt(int x, int y, int w, int h, const SkPaint& paint) {
|
| SkIRect rc = { x, y, x + w, y + h };
|
| - drawIRect(rc, paint);
|
| + skia_canvas_->drawIRect(rc, paint);
|
| }
|
|
|
| void CanvasSkia::DrawLineInt(const SkColor& color,
|
| @@ -158,8 +170,9 @@
|
| SkPaint paint;
|
| paint.setColor(color);
|
| paint.setStrokeWidth(SkIntToScalar(1));
|
| - drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2),
|
| - SkIntToScalar(y2), paint);
|
| + skia_canvas_->drawLine(SkIntToScalar(x1), SkIntToScalar(y1),
|
| + SkIntToScalar(x2), SkIntToScalar(y2),
|
| + paint);
|
| }
|
|
|
| void CanvasSkia::DrawFocusRect(int x, int y, int width, int height) {
|
| @@ -207,13 +220,13 @@
|
| }
|
|
|
| void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) {
|
| - drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y));
|
| + skia_canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y));
|
| }
|
|
|
| void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap,
|
| int x, int y,
|
| const SkPaint& paint) {
|
| - drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
|
| + skia_canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
|
| }
|
|
|
| void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap,
|
| @@ -249,7 +262,7 @@
|
| // Workaround for apparent bug in Skia that causes image to occasionally
|
| // shift.
|
| SkIRect src_rect = { src_x, src_y, src_x + src_w, src_y + src_h };
|
| - drawBitmapRect(bitmap, &src_rect, dest_rect, &paint);
|
| + skia_canvas_->drawBitmapRect(bitmap, &src_rect, dest_rect, &paint);
|
| return;
|
| }
|
|
|
| @@ -275,7 +288,7 @@
|
| shader->unref();
|
|
|
| // The rect will be filled by the bitmap.
|
| - drawRect(dest_rect, p);
|
| + skia_canvas_->drawRect(dest_rect, p);
|
| }
|
|
|
| void CanvasSkia::DrawStringInt(const string16& text,
|
| @@ -316,23 +329,25 @@
|
| // CreateBitmapShader returns a Shader with a reference count of one, we
|
| // need to unref after paint takes ownership of the shader.
|
| shader->unref();
|
| - save();
|
| - translate(SkIntToScalar(dest_x - src_x), SkIntToScalar(dest_y - src_y));
|
| + skia_canvas_->save();
|
| + skia_canvas_->translate(SkIntToScalar(dest_x - src_x),
|
| + SkIntToScalar(dest_y - src_y));
|
| ClipRectInt(src_x, src_y, w, h);
|
| - drawPaint(paint);
|
| - restore();
|
| + skia_canvas_->drawPaint(paint);
|
| + skia_canvas_->restore();
|
| }
|
|
|
| gfx::NativeDrawingContext CanvasSkia::BeginPlatformPaint() {
|
| - return beginPlatformPaint();
|
| + return skia::BeginPlatformPaint(skia_canvas_.get());
|
| }
|
|
|
| void CanvasSkia::EndPlatformPaint() {
|
| - endPlatformPaint();
|
| + skia::EndPlatformPaint(skia_canvas_.get());
|
| }
|
|
|
| void CanvasSkia::Transform(const ui::Transform& transform) {
|
| - concat(*reinterpret_cast<const ui::TransformSkia&>(transform).matrix_.get());
|
| + skia_canvas_->concat(
|
| + *reinterpret_cast<const ui::TransformSkia&>(transform).matrix_.get());
|
| }
|
|
|
| CanvasSkia* CanvasSkia::AsCanvasSkia() {
|
| @@ -348,7 +363,7 @@
|
|
|
| bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) {
|
| SkRect clip;
|
| - return getClipBounds(&clip) &&
|
| + return skia_canvas_->getClipBounds(&clip) &&
|
| clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w),
|
| SkIntToScalar(y + h));
|
| }
|
| @@ -361,33 +376,17 @@
|
| }
|
|
|
| Canvas* Canvas::CreateCanvas(int width, int height, bool is_opaque) {
|
| - return new CanvasSkia(width, height, is_opaque);
|
| + CanvasSkia* canvas = new CanvasSkia;
|
| + if (!canvas->Init(width, height, is_opaque)) {
|
| + delete canvas;
|
| + return NULL;
|
| + }
|
| + return canvas;
|
| }
|
|
|
| -#if defined(OS_WIN)
|
| -// TODO(beng): move to canvas_win.cc, etc.
|
| -class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint {
|
| - public:
|
| - CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {}
|
| -
|
| - // Overridden from CanvasPaint2:
|
| - virtual bool IsValid() const {
|
| - return isEmpty();
|
| - }
|
| -
|
| - virtual gfx::Rect GetInvalidRect() const {
|
| - return gfx::Rect(paintStruct().rcPaint);
|
| - }
|
| -
|
| - virtual Canvas* AsCanvas() {
|
| - return this;
|
| - }
|
| -};
|
| -#endif
|
| -
|
| CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) {
|
| #if defined(OS_WIN)
|
| - return new CanvasPaintWin(view);
|
| + return new CanvasSkiaPaint(view);
|
| #else
|
| return NULL;
|
| #endif
|
|
|