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

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

Issue 1367683002: Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added nullptr check + fixed style check errors Created 5 years, 2 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
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (m_client) 141 if (m_client)
142 m_client->notifySurfaceInvalid(); 142 m_client->notifySurfaceInvalid();
143 } 143 }
144 144
145 void ImageBuffer::resetCanvas(SkCanvas* canvas) const 145 void ImageBuffer::resetCanvas(SkCanvas* canvas) const
146 { 146 {
147 if (m_client) 147 if (m_client)
148 m_client->restoreCanvasMatrixClipStack(canvas); 148 m_client->restoreCanvasMatrixClipStack(canvas);
149 } 149 }
150 150
151 PassRefPtr<SkImage> ImageBuffer::newSkImageSnapshot() const 151 PassRefPtr<SkImage> ImageBuffer::newSkImageSnapshot(AccelerationHint hint) const
152 { 152 {
153 if (m_snapshotState == InitialSnapshotState) 153 if (m_snapshotState == InitialSnapshotState)
154 m_snapshotState = DidAcquireSnapshot; 154 m_snapshotState = DidAcquireSnapshot;
155 155
156 if (!isSurfaceValid()) 156 if (!isSurfaceValid())
157 return nullptr; 157 return nullptr;
158 return m_surface->newImageSnapshot(); 158 return m_surface->newImageSnapshot(hint);
159 } 159 }
160 160
161 PassRefPtr<Image> ImageBuffer::newImageSnapshot() const 161 PassRefPtr<Image> ImageBuffer::newImageSnapshot(AccelerationHint hint) const
162 { 162 {
163 RefPtr<SkImage> snapshot = newSkImageSnapshot(); 163 RefPtr<SkImage> snapshot = newSkImageSnapshot(hint);
164 if (!snapshot) 164 if (!snapshot)
165 return nullptr; 165 return nullptr;
166 return StaticBitmapImage::create(snapshot); 166 return StaticBitmapImage::create(snapshot);
167 } 167 }
168 168
169 void ImageBuffer::didDraw(const FloatRect& rect) const 169 void ImageBuffer::didDraw(const FloatRect& rect) const
170 { 170 {
171 if (m_snapshotState == DidAcquireSnapshot) 171 if (m_snapshotState == DidAcquireSnapshot)
172 m_snapshotState = DrawnToAfterSnapshot; 172 m_snapshotState = DrawnToAfterSnapshot;
173 m_surface->didDraw(rect); 173 m_surface->didDraw(rect);
174 } 174 }
175 175
176 WebLayer* ImageBuffer::platformLayer() const 176 WebLayer* ImageBuffer::platformLayer() const
177 { 177 {
178 return m_surface->layer(); 178 return m_surface->layer();
179 } 179 }
180 180
181 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3 DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu ltiplyAlpha, bool flipY) 181 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3 DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu ltiplyAlpha, bool flipY)
182 { 182 {
183 if (!m_surface->isAccelerated() || !isSurfaceValid())
184 return false;
185
186 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm at, destType, level)) 183 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm at, destType, level))
187 return false; 184 return false;
188 185
189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(); 186 if (!isSurfaceValid())
187 return false;
188
189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel eration);
190 if (!textureImage) 190 if (!textureImage)
191 return false; 191 return false;
192 192
193 if (!m_surface->isAccelerated())
194 return false;
195
196
193 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou ld guarantee this 197 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou ld guarantee this
194 // Get the texture ID, flushing pending operations if needed. 198 // Get the texture ID, flushing pending operations if needed.
195 Platform3DObject textureId = textureImage->getTextureHandle(true); 199 Platform3DObject textureId = textureImage->getTextureHandle(true);
196 if (!textureId) 200 if (!textureId)
197 return false; 201 return false;
198 202
199 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current() ->createSharedOffscreenGraphicsContext3DProvider()); 203 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current() ->createSharedOffscreenGraphicsContext3DProvider());
200 if (!provider) 204 if (!provider)
201 return false; 205 return false;
202 WebGraphicsContext3D* sharedContext = provider->context3d(); 206 WebGraphicsContext3D* sharedContext = provider->context3d();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 dataSize *= rect.height(); 284 dataSize *= rect.height();
281 if (dataSize.hasOverflowed()) 285 if (dataSize.hasOverflowed())
282 return false; 286 return false;
283 287
284 if (!isSurfaceValid()) { 288 if (!isSurfaceValid()) {
285 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); 289 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize);
286 result.transfer(contents); 290 result.transfer(contents);
287 return true; 291 return true;
288 } 292 }
289 293
294 ASSERT(canvas());
295 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration) ;
296 if (!snapshot)
297 return false;
298
290 const bool mayHaveStrayArea = 299 const bool mayHaveStrayArea =
291 m_surface->isAccelerated() // GPU readback may fail silently 300 m_surface->isAccelerated() // GPU readback may fail silently
292 || rect.x() < 0 301 || rect.x() < 0
293 || rect.y() < 0 302 || rect.y() < 0
294 || rect.maxX() > m_surface->size().width() 303 || rect.maxX() > m_surface->size().width()
295 || rect.maxY() > m_surface->size().height(); 304 || rect.maxY() > m_surface->size().height();
296 WTF::ArrayBufferContents result( 305 WTF::ArrayBufferContents result(
297 rect.width() * rect.height(), 4, 306 rect.width() * rect.height(), 4,
298 WTF::ArrayBufferContents::NotShared, 307 WTF::ArrayBufferContents::NotShared,
299 mayHaveStrayArea 308 mayHaveStrayArea
300 ? WTF::ArrayBufferContents::ZeroInitialize 309 ? WTF::ArrayBufferContents::ZeroInitialize
301 : WTF::ArrayBufferContents::DontInitialize); 310 : WTF::ArrayBufferContents::DontInitialize);
302 311
303 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 312 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
304 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType); 313 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888 _SkColorType, alphaType);
305 314
306 ASSERT(canvas());
307 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot();
308 if (!snapshot)
309 return false;
310 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ()); 315 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y ());
311 result.transfer(contents); 316 result.transfer(contents);
312 return true; 317 return true;
313 } 318 }
314 319
315 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint ) 320 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint )
316 { 321 {
317 if (!isSurfaceValid()) 322 if (!isSurfaceValid())
318 return; 323 return;
319 324
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 376 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
372 377
373 Vector<char> encodedImage; 378 Vector<char> encodedImage;
374 if (!encodeImage(mimeType, quality, &encodedImage)) 379 if (!encodeImage(mimeType, quality, &encodedImage))
375 return "data:,"; 380 return "data:,";
376 381
377 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); 382 return "data:" + mimeType + ";base64," + base64Encode(encodedImage);
378 } 383 }
379 384
380 } // namespace blink 385 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698