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, |
73 int width, int height, | 73 int width, int height, |
74 bool isOpaque) { | 74 bool isOpaque) { |
75 // TODO(myhuang): Here we might also have similar issues as those on Windows | 75 // 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). | 76 // (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. | 77 // Please note that is_opaque is true when we use this class for printing. |
78 // Fallback to bitmap when context is NULL. | 78 // Fallback to bitmap when context is NULL. |
79 if (!isOpaque || NULL == context) { | 79 if (!isOpaque || NULL == context) { |
80 return BitmapPlatformDevice::Create(width, height, isOpaque); | 80 return BitmapPlatformDevice::Create(width, height, isOpaque); |
81 } | 81 } |
82 | 82 |
83 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); | 83 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); |
84 SkASSERT(width > 0); | 84 SkASSERT(width > 0); |
85 SkASSERT(height > 0); | 85 SkASSERT(height > 0); |
86 | 86 |
87 SkBitmap bitmap; | 87 SkBitmap bitmap; |
88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
89 | 89 |
90 return new VectorPlatformDeviceCairo(context, bitmap); | 90 return new VectorPlatformDeviceCairo(context, bitmap); |
91 } | 91 } |
92 | 92 |
93 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, | 93 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, |
94 const SkBitmap& bitmap) | 94 const SkBitmap& bitmap) |
95 : PlatformDevice(bitmap), | 95 : PlatformDevice(this), |
| 96 SkDevice(bitmap), |
96 context_(context) { | 97 context_(context) { |
97 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 98 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
98 | 99 |
| 100 // Pass false, because VectorPlatformDeviceCairo inherits both SkDevice, and |
| 101 // PlatformDevice, so there is no need to explicitly bind the lifetime of the |
| 102 // two classes. |
| 103 SetPlatformDevice(this, this, false); |
| 104 |
99 // Increase the reference count to keep the context alive. | 105 // Increase the reference count to keep the context alive. |
100 cairo_reference(context_); | 106 cairo_reference(context_); |
101 | 107 |
102 transform_.reset(); | 108 transform_.reset(); |
103 } | 109 } |
104 | 110 |
105 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { | 111 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { |
106 // Un-ref |context_| since we referenced it in the constructor. | 112 // Un-ref |context_| since we referenced it in the constructor. |
107 cairo_destroy(context_); | 113 cairo_destroy(context_); |
108 } | 114 } |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 DCHECK(it->second.font_stream); | 686 DCHECK(it->second.font_stream); |
681 | 687 |
682 cairo_font_face_destroy(it->second.cairo_face); | 688 cairo_font_face_destroy(it->second.cairo_face); |
683 // |it->second.ft_face| is handled by Cairo. | 689 // |it->second.ft_face| is handled by Cairo. |
684 it->second.font_stream->unref(); | 690 it->second.font_stream->unref(); |
685 } | 691 } |
686 g_font_cache->clear(); | 692 g_font_cache->clear(); |
687 } | 693 } |
688 | 694 |
689 } // namespace skia | 695 } // namespace skia |
OLD | NEW |