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