Chromium Code Reviews

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

Issue 3590011: Update use of SkCanvas and SkDevice to match change in Skia (Closed)
Patch Set: Bump deps again to bring in fix for memory leak Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « skia/ext/vector_platform_device_linux.h ('k') | skia/ext/vector_platform_device_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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.h" 5 #include "skia/ext/vector_platform_device.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>
11 #include FT_FREETYPE_H 11 #include FT_FREETYPE_H
12 12
13 #include <map> 13 #include <map>
14 14
15 #include "base/logging.h"
16 #include "base/singleton.h"
17 #include "skia/ext/bitmap_platform_device.h"
15 #include "third_party/skia/include/core/SkFontHost.h" 18 #include "third_party/skia/include/core/SkFontHost.h"
16 #include "third_party/skia/include/core/SkStream.h" 19 #include "third_party/skia/include/core/SkStream.h"
17 #include "third_party/skia/include/core/SkTypeface.h" 20 #include "third_party/skia/include/core/SkTypeface.h"
18 21
19 #include "base/logging.h"
20 #include "base/singleton.h"
21
22 namespace { 22 namespace {
23 23
24 struct FontInfo { 24 struct FontInfo {
25 SkStream* font_stream; 25 SkStream* font_stream;
26 FT_Face ft_face; 26 FT_Face ft_face;
27 cairo_font_face_t* cairo_face; 27 cairo_font_face_t* cairo_face;
28 cairo_user_data_key_t data_key; 28 cairo_user_data_key_t data_key;
29 }; 29 };
30 30
31 typedef std::map<uint32_t, FontInfo> MapFontId2FontInfo; 31 typedef std::map<uint32_t, FontInfo> MapFontId2FontInfo;
(...skipping 26 matching lines...)
58 58
59 // Verify cairo surface after creation/modification. 59 // Verify cairo surface after creation/modification.
60 bool IsContextValid(cairo_t* context) { 60 bool IsContextValid(cairo_t* context) {
61 return cairo_status(context) == CAIRO_STATUS_SUCCESS; 61 return cairo_status(context) == CAIRO_STATUS_SUCCESS;
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 namespace skia { 66 namespace skia {
67 67
68 SkDevice* SkVectorPlatformDeviceFactory::newDevice(SkBitmap::Config config,
69 int width, int height,
70 bool isOpaque,
71 bool isForLayer) {
72 SkASSERT(config == SkBitmap::kARGB_8888_Config);
73 return CreateDevice(NULL, width, height, isOpaque);
74 }
75
76 // static
77 SkDevice* SkVectorPlatformDeviceFactory::CreateDevice(cairo_t* context,
78 int width, int height,
79 bool isOpaque) {
80 // TODO(myhuang): Here we might also have similar issues as those on Windows
81 // (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383).
82 // Please note that is_opaque is true when we use this class for printing.
83 // Fallback to bitmap when context is NULL.
84 if (!isOpaque || NULL == context) {
85 return BitmapPlatformDevice::Create(width, height, isOpaque);
86 }
87
88 PlatformDevice* device =
89 VectorPlatformDevice::create(context, width, height);
90 return device;
91 }
92
68 VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context, 93 VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context,
69 int width, int height) { 94 int width, int height) {
70 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); 95 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS);
71 SkASSERT(width > 0); 96 SkASSERT(width > 0);
72 SkASSERT(height > 0); 97 SkASSERT(height > 0);
73 98
74 // TODO(myhuang): Can we get rid of the bitmap? In this vectorial device, 99 // TODO(myhuang): Can we get rid of the bitmap? In this vectorial device,
75 // the content of this bitmap might be meaningless. However, it does occupy 100 // the content of this bitmap might be meaningless. However, it does occupy
76 // lots of memory space. 101 // lots of memory space.
77 SkBitmap bitmap; 102 SkBitmap bitmap;
(...skipping 574 matching lines...)
652 DCHECK(it->second.font_stream); 677 DCHECK(it->second.font_stream);
653 678
654 cairo_font_face_destroy(it->second.cairo_face); 679 cairo_font_face_destroy(it->second.cairo_face);
655 // |it->second.ft_face| is handled by Cairo. 680 // |it->second.ft_face| is handled by Cairo.
656 it->second.font_stream->unref(); 681 it->second.font_stream->unref();
657 } 682 }
658 g_font_cache->clear(); 683 g_font_cache->clear();
659 } 684 }
660 685
661 } // namespace skia 686 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/vector_platform_device_linux.h ('k') | skia/ext/vector_platform_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine