Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: cc/draw_quad.cc

Issue 11344050: Fix DrawQuad copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/draw_quad.h ('k') | cc/draw_quad_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "cc/draw_quad.h" 7 #include "cc/draw_quad.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "cc/checkerboard_draw_quad.h" 10 #include "cc/checkerboard_draw_quad.h"
11 #include "cc/debug_border_draw_quad.h" 11 #include "cc/debug_border_draw_quad.h"
12 #include "cc/io_surface_draw_quad.h" 12 #include "cc/io_surface_draw_quad.h"
13 #include "cc/render_pass_draw_quad.h" 13 #include "cc/render_pass_draw_quad.h"
14 #include "cc/solid_color_draw_quad.h" 14 #include "cc/solid_color_draw_quad.h"
15 #include "cc/stream_video_draw_quad.h" 15 #include "cc/stream_video_draw_quad.h"
16 #include "cc/texture_draw_quad.h" 16 #include "cc/texture_draw_quad.h"
17 #include "cc/tile_draw_quad.h" 17 #include "cc/tile_draw_quad.h"
18 #include "cc/yuv_video_draw_quad.h" 18 #include "cc/yuv_video_draw_quad.h"
19 19
20 namespace {
21
22 template<typename T> T* TypedCopy(const cc::DrawQuad* other) {
23 return new T(*T::materialCast(other));
24 }
25
26 }
27
20 namespace cc { 28 namespace cc {
21 29
22 DrawQuad::DrawQuad(const SharedQuadState* sharedQuadState, Material material, co nst gfx::Rect& quadRect) 30 DrawQuad::DrawQuad(const SharedQuadState* sharedQuadState, Material material, co nst gfx::Rect& quadRect)
23 : m_sharedQuadState(sharedQuadState) 31 : m_sharedQuadState(sharedQuadState)
24 , m_sharedQuadStateId(sharedQuadState->id) 32 , m_sharedQuadStateId(sharedQuadState->id)
25 , m_material(material) 33 , m_material(material)
26 , m_quadRect(quadRect) 34 , m_quadRect(quadRect)
27 , m_quadVisibleRect(quadRect) 35 , m_quadVisibleRect(quadRect)
28 , m_quadOpaque(true) 36 , m_quadOpaque(true)
29 , m_needsBlending(false) 37 , m_needsBlending(false)
30 { 38 {
31 DCHECK(m_sharedQuadState); 39 DCHECK(m_sharedQuadState);
32 DCHECK(m_material != Invalid); 40 DCHECK(m_material != Invalid);
33 } 41 }
34 42
35 gfx::Rect DrawQuad::opaqueRect() const 43 gfx::Rect DrawQuad::opaqueRect() const
36 { 44 {
37 if (opacity() != 1) 45 if (opacity() != 1)
38 return gfx::Rect(); 46 return gfx::Rect();
39 if (m_sharedQuadState->opaque && m_quadOpaque) 47 if (m_sharedQuadState->opaque && m_quadOpaque)
40 return m_quadRect; 48 return m_quadRect;
41 return m_opaqueRect; 49 return m_opaqueRect;
42 } 50 }
43 51
44 void DrawQuad::setQuadVisibleRect(gfx::Rect quadVisibleRect) 52 void DrawQuad::setQuadVisibleRect(gfx::Rect quadVisibleRect)
45 { 53 {
46 m_quadVisibleRect = gfx::IntersectRects(quadVisibleRect, m_quadRect); 54 m_quadVisibleRect = gfx::IntersectRects(quadVisibleRect, m_quadRect);
47 } 55 }
48 56
49 unsigned DrawQuad::size() const
50 {
51 switch (material()) {
52 case Checkerboard:
53 return sizeof(CheckerboardDrawQuad);
54 case DebugBorder:
55 return sizeof(DebugBorderDrawQuad);
56 case IOSurfaceContent:
57 return sizeof(IOSurfaceDrawQuad);
58 case TextureContent:
59 return sizeof(TextureDrawQuad);
60 case SolidColor:
61 return sizeof(SolidColorDrawQuad);
62 case TiledContent:
63 return sizeof(TileDrawQuad);
64 case StreamVideoContent:
65 return sizeof(StreamVideoDrawQuad);
66 case RenderPass:
67 return sizeof(RenderPassDrawQuad);
68 case YUVVideoContent:
69 return sizeof(YUVVideoDrawQuad);
70 case Invalid:
71 break;
72 }
73
74 CRASH();
75 return sizeof(DrawQuad);
76 }
77
78 scoped_ptr<DrawQuad> DrawQuad::copy(const SharedQuadState* copiedSharedQuadState ) const 57 scoped_ptr<DrawQuad> DrawQuad::copy(const SharedQuadState* copiedSharedQuadState ) const
79 { 58 {
80 // RenderPass quads have their own copy() method. 59 scoped_ptr<DrawQuad> copyQuad;
81 DCHECK(material() != RenderPass); 60 switch (material()) {
82 61 case Checkerboard:
83 unsigned bytes = size(); 62 copyQuad.reset(TypedCopy<CheckerboardDrawQuad>(this));
84 DCHECK(bytes > 0); 63 break;
85 64 case DebugBorder:
86 scoped_ptr<DrawQuad> copyQuad(reinterpret_cast<DrawQuad*>(new char[bytes])); 65 copyQuad.reset(TypedCopy<DebugBorderDrawQuad>(this));
87 memcpy(copyQuad.get(), this, bytes); 66 break;
67 case IOSurfaceContent:
68 copyQuad.reset(TypedCopy<IOSurfaceDrawQuad>(this));
69 break;
70 case TextureContent:
71 copyQuad.reset(TypedCopy<TextureDrawQuad>(this));
72 break;
73 case SolidColor:
74 copyQuad.reset(TypedCopy<SolidColorDrawQuad>(this));
75 break;
76 case TiledContent:
77 copyQuad.reset(TypedCopy<TileDrawQuad>(this));
78 break;
79 case StreamVideoContent:
80 copyQuad.reset(TypedCopy<StreamVideoDrawQuad>(this));
81 break;
82 case YUVVideoContent:
83 copyQuad.reset(TypedCopy<YUVVideoDrawQuad>(this));
84 break;
85 case RenderPass: // RenderPass quads have their own copy() method.
86 case Invalid:
87 CRASH();
88 break;
89 }
88 copyQuad->setSharedQuadState(copiedSharedQuadState); 90 copyQuad->setSharedQuadState(copiedSharedQuadState);
89
90 return copyQuad.Pass(); 91 return copyQuad.Pass();
91 } 92 }
92 93
93 void DrawQuad::setSharedQuadState(const SharedQuadState* sharedQuadState) 94 void DrawQuad::setSharedQuadState(const SharedQuadState* sharedQuadState)
94 { 95 {
95 m_sharedQuadState = sharedQuadState; 96 m_sharedQuadState = sharedQuadState;
96 m_sharedQuadStateId = sharedQuadState->id; 97 m_sharedQuadStateId = sharedQuadState->id;
97 } 98 }
98 99
99 } 100 }
OLDNEW
« no previous file with comments | « cc/draw_quad.h ('k') | cc/draw_quad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698