| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 #include "config.h" | |
| 7 | |
| 8 #if USE(ACCELERATED_COMPOSITING) | |
| 9 | |
| 10 #include "FrameBufferSkPictureCanvasLayerTextureUpdater.h" | |
| 11 | |
| 12 #include "CCProxy.h" | |
| 13 #include "LayerPainterChromium.h" | |
| 14 #include "SkCanvas.h" | |
| 15 #include "SkGpuDevice.h" | |
| 16 #include <public/WebGraphicsContext3D.h> | |
| 17 #include <public/WebSharedGraphicsContext3D.h> | |
| 18 | |
| 19 using WebKit::WebGraphicsContext3D; | |
| 20 using WebKit::WebSharedGraphicsContext3D; | |
| 21 | |
| 22 namespace cc { | |
| 23 | |
| 24 static PassOwnPtr<SkCanvas> createAcceleratedCanvas(GrContext* grContext, | |
| 25 IntSize canvasSize, | |
| 26 unsigned textureId) | |
| 27 { | |
| 28 GrPlatformTextureDesc textureDesc; | |
| 29 textureDesc.fFlags = kRenderTarget_GrPlatformTextureFlag; | |
| 30 textureDesc.fWidth = canvasSize.width(); | |
| 31 textureDesc.fHeight = canvasSize.height(); | |
| 32 textureDesc.fConfig = kSkia8888_GrPixelConfig; | |
| 33 textureDesc.fTextureHandle = textureId; | |
| 34 SkAutoTUnref<GrTexture> target(grContext->createPlatformTexture(textureDesc)
); | |
| 35 SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get())); | |
| 36 return adoptPtr(new SkCanvas(device.get())); | |
| 37 } | |
| 38 | |
| 39 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::Texture(FrameBufferSkPic
tureCanvasLayerTextureUpdater* textureUpdater, scoped_ptr<CCPrioritizedTexture>
texture) | |
| 40 : LayerTextureUpdater::Texture(texture.Pass()) | |
| 41 , m_textureUpdater(textureUpdater) | |
| 42 { | |
| 43 } | |
| 44 | |
| 45 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::~Texture() | |
| 46 { | |
| 47 } | |
| 48 | |
| 49 void FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::updateRect(CCResour
ceProvider* resourceProvider, const IntRect& sourceRect, const IntSize& destOffs
et) | |
| 50 { | |
| 51 WebGraphicsContext3D* sharedContext = CCProxy::hasImplThread() ? WebSharedGr
aphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThr
eadContext(); | |
| 52 GrContext* sharedGrContext = CCProxy::hasImplThread() ? WebSharedGraphicsCon
text3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrCo
ntext(); | |
| 53 if (!sharedContext || !sharedGrContext) | |
| 54 return; | |
| 55 textureUpdater()->updateTextureRect(sharedContext, sharedGrContext, resource
Provider, texture(), sourceRect, destOffset); | |
| 56 } | |
| 57 | |
| 58 PassRefPtr<FrameBufferSkPictureCanvasLayerTextureUpdater> FrameBufferSkPictureCa
nvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter) | |
| 59 { | |
| 60 return adoptRef(new FrameBufferSkPictureCanvasLayerTextureUpdater(painter)); | |
| 61 } | |
| 62 | |
| 63 FrameBufferSkPictureCanvasLayerTextureUpdater::FrameBufferSkPictureCanvasLayerTe
xtureUpdater(PassOwnPtr<LayerPainterChromium> painter) | |
| 64 : SkPictureCanvasLayerTextureUpdater(painter) | |
| 65 { | |
| 66 } | |
| 67 | |
| 68 FrameBufferSkPictureCanvasLayerTextureUpdater::~FrameBufferSkPictureCanvasLayerT
extureUpdater() | |
| 69 { | |
| 70 } | |
| 71 | |
| 72 PassOwnPtr<LayerTextureUpdater::Texture> FrameBufferSkPictureCanvasLayerTextureU
pdater::createTexture(CCPrioritizedTextureManager* manager) | |
| 73 { | |
| 74 return adoptPtr(new Texture(this, CCPrioritizedTexture::create(manager))); | |
| 75 } | |
| 76 | |
| 77 LayerTextureUpdater::SampledTexelFormat FrameBufferSkPictureCanvasLayerTextureUp
dater::sampledTexelFormat(GC3Denum textureFormat) | |
| 78 { | |
| 79 // Here we directly render to the texture, so the component order is always
correct. | |
| 80 return LayerTextureUpdater::SampledTexelFormatRGBA; | |
| 81 } | |
| 82 | |
| 83 void FrameBufferSkPictureCanvasLayerTextureUpdater::updateTextureRect(WebGraphic
sContext3D* context, GrContext* grContext, CCResourceProvider* resourceProvider,
CCPrioritizedTexture* texture, const IntRect& sourceRect, const IntSize& destOf
fset) | |
| 84 { | |
| 85 texture->acquireBackingTexture(resourceProvider); | |
| 86 // Flush the context in which the backing texture is created so that it | |
| 87 // is available in other shared contexts. It is important to do here | |
| 88 // because the backing texture is created in one context while it is | |
| 89 // being written to in another. | |
| 90 resourceProvider->flush(); | |
| 91 CCResourceProvider::ScopedWriteLockGL lock(resourceProvider, texture->resour
ceId()); | |
| 92 | |
| 93 // Make sure ganesh uses the correct GL context. | |
| 94 context->makeContextCurrent(); | |
| 95 // Create an accelerated canvas to draw on. | |
| 96 OwnPtr<SkCanvas> canvas = createAcceleratedCanvas(grContext, texture->size()
, lock.textureId()); | |
| 97 | |
| 98 // The compositor expects the textures to be upside-down so it can flip | |
| 99 // the final composited image. Ganesh renders the image upright so we | |
| 100 // need to do a y-flip. | |
| 101 canvas->translate(0.0, texture->size().height()); | |
| 102 canvas->scale(1.0, -1.0); | |
| 103 // Clip to the destination on the texture that must be updated. | |
| 104 canvas->clipRect(SkRect::MakeXYWH(destOffset.width(), destOffset.height(), s
ourceRect.width(), sourceRect.height())); | |
| 105 // Translate the origin of contentRect to that of destRect. | |
| 106 // Note that destRect is defined relative to sourceRect. | |
| 107 canvas->translate(contentRect().x() - sourceRect.x() + destOffset.width(), | |
| 108 contentRect().y() - sourceRect.y() + destOffset.height()); | |
| 109 drawPicture(canvas.get()); | |
| 110 | |
| 111 // Flush ganesh context so that all the rendered stuff appears on the textur
e. | |
| 112 grContext->flush(); | |
| 113 | |
| 114 // Flush the GL context so rendering results from this context are visible i
n the compositor's context. | |
| 115 context->flush(); | |
| 116 } | |
| 117 | |
| 118 } // namespace cc | |
| 119 #endif // USE(ACCELERATED_COMPOSITING) | |
| OLD | NEW |