| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 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 SkDevice* VectorPlatformDeviceCairoFactory::newDevice(SkCanvas* ignored, | |
| 72 SkBitmap::Config config, | |
| 73 int width, int height, | |
| 74 bool isOpaque, | |
| 75 bool isForLayer) { | |
| 76 SkASSERT(config == SkBitmap::kARGB_8888_Config); | |
| 77 return CreateDevice(NULL, width, height, isOpaque); | |
| 78 } | |
| 79 | |
| 80 // static | 71 // static |
| 81 PlatformDevice* VectorPlatformDeviceCairoFactory::CreateDevice(cairo_t* context, | 72 PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, |
| 82 int width, | 73 int width, int height, |
| 83 int height, | 74 bool isOpaque) { |
| 84 bool isOpaque) { | |
| 85 // 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 |
| 86 // (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). |
| 87 // 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. |
| 88 // Fallback to bitmap when context is NULL. | 78 // Fallback to bitmap when context is NULL. |
| 89 if (!isOpaque || NULL == context) { | 79 if (!isOpaque || NULL == context) { |
| 90 return BitmapPlatformDevice::Create(width, height, isOpaque); | 80 return BitmapPlatformDevice::Create(width, height, isOpaque); |
| 91 } | 81 } |
| 92 | 82 |
| 93 PlatformDevice* device = | |
| 94 VectorPlatformDeviceCairo::create(context, width, height); | |
| 95 return device; | |
| 96 } | |
| 97 | |
| 98 VectorPlatformDeviceCairo* VectorPlatformDeviceCairo::create( | |
| 99 PlatformSurface context, | |
| 100 int width, | |
| 101 int height) { | |
| 102 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); | 83 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); |
| 103 SkASSERT(width > 0); | 84 SkASSERT(width > 0); |
| 104 SkASSERT(height > 0); | 85 SkASSERT(height > 0); |
| 105 | 86 |
| 106 // TODO(myhuang): Can we get rid of the bitmap? In this vectorial device, | |
| 107 // the content of this bitmap might be meaningless. However, it does occupy | |
| 108 // lots of memory space. | |
| 109 SkBitmap bitmap; | 87 SkBitmap bitmap; |
| 110 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 111 | 89 |
| 112 return new VectorPlatformDeviceCairo(context, bitmap); | 90 return new VectorPlatformDeviceCairo(context, bitmap); |
| 113 } | 91 } |
| 114 | 92 |
| 115 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, | 93 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, |
| 116 const SkBitmap& bitmap) | 94 const SkBitmap& bitmap) |
| 117 : PlatformDevice(bitmap), | 95 : PlatformDevice(bitmap), |
| 118 context_(context) { | 96 context_(context) { |
| 119 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 97 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
| 120 | 98 |
| 121 // Increase the reference count to keep the context alive. | 99 // Increase the reference count to keep the context alive. |
| 122 cairo_reference(context_); | 100 cairo_reference(context_); |
| 123 | 101 |
| 124 transform_.reset(); | 102 transform_.reset(); |
| 125 } | 103 } |
| 126 | 104 |
| 127 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { | 105 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { |
| 128 // Un-ref |context_| since we referenced it in the constructor. | 106 // Un-ref |context_| since we referenced it in the constructor. |
| 129 cairo_destroy(context_); | 107 cairo_destroy(context_); |
| 130 } | 108 } |
| 131 | 109 |
| 132 SkDeviceFactory* VectorPlatformDeviceCairo::onNewDeviceFactory() { | |
| 133 return SkNEW(VectorPlatformDeviceCairoFactory); | |
| 134 } | |
| 135 | |
| 136 PlatformDevice::PlatformSurface | 110 PlatformDevice::PlatformSurface |
| 137 VectorPlatformDeviceCairo::BeginPlatformPaint() { | 111 VectorPlatformDeviceCairo::BeginPlatformPaint() { |
| 138 return context_; | 112 return context_; |
| 139 } | 113 } |
| 140 | 114 |
| 115 SkDevice* VectorPlatformDeviceCairo::onCreateCompatibleDevice( |
| 116 SkBitmap::Config config, |
| 117 int width, int height, |
| 118 bool isOpaque, Usage) { |
| 119 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 120 return CreateDevice(NULL, width, height, isOpaque); |
| 121 } |
| 122 |
| 141 uint32_t VectorPlatformDeviceCairo::getDeviceCapabilities() { | 123 uint32_t VectorPlatformDeviceCairo::getDeviceCapabilities() { |
| 142 return SkDevice::getDeviceCapabilities() | kVector_Capability; | 124 return SkDevice::getDeviceCapabilities() | kVector_Capability; |
| 143 } | 125 } |
| 144 | 126 |
| 145 void VectorPlatformDeviceCairo::drawBitmap(const SkDraw& draw, | 127 void VectorPlatformDeviceCairo::drawBitmap(const SkDraw& draw, |
| 146 const SkBitmap& bitmap, | 128 const SkBitmap& bitmap, |
| 147 const SkIRect* srcRectOrNull, | 129 const SkIRect* srcRectOrNull, |
| 148 const SkMatrix& matrix, | 130 const SkMatrix& matrix, |
| 149 const SkPaint& paint) { | 131 const SkPaint& paint) { |
| 150 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 132 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 DCHECK(it->second.font_stream); | 680 DCHECK(it->second.font_stream); |
| 699 | 681 |
| 700 cairo_font_face_destroy(it->second.cairo_face); | 682 cairo_font_face_destroy(it->second.cairo_face); |
| 701 // |it->second.ft_face| is handled by Cairo. | 683 // |it->second.ft_face| is handled by Cairo. |
| 702 it->second.font_stream->unref(); | 684 it->second.font_stream->unref(); |
| 703 } | 685 } |
| 704 g_font_cache->clear(); | 686 g_font_cache->clear(); |
| 705 } | 687 } |
| 706 | 688 |
| 707 } // namespace skia | 689 } // namespace skia |
| OLD | NEW |