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

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

Issue 9416017: Optionally clear PlatformCanvas instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address style issues. Created 8 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bitmap_platform_device_linux.h" 5 #include "skia/ext/bitmap_platform_device_linux.h"
6 6
7 #include "skia/ext/bitmap_platform_device_data.h" 7 #include "skia/ext/bitmap_platform_device_data.h"
8 8
9 #if defined(OS_OPENBSD) 9 #if defined(OS_OPENBSD)
10 #include <cairo.h> 10 #include <cairo.h>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 LoadClipToContext(bitmap_context_, clip_region_); 75 LoadClipToContext(bitmap_context_, clip_region_);
76 LoadMatrixToContext(bitmap_context_, transform_); 76 LoadMatrixToContext(bitmap_context_, transform_);
77 } 77 }
78 78
79 // We use this static factory function instead of the regular constructor so 79 // We use this static factory function instead of the regular constructor so
80 // that we can create the pixel data before calling the constructor. This is 80 // that we can create the pixel data before calling the constructor. This is
81 // required so that we can call the base class' constructor with the pixel 81 // required so that we can call the base class' constructor with the pixel
82 // data. 82 // data.
83 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, 83 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
84 bool is_opaque, 84 int flags,
85 cairo_surface_t* surface) { 85 cairo_surface_t* surface) {
86 SkBitmap bitmap; 86 SkBitmap bitmap;
87 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 87 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
88 cairo_image_surface_get_stride(surface)); 88 cairo_image_surface_get_stride(surface));
89 bitmap.setPixels(cairo_image_surface_get_data(surface)); 89 bitmap.setPixels(cairo_image_surface_get_data(surface));
90 bitmap.setIsOpaque(is_opaque); 90 bitmap.setIsOpaque(flags & FLAGS_OPAQUE);
91 91
92 // The device object will take ownership of the graphics context. 92 // The device object will take ownership of the graphics context.
93 return new BitmapPlatformDevice 93 return new BitmapPlatformDevice
94 (bitmap, new BitmapPlatformDeviceData(surface)); 94 (bitmap, new BitmapPlatformDeviceData(surface));
95 } 95 }
96 96
97 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, 97 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
98 bool is_opaque) { 98 int flags) {
99 // This initializes the bitmap to all zeros. 99 // This initializes the bitmap to all zeros.
100 cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100 cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
101 width, height); 101 width, height);
102 102
103 BitmapPlatformDevice* device = Create(width, height, is_opaque, surface); 103 BitmapPlatformDevice* device = Create(width, height, flags, surface);
104 104
105 #ifndef NDEBUG 105 #ifndef NDEBUG
106 if (is_opaque) // Fill with bright bluish green 106 if (flags & FLAGS_OPAQUE) // Fill with bright bluish green
107 device->eraseColor(SkColorSetARGB(255, 0, 255, 128)); 107 device->eraseColor(SkColorSetARGB(255, 0, 255, 128));
108 #endif 108 #endif
109 109
110 return device; 110 return device;
111 } 111 }
112 112
113 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, 113 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
114 bool is_opaque, 114 int flags, uint8_t* data) {
115 uint8_t* data) {
116 cairo_surface_t* surface = cairo_image_surface_create_for_data( 115 cairo_surface_t* surface = cairo_image_surface_create_for_data(
117 data, CAIRO_FORMAT_ARGB32, width, height, 116 data, CAIRO_FORMAT_ARGB32, width, height,
118 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width)); 117 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
119 118
120 return Create(width, height, is_opaque, surface); 119 return Create(width, height, flags, surface);
121 } 120 }
122 121
123 // The device will own the bitmap, which corresponds to also owning the pixel 122 // The device will own the bitmap, which corresponds to also owning the pixel
124 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. 123 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
125 BitmapPlatformDevice::BitmapPlatformDevice( 124 BitmapPlatformDevice::BitmapPlatformDevice(
126 const SkBitmap& bitmap, 125 const SkBitmap& bitmap,
127 BitmapPlatformDeviceData* data) 126 BitmapPlatformDeviceData* data)
128 : SkDevice(bitmap), 127 : SkDevice(bitmap),
129 data_(data) { 128 data_(data) {
130 SetPlatformDevice(this, this); 129 SetPlatformDevice(this, this);
131 } 130 }
132 131
133 BitmapPlatformDevice::~BitmapPlatformDevice() { 132 BitmapPlatformDevice::~BitmapPlatformDevice() {
134 } 133 }
135 134
136 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( 135 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
137 SkBitmap::Config config, int width, int height, bool isOpaque, 136 SkBitmap::Config config, int width, int height, bool isOpaque,
138 Usage /*usage*/) { 137 Usage /*usage*/) {
139 SkASSERT(config == SkBitmap::kARGB_8888_Config); 138 SkASSERT(config == SkBitmap::kARGB_8888_Config);
140 return BitmapPlatformDevice::Create(width, height, isOpaque); 139 return BitmapPlatformDevice::Create(width, height, GetDefaultFlags(isOpaque));
Jeff Timanus 2012/02/23 22:14:10 The various BitmapPlatformDevice::onCreateCompatib
141 } 140 }
142 141
143 cairo_t* BitmapPlatformDevice::BeginPlatformPaint() { 142 cairo_t* BitmapPlatformDevice::BeginPlatformPaint() {
144 data_->LoadConfig(); 143 data_->LoadConfig();
145 cairo_t* cairo = data_->bitmap_context(); 144 cairo_t* cairo = data_->bitmap_context();
146 cairo_surface_t* surface = cairo_get_target(cairo); 145 cairo_surface_t* surface = cairo_get_target(cairo);
147 // Tell cairo to flush anything it has pending. 146 // Tell cairo to flush anything it has pending.
148 cairo_surface_flush(surface); 147 cairo_surface_flush(surface);
149 // Tell Cairo that we (probably) modified (actually, will modify) its pixel 148 // Tell Cairo that we (probably) modified (actually, will modify) its pixel
150 // buffer directly. 149 // buffer directly.
151 cairo_surface_mark_dirty(surface); 150 cairo_surface_mark_dirty(surface);
152 return cairo; 151 return cairo;
153 } 152 }
154 153
155 void BitmapPlatformDevice::DrawToNativeContext( 154 void BitmapPlatformDevice::DrawToNativeContext(
156 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { 155 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
157 // Should never be called on Linux. 156 // Should never be called on Linux.
158 SkASSERT(false); 157 SkASSERT(false);
159 } 158 }
160 159
161 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, 160 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
162 const SkRegion& region, 161 const SkRegion& region,
163 const SkClipStack&) { 162 const SkClipStack&) {
164 data_->SetMatrixClip(transform, region); 163 data_->SetMatrixClip(transform, region);
165 } 164 }
166 165
167 } // namespace skia 166 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698