| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCDirectRenderer.h" | 7 #include "CCDirectRenderer.h" |
| 8 | 8 |
| 9 #include "CCMathUtil.h" | 9 #include "CCMathUtil.h" |
| 10 #include "ui/gfx/rect_conversions.h" |
| 10 #include <public/WebTransformationMatrix.h> | 11 #include <public/WebTransformationMatrix.h> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 using WebKit::WebTransformationMatrix; | 14 using WebKit::WebTransformationMatrix; |
| 14 | 15 |
| 15 static WebTransformationMatrix orthoProjectionMatrix(float left, float right, fl
oat bottom, float top) | 16 static WebTransformationMatrix orthoProjectionMatrix(float left, float right, fl
oat bottom, float top) |
| 16 { | 17 { |
| 17 // Use the standard formula to map the clipping frustum to the cube from | 18 // Use the standard formula to map the clipping frustum to the cube from |
| 18 // [-1, -1, -1] to [1, 1, 1]. | 19 // [-1, -1, -1] to [1, 1, 1]. |
| 19 float deltaX = right - left; | 20 float deltaX = right - left; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 64 } |
| 64 | 65 |
| 65 // | 66 // |
| 66 // static | 67 // static |
| 67 FloatRect CCDirectRenderer::quadVertexRect() | 68 FloatRect CCDirectRenderer::quadVertexRect() |
| 68 { | 69 { |
| 69 return FloatRect(-0.5, -0.5, 1, 1); | 70 return FloatRect(-0.5, -0.5, 1, 1); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // static | 73 // static |
| 73 void CCDirectRenderer::quadRectTransform(WebKit::WebTransformationMatrix* quadRe
ctTransform, const WebKit::WebTransformationMatrix& quadTransform, const FloatRe
ct& quadRect) | 74 void CCDirectRenderer::quadRectTransform(WebKit::WebTransformationMatrix* quadRe
ctTransform, const WebKit::WebTransformationMatrix& quadTransform, const gfx::Re
ctF& quadRect) |
| 74 { | 75 { |
| 75 *quadRectTransform = quadTransform; | 76 *quadRectTransform = quadTransform; |
| 76 quadRectTransform->translate(0.5 * quadRect.width() + quadRect.x(), 0.5 * qu
adRect.height() + quadRect.y()); | 77 quadRectTransform->translate(0.5 * quadRect.width() + quadRect.x(), 0.5 * qu
adRect.height() + quadRect.y()); |
| 77 quadRectTransform->scaleNonUniform(quadRect.width(), quadRect.height()); | 78 quadRectTransform->scaleNonUniform(quadRect.width(), quadRect.height()); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // static | 81 // static |
| 81 void CCDirectRenderer::initializeMatrices(DrawingFrame& frame, const IntRect& dr
awRect, bool flipY) | 82 void CCDirectRenderer::initializeMatrices(DrawingFrame& frame, const gfx::Rect&
drawRect, bool flipY) |
| 82 { | 83 { |
| 83 if (flipY) | 84 if (flipY) |
| 84 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ma
xX(), drawRect.maxY(), drawRect.y()); | 85 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ri
ght(), drawRect.bottom(), drawRect.y()); |
| 85 else | 86 else |
| 86 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ma
xX(), drawRect.y(), drawRect.maxY()); | 87 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ri
ght(), drawRect.y(), drawRect.bottom()); |
| 87 frame.windowMatrix = windowMatrix(0, 0, drawRect.width(), drawRect.height())
; | 88 frame.windowMatrix = windowMatrix(0, 0, drawRect.width(), drawRect.height())
; |
| 88 frame.flippedY = flipY; | 89 frame.flippedY = flipY; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // static | 92 // static |
| 92 IntRect CCDirectRenderer::moveScissorToWindowSpace(const DrawingFrame& frame, Fl
oatRect scissorRect) | 93 gfx::Rect CCDirectRenderer::moveScissorToWindowSpace(const DrawingFrame& frame,
gfx::RectF scissorRect) |
| 93 { | 94 { |
| 94 IntRect scissorRectInCanvasSpace = enclosingIntRect(scissorRect); | 95 gfx::Rect scissorRectInCanvasSpace = gfx::ToEnclosingRect(scissorRect); |
| 95 // The scissor coordinates must be supplied in viewport space so we need to
offset | 96 // The scissor coordinates must be supplied in viewport space so we need to
offset |
| 96 // by the relative position of the top left corner of the current render pas
s. | 97 // by the relative position of the top left corner of the current render pas
s. |
| 97 IntRect framebufferOutputRect = frame.currentRenderPass->outputRect(); | 98 gfx::Rect framebufferOutputRect = frame.currentRenderPass->outputRect(); |
| 98 scissorRectInCanvasSpace.setX(scissorRectInCanvasSpace.x() - framebufferOutp
utRect.x()); | 99 scissorRectInCanvasSpace.set_x(scissorRectInCanvasSpace.x() - framebufferOut
putRect.x()); |
| 99 if (frame.flippedY && !frame.currentTexture) | 100 if (frame.flippedY && !frame.currentTexture) |
| 100 scissorRectInCanvasSpace.setY(framebufferOutputRect.height() - (scissorR
ectInCanvasSpace.maxY() - framebufferOutputRect.y())); | 101 scissorRectInCanvasSpace.set_y(framebufferOutputRect.height() - (scissor
RectInCanvasSpace.bottom() - framebufferOutputRect.y())); |
| 101 else | 102 else |
| 102 scissorRectInCanvasSpace.setY(scissorRectInCanvasSpace.y() - framebuffer
OutputRect.y()); | 103 scissorRectInCanvasSpace.set_y(scissorRectInCanvasSpace.y() - framebuffe
rOutputRect.y()); |
| 103 return scissorRectInCanvasSpace; | 104 return scissorRectInCanvasSpace; |
| 104 } | 105 } |
| 105 | 106 |
| 106 CCDirectRenderer::CCDirectRenderer(CCRendererClient* client, CCResourceProvider*
resourceProvider) | 107 CCDirectRenderer::CCDirectRenderer(CCRendererClient* client, CCResourceProvider*
resourceProvider) |
| 107 : CCRenderer(client) | 108 : CCRenderer(client) |
| 108 , m_resourceProvider(resourceProvider) | 109 , m_resourceProvider(resourceProvider) |
| 109 { | 110 { |
| 110 } | 111 } |
| 111 | 112 |
| 112 CCDirectRenderer::~CCDirectRenderer() | 113 CCDirectRenderer::~CCDirectRenderer() |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 153 |
| 153 void CCDirectRenderer::drawFrame(const CCRenderPassList& renderPassesInDrawOrder
, const CCRenderPassIdHashMap& renderPassesById) | 154 void CCDirectRenderer::drawFrame(const CCRenderPassList& renderPassesInDrawOrder
, const CCRenderPassIdHashMap& renderPassesById) |
| 154 { | 155 { |
| 155 const CCRenderPass* rootRenderPass = renderPassesInDrawOrder.back(); | 156 const CCRenderPass* rootRenderPass = renderPassesInDrawOrder.back(); |
| 156 DCHECK(rootRenderPass); | 157 DCHECK(rootRenderPass); |
| 157 | 158 |
| 158 DrawingFrame frame; | 159 DrawingFrame frame; |
| 159 frame.renderPassesById = &renderPassesById; | 160 frame.renderPassesById = &renderPassesById; |
| 160 frame.rootRenderPass = rootRenderPass; | 161 frame.rootRenderPass = rootRenderPass; |
| 161 frame.rootDamageRect = capabilities().usingPartialSwap ? rootRenderPass->dam
ageRect() : rootRenderPass->outputRect(); | 162 frame.rootDamageRect = capabilities().usingPartialSwap ? rootRenderPass->dam
ageRect() : rootRenderPass->outputRect(); |
| 162 frame.rootDamageRect.intersect(IntRect(IntPoint::zero(), viewportSize())); | 163 frame.rootDamageRect = frame.rootDamageRect.Intersect(gfx::Rect(gfx::Point()
, viewportSize())); |
| 163 | 164 |
| 164 beginDrawingFrame(frame); | 165 beginDrawingFrame(frame); |
| 165 for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i) | 166 for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i) |
| 166 drawRenderPass(frame, renderPassesInDrawOrder[i]); | 167 drawRenderPass(frame, renderPassesInDrawOrder[i]); |
| 167 finishDrawingFrame(frame); | 168 finishDrawingFrame(frame); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void CCDirectRenderer::drawRenderPass(DrawingFrame& frame, const CCRenderPass* r
enderPass) | 171 void CCDirectRenderer::drawRenderPass(DrawingFrame& frame, const CCRenderPass* r
enderPass) |
| 171 { | 172 { |
| 172 if (!useRenderPass(frame, renderPass)) | 173 if (!useRenderPass(frame, renderPass)) |
| 173 return; | 174 return; |
| 174 | 175 |
| 175 frame.scissorRectInRenderPassSpace = frame.currentRenderPass->outputRect(); | 176 frame.scissorRectInRenderPassSpace = frame.currentRenderPass->outputRect(); |
| 176 if (frame.rootDamageRect != frame.rootRenderPass->outputRect()) { | 177 if (frame.rootDamageRect != frame.rootRenderPass->outputRect()) { |
| 177 WebTransformationMatrix inverseTransformToRoot = frame.currentRenderPass
->transformToRootTarget().inverse(); | 178 WebTransformationMatrix inverseTransformToRoot = frame.currentRenderPass
->transformToRootTarget().inverse(); |
| 178 frame.scissorRectInRenderPassSpace.intersect(CCMathUtil::projectClippedR
ect(inverseTransformToRoot, frame.rootDamageRect)); | 179 gfx::RectF damageRectInRenderPassSpace = CCMathUtil::projectClippedRect(
inverseTransformToRoot, cc::FloatRect(frame.rootDamageRect)); |
| 180 frame.scissorRectInRenderPassSpace = frame.scissorRectInRenderPassSpace.
Intersect(damageRectInRenderPassSpace); |
| 179 } | 181 } |
| 180 | 182 |
| 181 enableScissorTestRect(moveScissorToWindowSpace(frame, frame.scissorRectInRen
derPassSpace)); | 183 enableScissorTestRect(moveScissorToWindowSpace(frame, frame.scissorRectInRen
derPassSpace)); |
| 182 clearFramebuffer(frame); | 184 clearFramebuffer(frame); |
| 183 | 185 |
| 184 const CCQuadList& quadList = renderPass->quadList(); | 186 const CCQuadList& quadList = renderPass->quadList(); |
| 185 for (CCQuadList::constBackToFrontIterator it = quadList.backToFrontBegin();
it != quadList.backToFrontEnd(); ++it) { | 187 for (CCQuadList::constBackToFrontIterator it = quadList.backToFrontBegin();
it != quadList.backToFrontEnd(); ++it) { |
| 186 FloatRect quadScissorRect = frame.scissorRectInRenderPassSpace; | 188 gfx::RectF quadScissorRect = frame.scissorRectInRenderPassSpace.Intersec
t((*it)->clippedRectInTarget()); |
| 187 quadScissorRect.intersect((*it)->clippedRectInTarget()); | 189 if (!quadScissorRect.IsEmpty()) { |
| 188 if (!quadScissorRect.isEmpty()) { | |
| 189 enableScissorTestRect(moveScissorToWindowSpace(frame, quadScissorRec
t)); | 190 enableScissorTestRect(moveScissorToWindowSpace(frame, quadScissorRec
t)); |
| 190 drawQuad(frame, *it); | 191 drawQuad(frame, *it); |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 CachedTexture* texture = m_renderPassTextures.get(renderPass->id()); | 195 CachedTexture* texture = m_renderPassTextures.get(renderPass->id()); |
| 195 if (texture) | 196 if (texture) |
| 196 texture->setIsComplete(!renderPass->hasOcclusionFromOutsideTargetSurface
()); | 197 texture->setIsComplete(!renderPass->hasOcclusionFromOutsideTargetSurface
()); |
| 197 } | 198 } |
| 198 | 199 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 218 | 219 |
| 219 bool CCDirectRenderer::haveCachedResourcesForRenderPassId(CCRenderPass::Id id) c
onst | 220 bool CCDirectRenderer::haveCachedResourcesForRenderPassId(CCRenderPass::Id id) c
onst |
| 220 { | 221 { |
| 221 CachedTexture* texture = m_renderPassTextures.get(id); | 222 CachedTexture* texture = m_renderPassTextures.get(id); |
| 222 return texture && texture->id() && texture->isComplete(); | 223 return texture && texture->id() && texture->isComplete(); |
| 223 } | 224 } |
| 224 | 225 |
| 225 // static | 226 // static |
| 226 IntSize CCDirectRenderer::renderPassTextureSize(const CCRenderPass* pass) | 227 IntSize CCDirectRenderer::renderPassTextureSize(const CCRenderPass* pass) |
| 227 { | 228 { |
| 228 return pass->outputRect().size(); | 229 return cc::IntSize(pass->outputRect().size()); |
| 229 } | 230 } |
| 230 | 231 |
| 231 // static | 232 // static |
| 232 GLenum CCDirectRenderer::renderPassTextureFormat(const CCRenderPass*) | 233 GLenum CCDirectRenderer::renderPassTextureFormat(const CCRenderPass*) |
| 233 { | 234 { |
| 234 return GL_RGBA; | 235 return GL_RGBA; |
| 235 } | 236 } |
| 236 | 237 |
| 237 } | 238 } |
| OLD | NEW |