| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #include "config.h" | 6 #include "config.h" |
| 7 | 7 |
| 8 #if USE(ACCELERATED_COMPOSITING) | 8 #if USE(ACCELERATED_COMPOSITING) |
| 9 | 9 |
| 10 #include "FrameBufferSkPictureCanvasLayerTextureUpdater.h" | 10 #include "FrameBufferSkPictureCanvasLayerTextureUpdater.h" |
| 11 | 11 |
| 12 #include "CCProxy.h" | 12 #include "CCProxy.h" |
| 13 #include "LayerPainterChromium.h" | 13 #include "LayerPainterChromium.h" |
| 14 #include "SkCanvas.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 | 15 |
| 22 namespace cc { | 16 namespace cc { |
| 23 | 17 |
| 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, PassOwnPtr<CCPrioritizedTexture>
texture) | 18 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::Texture(FrameBufferSkPic
tureCanvasLayerTextureUpdater* textureUpdater, PassOwnPtr<CCPrioritizedTexture>
texture) |
| 40 : LayerTextureUpdater::Texture(texture) | 19 : LayerTextureUpdater::Texture(texture) |
| 41 , m_textureUpdater(textureUpdater) | 20 , m_textureUpdater(textureUpdater) |
| 42 { | 21 { |
| 43 } | 22 } |
| 44 | 23 |
| 45 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::~Texture() | 24 FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::~Texture() |
| 46 { | 25 { |
| 47 } | 26 } |
| 48 | 27 |
| 49 void FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::updateRect(CCResour
ceProvider* resourceProvider, const IntRect& sourceRect, const IntSize& destOffs
et) | 28 void FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::update(CCTextureUpd
ateQueue& queue, const IntRect& sourceRect, const IntSize& destOffset, bool part
ialUpdate, CCRenderingStats&) |
| 50 { | 29 { |
| 51 WebGraphicsContext3D* sharedContext = CCProxy::hasImplThread() ? WebSharedGr
aphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThr
eadContext(); | 30 textureUpdater()->updateTexture(queue, texture(), sourceRect, destOffset, pa
rtialUpdate); |
| 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 } | 31 } |
| 57 | 32 |
| 58 PassRefPtr<FrameBufferSkPictureCanvasLayerTextureUpdater> FrameBufferSkPictureCa
nvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter) | 33 PassRefPtr<FrameBufferSkPictureCanvasLayerTextureUpdater> FrameBufferSkPictureCa
nvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter) |
| 59 { | 34 { |
| 60 return adoptRef(new FrameBufferSkPictureCanvasLayerTextureUpdater(painter)); | 35 return adoptRef(new FrameBufferSkPictureCanvasLayerTextureUpdater(painter)); |
| 61 } | 36 } |
| 62 | 37 |
| 63 FrameBufferSkPictureCanvasLayerTextureUpdater::FrameBufferSkPictureCanvasLayerTe
xtureUpdater(PassOwnPtr<LayerPainterChromium> painter) | 38 FrameBufferSkPictureCanvasLayerTextureUpdater::FrameBufferSkPictureCanvasLayerTe
xtureUpdater(PassOwnPtr<LayerPainterChromium> painter) |
| 64 : SkPictureCanvasLayerTextureUpdater(painter) | 39 : SkPictureCanvasLayerTextureUpdater(painter) |
| 65 { | 40 { |
| 66 } | 41 } |
| 67 | 42 |
| 68 FrameBufferSkPictureCanvasLayerTextureUpdater::~FrameBufferSkPictureCanvasLayerT
extureUpdater() | 43 FrameBufferSkPictureCanvasLayerTextureUpdater::~FrameBufferSkPictureCanvasLayerT
extureUpdater() |
| 69 { | 44 { |
| 70 } | 45 } |
| 71 | 46 |
| 72 PassOwnPtr<LayerTextureUpdater::Texture> FrameBufferSkPictureCanvasLayerTextureU
pdater::createTexture(CCPrioritizedTextureManager* manager) | 47 PassOwnPtr<LayerTextureUpdater::Texture> FrameBufferSkPictureCanvasLayerTextureU
pdater::createTexture(CCPrioritizedTextureManager* manager) |
| 73 { | 48 { |
| 74 return adoptPtr(new Texture(this, CCPrioritizedTexture::create(manager))); | 49 return adoptPtr(new Texture(this, CCPrioritizedTexture::create(manager))); |
| 75 } | 50 } |
| 76 | 51 |
| 77 LayerTextureUpdater::SampledTexelFormat FrameBufferSkPictureCanvasLayerTextureUp
dater::sampledTexelFormat(GC3Denum textureFormat) | 52 LayerTextureUpdater::SampledTexelFormat FrameBufferSkPictureCanvasLayerTextureUp
dater::sampledTexelFormat(GC3Denum textureFormat) |
| 78 { | 53 { |
| 79 // Here we directly render to the texture, so the component order is always
correct. | 54 // Here we directly render to the texture, so the component order is always
correct. |
| 80 return LayerTextureUpdater::SampledTexelFormatRGBA; | 55 return LayerTextureUpdater::SampledTexelFormatRGBA; |
| 81 } | 56 } |
| 82 | 57 |
| 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 | 58 } // namespace cc |
| 119 #endif // USE(ACCELERATED_COMPOSITING) | 59 #endif // USE(ACCELERATED_COMPOSITING) |
| OLD | NEW |