OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 126 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
127 if (rect.origin().x() || rect.origin().y()) { | 127 if (rect.origin().x() || rect.origin().y()) { |
128 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)"; | 128 VLOG(0) << "SetBounds not implemented for (x,y)!=(0,0)"; |
129 } | 129 } |
130 SetSize(rect.size()); | 130 SetSize(rect.size()); |
131 } | 131 } |
132 | 132 |
133 WebKit::WebGLId RenderWidgetHostViewAndroid::GetScaledContentTexture( | 133 WebKit::WebGLId RenderWidgetHostViewAndroid::GetScaledContentTexture( |
134 const gfx::Size& size) { | 134 const gfx::Size& size, |
| 135 const gfx::Rect& src_rect) { |
135 if (!CompositorImpl::IsInitialized() || | 136 if (!CompositorImpl::IsInitialized() || |
136 texture_id_in_layer_ == 0 || | 137 texture_id_in_layer_ == 0 || |
137 texture_size_in_layer_.IsEmpty()) | 138 texture_size_in_layer_.IsEmpty()) |
138 return 0; | 139 return 0; |
139 | 140 |
| 141 // Intersect the rects to make sure we aren't trying to grab area from |
| 142 // outside the texture area. |
| 143 gfx::Rect intersected_rect(gfx::IntersectRects( |
| 144 src_rect, |
| 145 gfx::Rect(texture_size_in_layer_))); |
| 146 |
140 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 147 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
141 return helper->CopyAndScaleTexture(texture_id_in_layer_, | 148 return helper->CopyAndScaleTexture(texture_id_in_layer_, |
142 texture_size_in_layer_, | 149 texture_size_in_layer_, |
| 150 intersected_rect, |
143 size, | 151 size, |
144 true); | 152 true); |
145 } | 153 } |
146 | 154 |
147 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { | 155 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { |
148 if (!CompositorImpl::IsInitialized() || | 156 if (!CompositorImpl::IsInitialized() || |
149 texture_id_in_layer_ == 0 || | 157 texture_id_in_layer_ == 0 || |
150 texture_size_in_layer_.IsEmpty()) | 158 texture_size_in_layer_.IsEmpty()) |
151 return false; | 159 return false; |
152 | 160 |
153 gfx::JavaBitmap bitmap(jbitmap); | 161 gfx::JavaBitmap bitmap(jbitmap); |
154 | 162 |
155 // TODO(dtrainor): Eventually add support for multiple formats here. | 163 // TODO(dtrainor): Eventually add support for multiple formats here. |
156 DCHECK(bitmap.format() == ANDROID_BITMAP_FORMAT_RGBA_8888); | 164 DCHECK(bitmap.format() == ANDROID_BITMAP_FORMAT_RGBA_8888); |
157 | 165 |
158 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 166 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
159 | 167 |
160 WebKit::WebGLId texture = helper->CopyAndScaleTexture(texture_id_in_layer_, | 168 WebKit::WebGLId texture = helper->CopyAndScaleTexture( |
161 texture_size_in_layer_, | 169 texture_id_in_layer_, |
162 bitmap.size(), | 170 texture_size_in_layer_, |
163 true); | 171 gfx::Rect(texture_size_in_layer_), |
| 172 bitmap.size(), |
| 173 true); |
164 if (texture == 0) | 174 if (texture == 0) |
165 return false; | 175 return false; |
166 | 176 |
167 helper->ReadbackTextureSync(texture, | 177 helper->ReadbackTextureSync(texture, |
168 bitmap.size(), | 178 bitmap.size(), |
169 static_cast<unsigned char*> (bitmap.pixels())); | 179 static_cast<unsigned char*> (bitmap.pixels())); |
170 | 180 |
171 WebKit::WebGraphicsContext3D* context = | 181 WebKit::WebGraphicsContext3D* context = |
172 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 182 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
173 context->deleteTexture(texture); | 183 context->deleteTexture(texture); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // RenderWidgetHostView, public: | 640 // RenderWidgetHostView, public: |
631 | 641 |
632 // static | 642 // static |
633 RenderWidgetHostView* | 643 RenderWidgetHostView* |
634 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 644 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
635 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 645 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
636 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 646 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
637 } | 647 } |
638 | 648 |
639 } // namespace content | 649 } // namespace content |
OLD | NEW |