| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "skia/ext/vector_platform_device_cairo_linux.h" | 5 #include "skia/ext/vector_platform_device_cairo_linux.h" |
| 6 | 6 |
| 7 #include <cairo.h> | 7 #include <cairo.h> |
| 8 #include <cairo-ft.h> | 8 #include <cairo-ft.h> |
| 9 | 9 |
| 10 #include <ft2build.h> | 10 #include <ft2build.h> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Verify cairo surface after creation/modification. | 62 // Verify cairo surface after creation/modification. |
| 63 bool IsContextValid(cairo_t* context) { | 63 bool IsContextValid(cairo_t* context) { |
| 64 return cairo_status(context) == CAIRO_STATUS_SUCCESS; | 64 return cairo_status(context) == CAIRO_STATUS_SUCCESS; |
| 65 } | 65 } |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 namespace skia { | 69 namespace skia { |
| 70 | 70 |
| 71 // static | 71 // static |
| 72 PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, | 72 SkDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, int width, |
| 73 int width, int height, | 73 int height, bool isOpaque) { |
| 74 bool isOpaque) { | |
| 75 // TODO(myhuang): Here we might also have similar issues as those on Windows | 74 // TODO(myhuang): Here we might also have similar issues as those on Windows |
| 76 // (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383). | 75 // (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383). |
| 77 // Please note that is_opaque is true when we use this class for printing. | 76 // Please note that is_opaque is true when we use this class for printing. |
| 78 // Fallback to bitmap when context is NULL. | 77 // Fallback to bitmap when context is NULL. |
| 79 if (!isOpaque || NULL == context) { | 78 if (!isOpaque || NULL == context) { |
| 80 return BitmapPlatformDevice::Create(width, height, isOpaque); | 79 return BitmapPlatformDevice::Create(width, height, isOpaque); |
| 81 } | 80 } |
| 82 | 81 |
| 83 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); | 82 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); |
| 84 SkASSERT(width > 0); | 83 SkASSERT(width > 0); |
| 85 SkASSERT(height > 0); | 84 SkASSERT(height > 0); |
| 86 | 85 |
| 87 SkBitmap bitmap; | 86 SkBitmap bitmap; |
| 88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 87 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 89 | 88 |
| 90 return new VectorPlatformDeviceCairo(context, bitmap); | 89 return new VectorPlatformDeviceCairo(context, bitmap); |
| 91 } | 90 } |
| 92 | 91 |
| 93 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, | 92 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, |
| 94 const SkBitmap& bitmap) | 93 const SkBitmap& bitmap) |
| 95 : PlatformDevice(bitmap), | 94 : SkDevice(bitmap), |
| 96 context_(context) { | 95 context_(context) { |
| 97 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 96 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
| 98 | 97 |
| 98 SetPlatformDevice(this, this); |
| 99 |
| 99 // Increase the reference count to keep the context alive. | 100 // Increase the reference count to keep the context alive. |
| 100 cairo_reference(context_); | 101 cairo_reference(context_); |
| 101 | 102 |
| 102 transform_.reset(); | 103 transform_.reset(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { | 106 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { |
| 106 // Un-ref |context_| since we referenced it in the constructor. | 107 // Un-ref |context_| since we referenced it in the constructor. |
| 107 cairo_destroy(context_); | 108 cairo_destroy(context_); |
| 108 } | 109 } |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 DCHECK(it->second.font_stream); | 681 DCHECK(it->second.font_stream); |
| 681 | 682 |
| 682 cairo_font_face_destroy(it->second.cairo_face); | 683 cairo_font_face_destroy(it->second.cairo_face); |
| 683 // |it->second.ft_face| is handled by Cairo. | 684 // |it->second.ft_face| is handled by Cairo. |
| 684 it->second.font_stream->unref(); | 685 it->second.font_stream->unref(); |
| 685 } | 686 } |
| 686 g_font_cache->clear(); | 687 g_font_cache->clear(); |
| 687 } | 688 } |
| 688 | 689 |
| 689 } // namespace skia | 690 } // namespace skia |
| OLD | NEW |