OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/canvas_skia_paint_linux.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/gfx/canvas_skia.h" |
| 9 #include "ui/gfx/rect.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 CanvasSkiaPaint::CanvasSkiaPaint(GdkEventExpose* event, bool opaque) |
| 14 : window_(event->window), |
| 15 region_(gdk_region_copy(event->region)) { |
| 16 CHECK(InitCanvas()); |
| 17 } |
| 18 |
| 19 CanvasSkiaPaint::~CanvasSkiaPaint() { |
| 20 canvas_->skia_canvas()->restoreToCount(1); |
| 21 |
| 22 if (!IsValid()) { |
| 23 // Blit the dirty rect to the window. |
| 24 CHECK(window_); |
| 25 cairo_t* dst_context = gdk_cairo_create(window_); |
| 26 CHECK(dst_context); |
| 27 cairo_surface_t* src_surface = cairo_get_target( |
| 28 canvas_->BeginPlatformPaint()); |
| 29 CHECK(src_surface); |
| 30 // Flush cairo's cache of the surface. |
| 31 cairo_surface_mark_dirty(src_surface); |
| 32 gfx::Rect rect = GetInvalidRect(); |
| 33 cairo_set_source_surface(dst_context, src_surface, rect.x(), rect.y()); |
| 34 gdk_cairo_region(dst_context, region_); |
| 35 cairo_fill(dst_context); |
| 36 cairo_destroy(dst_context); |
| 37 canvas_->EndPlatformPaint(); |
| 38 } |
| 39 |
| 40 gdk_region_destroy(region_); |
| 41 } |
| 42 |
| 43 bool CanvasSkiaPaint::IsValid() const { |
| 44 return gdk_region_empty(region_); |
| 45 } |
| 46 |
| 47 gfx::Rect CanvasSkiaPaint::GetInvalidRect() const { |
| 48 GdkRectangle invalid_rect; |
| 49 gdk_region_get_clipbox(region_, &invalid_rect); |
| 50 return gfx::Rect(invalid_rect); |
| 51 } |
| 52 |
| 53 Canvas* CanvasSkiaPaint::AsCanvas() { |
| 54 return canvas_.get(); |
| 55 } |
| 56 |
| 57 bool CanvasSkiaPaint::InitCanvas() { |
| 58 gfx::Rect rect = GetInvalidRect(); |
| 59 canvas_.reset(new CanvasSkia); |
| 60 if (!canvas_->Init(rect.width(), rect.height(), true)) |
| 61 return false; |
| 62 |
| 63 // Translate so that the dirty region appears at the origin. |
| 64 canvas_->skia_canvas()->translate(-SkIntToScalar(rect.x()), |
| 65 -SkIntToScalar(rect.y())); |
| 66 return true; |
| 67 } |
| 68 |
| 69 } // namespace gfx |
OLD | NEW |