| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 Canvas2DLayerChromium::Canvas2DLayerChromium(DrawingBuffer* drawingBuffer, Graph
icsLayerChromium* owner) | 49 Canvas2DLayerChromium::Canvas2DLayerChromium(DrawingBuffer* drawingBuffer, Graph
icsLayerChromium* owner) |
| 50 : CanvasLayerChromium(owner) | 50 : CanvasLayerChromium(owner) |
| 51 , m_drawingBuffer(drawingBuffer) | 51 , m_drawingBuffer(drawingBuffer) |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 | 54 |
| 55 Canvas2DLayerChromium::~Canvas2DLayerChromium() | 55 Canvas2DLayerChromium::~Canvas2DLayerChromium() |
| 56 { | 56 { |
| 57 if (m_textureId) | |
| 58 layerRendererContext()->deleteTexture(m_textureId); | |
| 59 if (m_drawingBuffer && layerRenderer()) | 57 if (m_drawingBuffer && layerRenderer()) |
| 60 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext3D()
.get()); | 58 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext3D()
.get()); |
| 61 } | 59 } |
| 62 | 60 |
| 63 bool Canvas2DLayerChromium::drawsContent() const | 61 bool Canvas2DLayerChromium::drawsContent() const |
| 64 { | 62 { |
| 65 GraphicsContext3D* context; | 63 GraphicsContext3D* context; |
| 66 return (m_drawingBuffer | 64 return (m_drawingBuffer |
| 67 && (context = m_drawingBuffer->graphicsContext3D().get()) | 65 && (context = m_drawingBuffer->graphicsContext3D().get()) |
| 68 && (context->getExtensions()->getGraphicsResetStatusARB() == Graphic
sContext3D::NO_ERROR)); | 66 && (context->getExtensions()->getGraphicsResetStatusARB() == Graphic
sContext3D::NO_ERROR)); |
| 69 } | 67 } |
| 70 | 68 |
| 71 void Canvas2DLayerChromium::updateCompositorResources() | 69 void Canvas2DLayerChromium::updateCompositorResources() |
| 72 { | 70 { |
| 73 if (!m_contentsDirty || !drawsContent()) | 71 if (!m_contentsDirty || !drawsContent()) |
| 74 return; | 72 return; |
| 75 if (m_textureChanged) { // We have to generate a new backing texture. | |
| 76 GraphicsContext3D* context = layerRendererContext(); | |
| 77 if (m_textureId) | |
| 78 context->deleteTexture(m_textureId); | |
| 79 m_textureId = context->createTexture(); | |
| 80 context->activeTexture(GraphicsContext3D::TEXTURE0); | |
| 81 context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId); | |
| 82 IntSize size = m_drawingBuffer->size(); | |
| 83 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, Graphi
csContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, Grap
hicsContext3D::UNSIGNED_BYTE); | |
| 84 // Set the min-mag filters to linear and wrap modes to GraphicsContext3D
::CLAMP_TO_EDGE | |
| 85 // to get around NPOT texture limitations of GLES. | |
| 86 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D:
:TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); | |
| 87 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D:
:TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); | |
| 88 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D:
:TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); | |
| 89 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D:
:TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); | |
| 90 m_textureChanged = false; | |
| 91 // The flush() here is required because we have to make sure that the te
xture created in this | |
| 92 // context (the compositor context) is actually created by the service s
ide before the child context | |
| 93 // attempts to use it (in publishToPlatformLayer). | |
| 94 context->flush(); | |
| 95 } | |
| 96 // Update the contents of the texture used by the compositor. | 73 // Update the contents of the texture used by the compositor. |
| 97 if (m_contentsDirty) { | 74 if (m_contentsDirty) { |
| 98 m_drawingBuffer->publishToPlatformLayer(); | 75 m_drawingBuffer->publishToPlatformLayer(); |
| 99 m_contentsDirty = false; | 76 m_contentsDirty = false; |
| 100 } | 77 } |
| 101 } | 78 } |
| 102 | 79 |
| 103 void Canvas2DLayerChromium::setTextureChanged() | |
| 104 { | |
| 105 m_textureChanged = true; | |
| 106 } | |
| 107 | |
| 108 unsigned Canvas2DLayerChromium::textureId() const | 80 unsigned Canvas2DLayerChromium::textureId() const |
| 109 { | 81 { |
| 110 return m_textureId; | 82 return m_drawingBuffer ? m_drawingBuffer->platformColorBuffer() : 0; |
| 111 } | 83 } |
| 112 | 84 |
| 113 void Canvas2DLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer) | 85 void Canvas2DLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer) |
| 114 { | 86 { |
| 115 if (drawingBuffer != m_drawingBuffer) { | 87 if (drawingBuffer != m_drawingBuffer) { |
| 116 if (m_drawingBuffer && layerRenderer()) | 88 if (m_drawingBuffer && layerRenderer()) |
| 117 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext
3D().get()); | 89 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext
3D().get()); |
| 118 | 90 |
| 119 m_drawingBuffer = drawingBuffer; | 91 m_drawingBuffer = drawingBuffer; |
| 120 m_textureChanged = true; | |
| 121 | 92 |
| 122 if (drawingBuffer && layerRenderer()) | 93 if (drawingBuffer && layerRenderer()) |
| 123 layerRenderer()->addChildContext(m_drawingBuffer->graphicsContext3D(
).get()); | 94 layerRenderer()->addChildContext(m_drawingBuffer->graphicsContext3D(
).get()); |
| 124 } | 95 } |
| 125 } | 96 } |
| 126 | 97 |
| 127 void Canvas2DLayerChromium::setLayerRenderer(LayerRendererChromium* newLayerRend
erer) | 98 void Canvas2DLayerChromium::setLayerRenderer(LayerRendererChromium* newLayerRend
erer) |
| 128 { | 99 { |
| 129 if (layerRenderer() != newLayerRenderer && m_drawingBuffer) { | 100 if (layerRenderer() != newLayerRenderer && m_drawingBuffer) { |
| 130 if (m_drawingBuffer->graphicsContext3D()) { | 101 if (m_drawingBuffer->graphicsContext3D()) { |
| 131 if (layerRenderer()) | 102 if (layerRenderer()) |
| 132 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsCon
text3D().get()); | 103 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsCon
text3D().get()); |
| 133 if (newLayerRenderer) | 104 if (newLayerRenderer) |
| 134 newLayerRenderer->addChildContext(m_drawingBuffer->graphicsConte
xt3D().get()); | 105 newLayerRenderer->addChildContext(m_drawingBuffer->graphicsConte
xt3D().get()); |
| 135 } | 106 } |
| 136 | 107 |
| 137 LayerChromium::setLayerRenderer(newLayerRenderer); | 108 LayerChromium::setLayerRenderer(newLayerRenderer); |
| 138 } | 109 } |
| 139 } | 110 } |
| 140 | 111 |
| 141 } | 112 } |
| 142 #endif // USE(ACCELERATED_COMPOSITING) | 113 #endif // USE(ACCELERATED_COMPOSITING) |
| OLD | NEW |