OLD | NEW |
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 if (!surface->isValid()) | 92 if (!surface->isValid()) |
93 return nullptr; | 93 return nullptr; |
94 return WTF::wrapUnique(new ImageBuffer(std::move(surface))); | 94 return WTF::wrapUnique(new ImageBuffer(std::move(surface))); |
95 } | 95 } |
96 | 96 |
97 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) | 97 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) |
98 : m_weakPtrFactory(this), | 98 : m_weakPtrFactory(this), |
99 m_snapshotState(InitialSnapshotState), | 99 m_snapshotState(InitialSnapshotState), |
100 m_surface(std::move(surface)), | 100 m_surface(std::move(surface)), |
101 m_client(0), | 101 m_client(0), |
102 m_gpuReadbackInvokedInCurrentFrame(false), | |
103 m_gpuReadbackSuccessiveFrames(0), | |
104 m_gpuMemoryUsage(0) { | 102 m_gpuMemoryUsage(0) { |
105 m_surface->setImageBuffer(this); | 103 m_surface->setImageBuffer(this); |
106 updateGPUMemoryUsage(); | 104 updateGPUMemoryUsage(); |
107 } | 105 } |
108 | 106 |
109 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0; | 107 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0; |
110 unsigned ImageBuffer::s_globalAcceleratedImageBufferCount = 0; | 108 unsigned ImageBuffer::s_globalAcceleratedImageBufferCount = 0; |
111 | 109 |
112 ImageBuffer::~ImageBuffer() { | 110 ImageBuffer::~ImageBuffer() { |
113 if (m_gpuMemoryUsage) { | 111 if (m_gpuMemoryUsage) { |
(...skipping 30 matching lines...) Expand all Loading... |
144 int x, | 142 int x, |
145 int y) { | 143 int y) { |
146 return m_surface->writePixels(info, pixels, rowBytes, x, y); | 144 return m_surface->writePixels(info, pixels, rowBytes, x, y); |
147 } | 145 } |
148 | 146 |
149 bool ImageBuffer::isSurfaceValid() const { | 147 bool ImageBuffer::isSurfaceValid() const { |
150 return m_surface->isValid(); | 148 return m_surface->isValid(); |
151 } | 149 } |
152 | 150 |
153 void ImageBuffer::finalizeFrame() { | 151 void ImageBuffer::finalizeFrame() { |
154 if (isAccelerated() && | |
155 ExpensiveCanvasHeuristicParameters::GPUReadbackForcesNoAcceleration && | |
156 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { | |
157 if (m_gpuReadbackInvokedInCurrentFrame) { | |
158 m_gpuReadbackSuccessiveFrames++; | |
159 m_gpuReadbackInvokedInCurrentFrame = false; | |
160 } else { | |
161 m_gpuReadbackSuccessiveFrames = 0; | |
162 } | |
163 | |
164 if (m_gpuReadbackSuccessiveFrames >= | |
165 ExpensiveCanvasHeuristicParameters::GPUReadbackMinSuccessiveFrames) { | |
166 disableAcceleration(); | |
167 } | |
168 } | |
169 | |
170 m_surface->finalizeFrame(); | 152 m_surface->finalizeFrame(); |
171 } | 153 } |
172 | 154 |
173 void ImageBuffer::doPaintInvalidation(const FloatRect& dirtyRect) { | 155 void ImageBuffer::doPaintInvalidation(const FloatRect& dirtyRect) { |
174 m_surface->doPaintInvalidation(dirtyRect); | 156 m_surface->doPaintInvalidation(dirtyRect); |
175 } | 157 } |
176 | 158 |
177 bool ImageBuffer::restoreSurface() const { | 159 bool ImageBuffer::restoreSurface() const { |
178 return m_surface->isValid() || m_surface->restore(); | 160 return m_surface->isValid() || m_surface->restore(); |
179 } | 161 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 if (!data) | 352 if (!data) |
371 return false; | 353 return false; |
372 WTF::ArrayBufferContents result(data, allocSizeInBytes, | 354 WTF::ArrayBufferContents result(data, allocSizeInBytes, |
373 WTF::ArrayBufferContents::NotShared); | 355 WTF::ArrayBufferContents::NotShared); |
374 result.transfer(contents); | 356 result.transfer(contents); |
375 return true; | 357 return true; |
376 } | 358 } |
377 | 359 |
378 DCHECK(canvas()); | 360 DCHECK(canvas()); |
379 | 361 |
| 362 if (ExpensiveCanvasHeuristicParameters::GetImageDataForcesNoAcceleration && |
| 363 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { |
| 364 const_cast<ImageBuffer*>(this)->disableAcceleration(); |
| 365 } |
| 366 |
380 sk_sp<SkImage> snapshot = m_surface->newImageSnapshot( | 367 sk_sp<SkImage> snapshot = m_surface->newImageSnapshot( |
381 PreferNoAcceleration, SnapshotReasonGetImageData); | 368 PreferNoAcceleration, SnapshotReasonGetImageData); |
382 if (!snapshot) | 369 if (!snapshot) |
383 return false; | 370 return false; |
384 | 371 |
385 const bool mayHaveStrayArea = | 372 const bool mayHaveStrayArea = |
386 m_surface->isAccelerated() // GPU readback may fail silently | 373 m_surface->isAccelerated() // GPU readback may fail silently |
387 || rect.x() < 0 || rect.y() < 0 || | 374 || rect.x() < 0 || rect.y() < 0 || |
388 rect.maxX() > m_surface->size().width() || | 375 rect.maxX() > m_surface->size().width() || |
389 rect.maxY() > m_surface->size().height(); | 376 rect.maxY() > m_surface->size().height(); |
(...skipping 25 matching lines...) Expand all Loading... |
415 sk_sp<SkColorSpace> colorSpace = nullptr; | 402 sk_sp<SkColorSpace> colorSpace = nullptr; |
416 if (m_surface->colorSpace()) { | 403 if (m_surface->colorSpace()) { |
417 colorSpace = SkColorSpace::MakeSRGB(); | 404 colorSpace = SkColorSpace::MakeSRGB(); |
418 } | 405 } |
419 | 406 |
420 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), colorType, | 407 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), colorType, |
421 alphaType, std::move(colorSpace)); | 408 alphaType, std::move(colorSpace)); |
422 | 409 |
423 snapshot->readPixels(info, result.data(), bytesPerPixel * rect.width(), | 410 snapshot->readPixels(info, result.data(), bytesPerPixel * rect.width(), |
424 rect.x(), rect.y()); | 411 rect.x(), rect.y()); |
425 m_gpuReadbackInvokedInCurrentFrame = true; | |
426 | 412 |
427 if (useF16Workaround) { | 413 if (useF16Workaround) { |
428 uint32_t* pixel = (uint32_t*)result.data(); | 414 uint32_t* pixel = (uint32_t*)result.data(); |
429 size_t pixelCount = allocSizeInBytes / sizeof(uint32_t); | 415 size_t pixelCount = allocSizeInBytes / sizeof(uint32_t); |
430 // TODO(skbug.com/5853): make readPixels support RGBA output so that we no | 416 // TODO(skbug.com/5853): make readPixels support RGBA output so that we no |
431 // longer | 417 // longer |
432 // have to do this. | 418 // have to do this. |
433 if (kN32_SkColorType == kBGRA_8888_SkColorType) { | 419 if (kN32_SkColorType == kBGRA_8888_SkColorType) { |
434 // Convert BGRA to RGBA if necessary on this platform. | 420 // Convert BGRA to RGBA if necessary on this platform. |
435 SkSwapRB(pixel, pixel, pixelCount); | 421 SkSwapRB(pixel, pixel, pixelCount); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 608 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
623 | 609 |
624 Vector<unsigned char> result; | 610 Vector<unsigned char> result; |
625 if (!encodeImage(mimeType, quality, &result)) | 611 if (!encodeImage(mimeType, quality, &result)) |
626 return "data:,"; | 612 return "data:,"; |
627 | 613 |
628 return "data:" + mimeType + ";base64," + base64Encode(result); | 614 return "data:" + mimeType + ";base64," + base64Encode(result); |
629 } | 615 } |
630 | 616 |
631 } // namespace blink | 617 } // namespace blink |
OLD | NEW |