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

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

Issue 125109: Refactor the PlatformContext layer to have only one class. (Closed)
Patch Set: Created 11 years, 6 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
« no previous file with comments | « skia/ext/platform_canvas_linux.h ('k') | skia/ext/platform_canvas_mac.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/platform_canvas_linux.h" 5 #include "skia/ext/platform_canvas.h"
6 6
7 #include <cairo/cairo.h> 7 #include <cairo/cairo.h>
8 8
9 #include "skia/ext/platform_device_linux.h" 9 #include "skia/ext/platform_device_linux.h"
10 #include "skia/ext/bitmap_platform_device_linux.h" 10 #include "skia/ext/bitmap_platform_device_linux.h"
11 #include "third_party/skia/include/core/SkTypes.h" 11 #include "third_party/skia/include/core/SkTypes.h"
12 12
13 namespace skia { 13 namespace skia {
14 14
15 PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() { 15 PlatformCanvas::PlatformCanvas() : SkCanvas() {
16 } 16 }
17 17
18 PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque) 18 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
19 : SkCanvas() { 19 : SkCanvas() {
20 if (!initialize(width, height, is_opaque)) 20 if (!initialize(width, height, is_opaque))
21 SK_CRASH(); 21 SK_CRASH();
22 } 22 }
23 23
24 PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque, 24 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque,
25 uint8_t* data) 25 uint8_t* data)
26 : SkCanvas() { 26 : SkCanvas() {
27 if (!initialize(width, height, is_opaque, data)) 27 if (!initialize(width, height, is_opaque, data))
28 SK_CRASH(); 28 SK_CRASH();
29 } 29 }
30 30
31 PlatformCanvasLinux::~PlatformCanvasLinux() { 31 PlatformCanvas::~PlatformCanvas() {
32 } 32 }
33 33 bool PlatformCanvas::initialize(int width, int height, bool is_opaque,
34 bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque) { 34 uint8_t* data) {
35 SkDevice* device = createPlatformDevice(width, height, is_opaque); 35 SkDevice* device =
36 BitmapPlatformDevice::Create(width, height, is_opaque, data);
36 if (!device) 37 if (!device)
37 return false; 38 return false;
38 39
39 setDevice(device);
40 device->unref(); // was created with refcount 1, and setDevice also refs
41 return true;
42 }
43
44 bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque,
45 uint8_t* data) {
46 SkDevice* device =
47 BitmapPlatformDeviceLinux::Create(width, height, is_opaque, data);
48 if (!device)
49 return false;
50
51 setDevice(device); 40 setDevice(device);
52 device->unref(); // was created with refcount 1, and setDevice also refs 41 device->unref(); // was created with refcount 1, and setDevice also refs
53 return true; 42 return true;
54 } 43 }
55 44
56 cairo_surface_t* PlatformCanvasLinux::beginPlatformPaint() { 45 cairo_surface_t* PlatformCanvas::beginPlatformPaint() {
57 return getTopPlatformDevice().beginPlatformPaint(); 46 return getTopPlatformDevice().beginPlatformPaint();
58 } 47 }
59 48
60 PlatformDeviceLinux& PlatformCanvasLinux::getTopPlatformDevice() const { 49 void PlatformCanvas::endPlatformPaint() {
61 // All of our devices should be our special PlatformDevice. 50 // We don't need to do anything on Linux here.
62 SkCanvas::LayerIter iter(const_cast<PlatformCanvasLinux*>(this), false);
63 return *static_cast<PlatformDeviceLinux*>(iter.device());
64 } 51 }
65 52
66 SkDevice* PlatformCanvasLinux::createDevice(SkBitmap::Config config, 53 SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
67 int width, 54 int width,
68 int height, 55 int height,
69 bool is_opaque, bool isForLayer) { 56 bool is_opaque,
57 bool isForLayer) {
70 SkASSERT(config == SkBitmap::kARGB_8888_Config); 58 SkASSERT(config == SkBitmap::kARGB_8888_Config);
71 return createPlatformDevice(width, height, is_opaque); 59 return BitmapPlatformDevice::Create(width, height, is_opaque);
72 }
73
74 SkDevice* PlatformCanvasLinux::createPlatformDevice(int width,
75 int height,
76 bool is_opaque) {
77 return BitmapPlatformDeviceLinux::Create(width, height, is_opaque);
78 }
79
80 // static
81 size_t PlatformCanvasLinux::StrideForWidth(unsigned width) {
82 return cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
83 } 60 }
84 61
85 } // namespace skia 62 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/platform_canvas_linux.h ('k') | skia/ext/platform_canvas_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698