| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "third_party/skia/include/gpu/GrContext.h" | 57 #include "third_party/skia/include/gpu/GrContext.h" |
| 58 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 58 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 59 #include "wtf/MathExtras.h" | 59 #include "wtf/MathExtras.h" |
| 60 #include "wtf/text/Base64.h" | 60 #include "wtf/text/Base64.h" |
| 61 #include "wtf/text/WTFString.h" | 61 #include "wtf/text/WTFString.h" |
| 62 | 62 |
| 63 using namespace std; | 63 using namespace std; |
| 64 | 64 |
| 65 namespace WebCore { | 65 namespace WebCore { |
| 66 | 66 |
| 67 static PassRefPtr<SkCanvas> createAcceleratedCanvas(const IntSize& size, Canvas2
DLayerBridgePtr* outLayerBridge, OpacityMode opacityMode) | 67 static PassRefPtr<SkCanvas> createAcceleratedCanvas(const IntSize& size, Canvas2
DLayerBridgePtr* outLayerBridge, OpacityMode opacityMode, int msaaSampleCount) |
| 68 { | 68 { |
| 69 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 69 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
| 70 if (!context3D) | 70 if (!context3D) |
| 71 return 0; | 71 return 0; |
| 72 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; | 72 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; |
| 73 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri
dgeOpacityMode); | 73 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri
dgeOpacityMode, msaaSampleCount); |
| 74 // If canvas buffer allocation failed, debug build will have asserted | 74 // If canvas buffer allocation failed, debug build will have asserted |
| 75 // For release builds, we must verify whether the device has a render target | 75 // For release builds, we must verify whether the device has a render target |
| 76 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; | 76 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; |
| 77 } | 77 } |
| 78 | 78 |
| 79 static PassRefPtr<SkCanvas> createNonPlatformCanvas(const IntSize& size) | 79 static PassRefPtr<SkCanvas> createNonPlatformCanvas(const IntSize& size) |
| 80 { | 80 { |
| 81 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(SkBitmap::kARGB_8888_Co
nfig, size.width(), size.height())); | 81 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(SkBitmap::kARGB_8888_Co
nfig, size.width(), size.height())); |
| 82 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); | 82 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); |
| 83 return adoptRef(pixelRef ? new SkCanvas(device) : 0); | 83 return adoptRef(pixelRef ? new SkCanvas(device) : 0); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 | 116 |
| 117 m_canvas = adoptRef(new SkCanvas(device)); | 117 m_canvas = adoptRef(new SkCanvas(device)); |
| 118 m_context = adoptPtr(new GraphicsContext(m_canvas.get())); | 118 m_context = adoptPtr(new GraphicsContext(m_canvas.get())); |
| 119 m_context->setCertainlyOpaque(!hasAlpha); | 119 m_context->setCertainlyOpaque(!hasAlpha); |
| 120 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); | 120 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); |
| 121 | 121 |
| 122 success = true; | 122 success = true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, RenderingMo
de renderingMode, OpacityMode opacityMode, bool& success) | 125 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, RenderingMo
de renderingMode, OpacityMode opacityMode, int acceleratedMSAASampleCount, bool&
success) |
| 126 : m_size(size) | 126 : m_size(size) |
| 127 , m_logicalSize(size) | 127 , m_logicalSize(size) |
| 128 , m_resolutionScale(resolutionScale) | 128 , m_resolutionScale(resolutionScale) |
| 129 { | 129 { |
| 130 if (renderingMode == Accelerated) { | 130 if (renderingMode == Accelerated) { |
| 131 m_canvas = createAcceleratedCanvas(size, &m_layerBridge, opacityMode); | 131 m_canvas = createAcceleratedCanvas(size, &m_layerBridge, opacityMode, ac
celeratedMSAASampleCount); |
| 132 if (!m_canvas) | 132 if (!m_canvas) |
| 133 renderingMode = UnacceleratedNonPlatformBuffer; | 133 renderingMode = UnacceleratedNonPlatformBuffer; |
| 134 } | 134 } |
| 135 | 135 |
| 136 if (renderingMode == UnacceleratedNonPlatformBuffer) | 136 if (renderingMode == UnacceleratedNonPlatformBuffer) |
| 137 m_canvas = createNonPlatformCanvas(size); | 137 m_canvas = createNonPlatformCanvas(size); |
| 138 | 138 |
| 139 if (!m_canvas) | 139 if (!m_canvas) |
| 140 m_canvas = adoptRef(skia::TryCreateBitmapCanvas(size.width(), size.heigh
t(), false)); | 140 m_canvas = adoptRef(skia::TryCreateBitmapCanvas(size.width(), size.heigh
t(), false)); |
| 141 | 141 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 492 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
| 493 return "data:,"; | 493 return "data:,"; |
| 494 | 494 |
| 495 Vector<char> base64Data; | 495 Vector<char> base64Data; |
| 496 base64Encode(encodedImage, base64Data); | 496 base64Encode(encodedImage, base64Data); |
| 497 | 497 |
| 498 return "data:" + mimeType + ";base64," + base64Data; | 498 return "data:" + mimeType + ";base64," + base64Data; |
| 499 } | 499 } |
| 500 | 500 |
| 501 } // namespace WebCore | 501 } // namespace WebCore |
| OLD | NEW |