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 "cc/direct_renderer.h" | 5 #include "cc/direct_renderer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/math_util.h" | 10 #include "cc/math_util.h" |
11 #include "ui/gfx/rect_conversions.h" | 11 #include "ui/gfx/rect_conversions.h" |
12 #include <public/WebTransformationMatrix.h> | 12 #include "ui/gfx/transform.h" |
13 | 13 |
14 using WebKit::WebTransformationMatrix; | 14 using gfx::Transform; |
15 | 15 |
16 static WebTransformationMatrix orthoProjectionMatrix(float left, float right, fl
oat bottom, float top) | 16 static Transform orthoProjectionMatrix(float left, float right, float bottom, fl
oat top) |
17 { | 17 { |
18 // 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 |
19 // [-1, -1, -1] to [1, 1, 1]. | 19 // [-1, -1, -1] to [1, 1, 1]. |
20 float deltaX = right - left; | 20 float deltaX = right - left; |
21 float deltaY = top - bottom; | 21 float deltaY = top - bottom; |
22 WebTransformationMatrix proj; | 22 Transform proj; |
23 if (!deltaX || !deltaY) | 23 if (!deltaX || !deltaY) |
24 return proj; | 24 return proj; |
25 proj.setM11(2.0f / deltaX); | 25 proj.matrix().setDouble(0, 0, 2.0f / deltaX); |
26 proj.setM41(-(right + left) / deltaX); | 26 proj.matrix().setDouble(0, 3, -(right + left) / deltaX); |
27 proj.setM22(2.0f / deltaY); | 27 proj.matrix().setDouble(1, 1, 2.0f / deltaY); |
28 proj.setM42(-(top + bottom) / deltaY); | 28 proj.matrix().setDouble(1, 3, -(top + bottom) / deltaY); |
29 | 29 |
30 // Z component of vertices is always set to zero as we don't use the depth b
uffer | 30 // Z component of vertices is always set to zero as we don't use the depth b
uffer |
31 // while drawing. | 31 // while drawing. |
32 proj.setM33(0); | 32 proj.matrix().setDouble(2, 2, 0); |
33 | 33 |
34 return proj; | 34 return proj; |
35 } | 35 } |
36 | 36 |
37 static WebTransformationMatrix windowMatrix(int x, int y, int width, int height) | 37 static Transform windowMatrix(int x, int y, int width, int height) |
38 { | 38 { |
39 WebTransformationMatrix canvas; | 39 Transform canvas; |
40 | 40 |
41 // Map to window position and scale up to pixel coordinates. | 41 // Map to window position and scale up to pixel coordinates. |
42 canvas.translate3d(x, y, 0); | 42 canvas.PreconcatTranslate3d(x, y, 0); |
43 canvas.scale3d(width, height, 0); | 43 canvas.PreconcatScale3d(width, height, 0); |
44 | 44 |
45 // Map from ([-1, -1] to [1, 1]) -> ([0, 0] to [1, 1]) | 45 // Map from ([-1, -1] to [1, 1]) -> ([0, 0] to [1, 1]) |
46 canvas.translate3d(0.5, 0.5, 0.5); | 46 canvas.PreconcatTranslate3d(0.5, 0.5, 0.5); |
47 canvas.scale3d(0.5, 0.5, 0.5); | 47 canvas.PreconcatScale3d(0.5, 0.5, 0.5); |
48 | 48 |
49 return canvas; | 49 return canvas; |
50 } | 50 } |
51 | 51 |
52 namespace cc { | 52 namespace cc { |
53 | 53 |
54 DirectRenderer::DrawingFrame::DrawingFrame() | 54 DirectRenderer::DrawingFrame::DrawingFrame() |
55 : rootRenderPass(0) | 55 : rootRenderPass(0) |
56 , currentRenderPass(0) | 56 , currentRenderPass(0) |
57 , currentTexture(0) | 57 , currentTexture(0) |
58 , flippedY(false) | 58 , flippedY(false) |
59 { | 59 { |
60 } | 60 } |
61 | 61 |
62 DirectRenderer::DrawingFrame::~DrawingFrame() | 62 DirectRenderer::DrawingFrame::~DrawingFrame() |
63 { | 63 { |
64 } | 64 } |
65 | 65 |
66 // | 66 // |
67 // static | 67 // static |
68 gfx::RectF DirectRenderer::quadVertexRect() | 68 gfx::RectF DirectRenderer::quadVertexRect() |
69 { | 69 { |
70 return gfx::RectF(-0.5, -0.5, 1, 1); | 70 return gfx::RectF(-0.5, -0.5, 1, 1); |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 void DirectRenderer::quadRectTransform(WebKit::WebTransformationMatrix* quadRect
Transform, const WebKit::WebTransformationMatrix& quadTransform, const gfx::Rect
F& quadRect) | 74 void DirectRenderer::quadRectTransform(gfx::Transform* quadRectTransform, const
gfx::Transform& quadTransform, const gfx::RectF& quadRect) |
75 { | 75 { |
76 *quadRectTransform = quadTransform; | 76 *quadRectTransform = quadTransform; |
77 quadRectTransform->translate(0.5 * quadRect.width() + quadRect.x(), 0.5 * qu
adRect.height() + quadRect.y()); | 77 quadRectTransform->PreconcatTranslate(0.5 * quadRect.width() + quadRect.x(),
0.5 * quadRect.height() + quadRect.y()); |
78 quadRectTransform->scaleNonUniform(quadRect.width(), quadRect.height()); | 78 quadRectTransform->PreconcatScale(quadRect.width(), quadRect.height()); |
79 } | 79 } |
80 | 80 |
81 // static | 81 // static |
82 void DirectRenderer::initializeMatrices(DrawingFrame& frame, const gfx::Rect& dr
awRect, bool flipY) | 82 void DirectRenderer::initializeMatrices(DrawingFrame& frame, const gfx::Rect& dr
awRect, bool flipY) |
83 { | 83 { |
84 if (flipY) | 84 if (flipY) |
85 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ri
ght(), drawRect.bottom(), drawRect.y()); | 85 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ri
ght(), drawRect.bottom(), drawRect.y()); |
86 else | 86 else |
87 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ri
ght(), drawRect.y(), drawRect.bottom()); | 87 frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.ri
ght(), drawRect.y(), drawRect.bottom()); |
88 frame.windowMatrix = windowMatrix(0, 0, drawRect.width(), drawRect.height())
; | 88 frame.windowMatrix = windowMatrix(0, 0, drawRect.width(), drawRect.height())
; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 finishDrawingFrame(frame); | 169 finishDrawingFrame(frame); |
170 } | 170 } |
171 | 171 |
172 gfx::RectF DirectRenderer::computeScissorRectForRenderPass(const DrawingFrame& f
rame) | 172 gfx::RectF DirectRenderer::computeScissorRectForRenderPass(const DrawingFrame& f
rame) |
173 { | 173 { |
174 gfx::RectF renderPassScissor = frame.currentRenderPass->output_rect; | 174 gfx::RectF renderPassScissor = frame.currentRenderPass->output_rect; |
175 | 175 |
176 if (frame.rootDamageRect == frame.rootRenderPass->output_rect) | 176 if (frame.rootDamageRect == frame.rootRenderPass->output_rect) |
177 return renderPassScissor; | 177 return renderPassScissor; |
178 | 178 |
179 WebTransformationMatrix inverseTransform = frame.currentRenderPass->transfor
m_to_root_target.inverse(); | 179 Transform inverseTransform = MathUtil::inverse(frame.currentRenderPass->tran
sform_to_root_target); |
180 gfx::RectF damageRectInRenderPassSpace = MathUtil::projectClippedRect(invers
eTransform, frame.rootDamageRect); | 180 gfx::RectF damageRectInRenderPassSpace = MathUtil::projectClippedRect(invers
eTransform, frame.rootDamageRect); |
181 renderPassScissor.Intersect(damageRectInRenderPassSpace); | 181 renderPassScissor.Intersect(damageRectInRenderPassSpace); |
182 | 182 |
183 return renderPassScissor; | 183 return renderPassScissor; |
184 } | 184 } |
185 | 185 |
186 void DirectRenderer::setScissorStateForQuad(const DrawingFrame& frame, const Dra
wQuad& quad) | 186 void DirectRenderer::setScissorStateForQuad(const DrawingFrame& frame, const Dra
wQuad& quad) |
187 { | 187 { |
188 if (quad.isClipped()) { | 188 if (quad.isClipped()) { |
189 gfx::RectF quadScissorRect = quad.clipRect(); | 189 gfx::RectF quadScissorRect = quad.clipRect(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 return pass->output_rect.size(); | 276 return pass->output_rect.size(); |
277 } | 277 } |
278 | 278 |
279 // static | 279 // static |
280 GLenum DirectRenderer::renderPassTextureFormat(const RenderPass*) | 280 GLenum DirectRenderer::renderPassTextureFormat(const RenderPass*) |
281 { | 281 { |
282 return GL_RGBA; | 282 return GL_RGBA; |
283 } | 283 } |
284 | 284 |
285 } // namespace cc | 285 } // namespace cc |
OLD | NEW |