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