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

Side by Side Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 1170523002: Removing GraphicsContext from ImageBuffer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix for shape bug Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/graphics/ImageBuffer.h ('k') | Source/platform/graphics/ImageBufferSurface.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 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 OwnPtr<ImageBufferSurface> surface(adoptPtr(new UnacceleratedImageBufferSurf ace(size, opacityMode))); 72 OwnPtr<ImageBufferSurface> surface(adoptPtr(new UnacceleratedImageBufferSurf ace(size, opacityMode)));
73 if (!surface->isValid()) 73 if (!surface->isValid())
74 return nullptr; 74 return nullptr;
75 return adoptPtr(new ImageBuffer(surface.release())); 75 return adoptPtr(new ImageBuffer(surface.release()));
76 } 76 }
77 77
78 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface) 78 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface)
79 : m_surface(surface) 79 : m_surface(surface)
80 , m_client(0) 80 , m_client(0)
81 { 81 {
82 if (m_surface->canvas()) {
83 m_context = GraphicsContext::deprecatedCreateWithCanvas(m_surface->canva s());
84 m_context->setAccelerated(m_surface->isAccelerated());
85 }
86 m_surface->setImageBuffer(this); 82 m_surface->setImageBuffer(this);
87 } 83 }
88 84
89 ImageBuffer::~ImageBuffer() 85 ImageBuffer::~ImageBuffer()
90 { 86 {
91 } 87 }
92 88
93 GraphicsContext* ImageBuffer::context() const
94 {
95 if (!isSurfaceValid())
96 return nullptr;
97 ASSERT(m_context.get());
98 return m_context.get();
99 }
100
101 SkCanvas* ImageBuffer::canvas() const 89 SkCanvas* ImageBuffer::canvas() const
102 { 90 {
103 if (!isSurfaceValid()) 91 if (!isSurfaceValid())
104 return nullptr; 92 return nullptr;
105 return m_surface->canvas(); 93 return m_surface->canvas();
106 } 94 }
107 95
108 const SkBitmap& ImageBuffer::bitmap() const 96 const SkBitmap& ImageBuffer::bitmap() const
109 { 97 {
110 return m_surface->bitmap(); 98 return m_surface->bitmap();
(...skipping 27 matching lines...) Expand all
138 } 126 }
139 127
140 void ImageBuffer::notifySurfaceInvalid() 128 void ImageBuffer::notifySurfaceInvalid()
141 { 129 {
142 if (m_client) 130 if (m_client)
143 m_client->notifySurfaceInvalid(); 131 m_client->notifySurfaceInvalid();
144 } 132 }
145 133
146 void ImageBuffer::resetCanvas(SkCanvas* canvas) 134 void ImageBuffer::resetCanvas(SkCanvas* canvas)
147 { 135 {
148 ASSERT(context()->canvas());
149 context()->resetCanvas(canvas);
150 if (m_client) 136 if (m_client)
151 m_client->restoreCanvasMatrixClipStack(); 137 m_client->restoreCanvasMatrixClipStack();
152 } 138 }
153 139
154 PassRefPtr<SkImage> ImageBuffer::newImageSnapshot() const 140 PassRefPtr<SkImage> ImageBuffer::newImageSnapshot() const
155 { 141 {
156 return m_surface->newImageSnapshot(); 142 return m_surface->newImageSnapshot();
157 } 143 }
158 144
159 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) 145 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 211
226 context->flush(); 212 context->flush();
227 sharedContext->waitSyncPoint(context->insertSyncPoint()); 213 sharedContext->waitSyncPoint(context->insertSyncPoint());
228 214
229 // Undo grContext texture binding changes introduced in this function 215 // Undo grContext texture binding changes introduced in this function
230 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); 216 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState);
231 217
232 return true; 218 return true;
233 } 219 }
234 220
235 static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst)
236 {
237 ASSERT(dst);
238 return (src == dst);
239 }
240
241 Platform3DObject ImageBuffer::getBackingTexture() 221 Platform3DObject ImageBuffer::getBackingTexture()
242 { 222 {
243 return m_surface->getBackingTexture(); 223 return m_surface->getBackingTexture();
244 } 224 }
245 225
246 void ImageBuffer::didModifyBackingTexture() 226 void ImageBuffer::didModifyBackingTexture()
247 { 227 {
248 m_surface->didModifyBackingTexture(); 228 m_surface->didModifyBackingTexture();
249 } 229 }
250 230
(...skipping 19 matching lines...) Expand all
270 250
271 return result; 251 return result;
272 } 252 }
273 253
274 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons t FloatRect* srcPtr, SkXfermode::Mode op) 254 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons t FloatRect* srcPtr, SkXfermode::Mode op)
275 { 255 {
276 if (!isSurfaceValid()) 256 if (!isSurfaceValid())
277 return; 257 return;
278 258
279 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); 259 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size());
280 m_surface->draw(context, destRect, srcRect, op, drawNeedsCopy(m_context.get( ), context)); 260 m_surface->draw(context, destRect, srcRect, op);
281 } 261 }
282 262
283 void ImageBuffer::flush() 263 void ImageBuffer::flush()
284 { 264 {
285 if (m_surface->canvas()) { 265 if (m_surface->canvas()) {
286 m_surface->canvas()->flush(); 266 m_surface->canvas()->flush();
287 } 267 }
288 } 268 }
289 269
290 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const 270 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar rayBufferContents& contents) const
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 ASSERT(originY >= 0); 324 ASSERT(originY >= 0);
345 ASSERT(originY < sourceRect.maxY()); 325 ASSERT(originY < sourceRect.maxY());
346 326
347 const size_t srcBytesPerRow = 4 * sourceSize.width(); 327 const size_t srcBytesPerRow = 4 * sourceSize.width();
348 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; 328 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4;
349 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 329 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
350 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType); 330 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType);
351 331
352 m_surface->willAccessPixels(); 332 m_surface->willAccessPixels();
353 333
354 context()->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); 334 canvas()->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
355 } 335 }
356 336
357 template <typename T> 337 template <typename T>
358 static bool encodeImage(T& source, const String& mimeType, const double* quality , Vector<char>* output) 338 static bool encodeImage(T& source, const String& mimeType, const double* quality , Vector<char>* output)
359 { 339 {
360 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char> *>(output); 340 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char> *>(output);
361 341
362 if (mimeType == "image/jpeg") { 342 if (mimeType == "image/jpeg") {
363 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; 343 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
364 if (quality && *quality >= 0.0 && *quality <= 1.0) 344 if (quality && *quality >= 0.0 && *quality <= 1.0)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 376 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
397 377
398 Vector<char> encodedImage; 378 Vector<char> encodedImage;
399 if (!encodeImage(*this, mimeType, quality, &encodedImage)) 379 if (!encodeImage(*this, mimeType, quality, &encodedImage))
400 return "data:,"; 380 return "data:,";
401 381
402 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); 382 return "data:" + mimeType + ";base64," + base64Encode(encodedImage);
403 } 383 }
404 384
405 } // namespace blink 385 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageBuffer.h ('k') | Source/platform/graphics/ImageBufferSurface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698