Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: skia/ext/vector_platform_device_cairo_linux.cc

Issue 7193040: Revert 91504 - Stop using deprecated factory API for SkDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
71 // static 80 // static
72 PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, 81 PlatformDevice* VectorPlatformDeviceCairoFactory::CreateDevice(cairo_t* context,
73 int width, int height, 82 int width,
74 bool isOpaque) { 83 int height,
84 bool isOpaque) {
75 // TODO(myhuang): Here we might also have similar issues as those on Windows 85 // 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). 86 // (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. 87 // Please note that is_opaque is true when we use this class for printing.
78 // Fallback to bitmap when context is NULL. 88 // Fallback to bitmap when context is NULL.
79 if (!isOpaque || NULL == context) { 89 if (!isOpaque || NULL == context) {
80 return BitmapPlatformDevice::Create(width, height, isOpaque); 90 return BitmapPlatformDevice::Create(width, height, isOpaque);
81 } 91 }
82 92
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) {
83 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); 102 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS);
84 SkASSERT(width > 0); 103 SkASSERT(width > 0);
85 SkASSERT(height > 0); 104 SkASSERT(height > 0);
86 105
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.
87 SkBitmap bitmap; 109 SkBitmap bitmap;
88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 110 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
89 111
90 return new VectorPlatformDeviceCairo(context, bitmap); 112 return new VectorPlatformDeviceCairo(context, bitmap);
91 } 113 }
92 114
93 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context, 115 VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context,
94 const SkBitmap& bitmap) 116 const SkBitmap& bitmap)
95 : PlatformDevice(bitmap), 117 : PlatformDevice(bitmap),
96 context_(context) { 118 context_(context) {
97 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); 119 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
98 120
99 // Increase the reference count to keep the context alive. 121 // Increase the reference count to keep the context alive.
100 cairo_reference(context_); 122 cairo_reference(context_);
101 123
102 transform_.reset(); 124 transform_.reset();
103 } 125 }
104 126
105 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() { 127 VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() {
106 // Un-ref |context_| since we referenced it in the constructor. 128 // Un-ref |context_| since we referenced it in the constructor.
107 cairo_destroy(context_); 129 cairo_destroy(context_);
108 } 130 }
109 131
132 SkDeviceFactory* VectorPlatformDeviceCairo::onNewDeviceFactory() {
133 return SkNEW(VectorPlatformDeviceCairoFactory);
134 }
135
110 PlatformDevice::PlatformSurface 136 PlatformDevice::PlatformSurface
111 VectorPlatformDeviceCairo::BeginPlatformPaint() { 137 VectorPlatformDeviceCairo::BeginPlatformPaint() {
112 return context_; 138 return context_;
113 } 139 }
114 140
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
123 uint32_t VectorPlatformDeviceCairo::getDeviceCapabilities() { 141 uint32_t VectorPlatformDeviceCairo::getDeviceCapabilities() {
124 return SkDevice::getDeviceCapabilities() | kVector_Capability; 142 return SkDevice::getDeviceCapabilities() | kVector_Capability;
125 } 143 }
126 144
127 void VectorPlatformDeviceCairo::drawBitmap(const SkDraw& draw, 145 void VectorPlatformDeviceCairo::drawBitmap(const SkDraw& draw,
128 const SkBitmap& bitmap, 146 const SkBitmap& bitmap,
129 const SkIRect* srcRectOrNull, 147 const SkIRect* srcRectOrNull,
130 const SkMatrix& matrix, 148 const SkMatrix& matrix,
131 const SkPaint& paint) { 149 const SkPaint& paint) {
132 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); 150 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 DCHECK(it->second.font_stream); 698 DCHECK(it->second.font_stream);
681 699
682 cairo_font_face_destroy(it->second.cairo_face); 700 cairo_font_face_destroy(it->second.cairo_face);
683 // |it->second.ft_face| is handled by Cairo. 701 // |it->second.ft_face| is handled by Cairo.
684 it->second.font_stream->unref(); 702 it->second.font_stream->unref();
685 } 703 }
686 g_font_cache->clear(); 704 g_font_cache->clear();
687 } 705 }
688 706
689 } // namespace skia 707 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/vector_platform_device_cairo_linux.h ('k') | skia/ext/vector_platform_device_emf_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698