OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions |
| 6 * are met: |
| 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. |
| 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ |
| 25 |
| 26 |
| 27 #include "config.h" |
| 28 |
| 29 #if USE(ACCELERATED_COMPOSITING) |
| 30 |
| 31 #include "FrameBufferSkPictureCanvasLayerTextureUpdater.h" |
| 32 |
| 33 #include "LayerPainterChromium.h" |
| 34 //#include "SharedGraphicsContext3D.h" |
| 35 #include "SkCanvas.h" |
| 36 #include "SkGpuDevice.h" |
| 37 #include "cc/CCProxy.h" |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 /* |
| 42 static PassOwnPtr<SkCanvas> createAcceleratedCanvas(GraphicsContext3D* context, |
| 43 TextureAllocator* allocator, |
| 44 ManagedTexture* texture) |
| 45 { |
| 46 // Allocate so that we have a valid texture id. |
| 47 texture->allocate(allocator); |
| 48 |
| 49 GrContext* grContext = context->grContext(); |
| 50 IntSize canvasSize = texture->size(); |
| 51 GrPlatformTextureDesc textureDesc; |
| 52 textureDesc.fFlags = kRenderTarget_GrPlatformTextureFlag; |
| 53 textureDesc.fWidth = canvasSize.width(); |
| 54 textureDesc.fHeight = canvasSize.height(); |
| 55 textureDesc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 56 textureDesc.fTextureHandle = texture->textureId(); |
| 57 SkAutoTUnref<GrTexture> target(grContext->createPlatformTexture(textureDesc)
); |
| 58 SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get())); |
| 59 return adoptPtr(new SkCanvas(device.get())); |
| 60 } |
| 61 */ |
| 62 |
| 63 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::Texture(FrameBufferSkPic
tureCanvasLayerTextureUpdater* textureUpdater, PassOwnPtr<ManagedTexture> textur
e) |
| 64 : LayerTextureUpdater::Texture(texture) |
| 65 , m_textureUpdater(textureUpdater) |
| 66 { |
| 67 } |
| 68 |
| 69 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::~Texture() |
| 70 { |
| 71 } |
| 72 |
| 73 void FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::updateRect(CCGraphi
csContext*, TextureAllocator* allocator, const IntRect& sourceRect, const IntRec
t& destRect) |
| 74 { |
| 75 /* |
| 76 RefPtr<GraphicsContext3D> sharedContext = CCProxy::hasImplThread() ? SharedG
raphicsContext3D::getForImplThread() : SharedGraphicsContext3D::get(); |
| 77 if (!sharedContext) |
| 78 return; |
| 79 textureUpdater()->updateTextureRect(sharedContext.release(), allocator, text
ure(), sourceRect, destRect); |
| 80 */ |
| 81 } |
| 82 |
| 83 PassRefPtr<FrameBufferSkPictureCanvasLayerTextureUpdater> FrameBufferSkPictureCa
nvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter) |
| 84 { |
| 85 return adoptRef(new FrameBufferSkPictureCanvasLayerTextureUpdater(painter)); |
| 86 } |
| 87 |
| 88 FrameBufferSkPictureCanvasLayerTextureUpdater::FrameBufferSkPictureCanvasLayerTe
xtureUpdater(PassOwnPtr<LayerPainterChromium> painter) |
| 89 : SkPictureCanvasLayerTextureUpdater(painter) |
| 90 { |
| 91 } |
| 92 |
| 93 FrameBufferSkPictureCanvasLayerTextureUpdater::~FrameBufferSkPictureCanvasLayerT
extureUpdater() |
| 94 { |
| 95 } |
| 96 |
| 97 PassOwnPtr<LayerTextureUpdater::Texture> FrameBufferSkPictureCanvasLayerTextureU
pdater::createTexture(TextureManager* manager) |
| 98 { |
| 99 return adoptPtr(new Texture(this, ManagedTexture::create(manager))); |
| 100 } |
| 101 |
| 102 LayerTextureUpdater::SampledTexelFormat FrameBufferSkPictureCanvasLayerTextureUp
dater::sampledTexelFormat(GC3Denum textureFormat) |
| 103 { |
| 104 // Here we directly render to the texture, so the component order is always
correct. |
| 105 return LayerTextureUpdater::SampledTexelFormatRGBA; |
| 106 } |
| 107 |
| 108 /* |
| 109 void FrameBufferSkPictureCanvasLayerTextureUpdater::updateTextureRect(PassRefPtr
<GraphicsContext3D> prpContext, TextureAllocator* allocator, ManagedTexture* tex
ture, const IntRect& sourceRect, const IntRect& destRect) |
| 110 { |
| 111 RefPtr<GraphicsContext3D> context(prpContext); |
| 112 |
| 113 // Make sure ganesh uses the correct GL context. |
| 114 context->makeContextCurrent(); |
| 115 |
| 116 // Create an accelerated canvas to draw on. |
| 117 OwnPtr<SkCanvas> canvas = createAcceleratedCanvas(context.get(), allocator,
texture); |
| 118 |
| 119 // The compositor expects the textures to be upside-down so it can flip |
| 120 // the final composited image. Ganesh renders the image upright so we |
| 121 // need to do a y-flip. |
| 122 canvas->translate(0.0, texture->size().height()); |
| 123 canvas->scale(1.0, -1.0); |
| 124 // Only the region corresponding to destRect on the texture must be updated. |
| 125 canvas->clipRect(SkRect(destRect)); |
| 126 // Translate the origin of contentRect to that of destRect. |
| 127 // Note that destRect is defined relative to sourceRect. |
| 128 canvas->translate(contentRect().x() - sourceRect.x() + destRect.x(), |
| 129 contentRect().y() - sourceRect.y() + destRect.y()); |
| 130 drawPicture(canvas.get()); |
| 131 |
| 132 // Flush ganesh context so that all the rendered stuff appears on the textur
e. |
| 133 context->grContext()->flush(); |
| 134 |
| 135 // Flush the GL context so rendering results from this context are visible i
n the compositor's context. |
| 136 context->flush(); |
| 137 } |
| 138 */ |
| 139 |
| 140 } // namespace WebCore |
| 141 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |