summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-08 04:43:17 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-08 04:43:17 +0000
commit37adf94a3925cbac6d8305cadcd30f7848a360c7 (patch)
tree239c1e6fc4496fb6ca0117bb7c59ec6c0c570f2e /cc
parent090883b5b677cdf8b1d9040ca09eb99f3732bf70 (diff)
downloadchromium_src-37adf94a3925cbac6d8305cadcd30f7848a360c7.zip
chromium_src-37adf94a3925cbac6d8305cadcd30f7848a360c7.tar.gz
chromium_src-37adf94a3925cbac6d8305cadcd30f7848a360c7.tar.bz2
cc: Chromify the NinePatchLayer classes.
Style-only change. Make the NinePatchLayer and NinePatchLayerImpl classes adopt the chromium style. R=jamesr,enne NOTRY=true Review URL: https://chromiumcodereview.appspot.com/12639004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/nine_patch_layer.cc147
-rw-r--r--cc/nine_patch_layer.h69
-rw-r--r--cc/nine_patch_layer_impl.cc421
-rw-r--r--cc/nine_patch_layer_impl.h55
-rw-r--r--cc/nine_patch_layer_impl_unittest.cc12
-rw-r--r--cc/nine_patch_layer_unittest.cc4
-rw-r--r--cc/test/layer_tree_json_parser.cc4
7 files changed, 411 insertions, 301 deletions
diff --git a/cc/nine_patch_layer.cc b/cc/nine_patch_layer.cc
index 56ae43c..486bc01 100644
--- a/cc/nine_patch_layer.cc
+++ b/cc/nine_patch_layer.cc
@@ -12,98 +12,105 @@
namespace cc {
-scoped_refptr<NinePatchLayer> NinePatchLayer::create()
-{
- return make_scoped_refptr(new NinePatchLayer());
+scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
+ return make_scoped_refptr(new NinePatchLayer());
}
NinePatchLayer::NinePatchLayer()
- : m_bitmapDirty(false)
-{
-}
+ : bitmap_dirty_(false) {}
-NinePatchLayer::~NinePatchLayer()
-{
-}
+NinePatchLayer::~NinePatchLayer() {}
-scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl(LayerTreeImpl* treeImpl)
-{
- return NinePatchLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>();
+scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl(
+ LayerTreeImpl* tree_impl) {
+ return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-void NinePatchLayer::setTexturePriorities(const PriorityCalculator& priorityCalc)
-{
- if (m_resource && !m_resource->texture()->resourceManager()) {
- // Release the resource here, as it is no longer tied to a resource manager.
- m_resource.reset();
- if (!m_bitmap.isNull())
- createResource();
- } else if (m_needsDisplay && m_bitmapDirty && drawsContent()) {
- createResource();
- }
-
- if (m_resource) {
- m_resource->texture()->setRequestPriority(PriorityCalculator::uiPriority(true));
- // FIXME: Need to support swizzle in the shader for !PlatformColor::sameComponentOrder(textureFormat)
- GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
- m_resource->texture()->setDimensions(gfx::Size(m_bitmap.width(), m_bitmap.height()), textureFormat);
- }
+void NinePatchLayer::setTexturePriorities(
+ const PriorityCalculator& priority_calc) {
+ if (resource_ && !resource_->texture()->resourceManager()) {
+ // Release the resource here, as it is no longer tied to a resource manager.
+ resource_.reset();
+ if (!bitmap_.isNull())
+ CreateResource();
+ } else if (m_needsDisplay && bitmap_dirty_ && drawsContent()) {
+ CreateResource();
+ }
+
+ if (resource_) {
+ resource_->texture()->setRequestPriority(
+ PriorityCalculator::uiPriority(true));
+ // FIXME: Need to support swizzle in the shader for
+ // !PlatformColor::sameComponentOrder(texture_format)
+ GLenum texture_format =
+ layerTreeHost()->rendererCapabilities().bestTextureFormat;
+ resource_->texture()->setDimensions(
+ gfx::Size(bitmap_.width(), bitmap_.height()), texture_format);
+ }
}
-void NinePatchLayer::setBitmap(const SkBitmap& bitmap, const gfx::Rect& aperture) {
- m_bitmap = bitmap;
- m_imageAperture = aperture;
- m_bitmapDirty = true;
- setNeedsDisplay();
+void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) {
+ bitmap_ = bitmap;
+ image_aperture_ = aperture;
+ bitmap_dirty_ = true;
+ setNeedsDisplay();
}
-void NinePatchLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats* stats)
-{
- createUpdaterIfNeeded();
-
- if (m_resource && (m_bitmapDirty || m_resource->texture()->resourceId() == 0)) {
- gfx::Rect contentRect(gfx::Point(), gfx::Size(m_bitmap.width(), m_bitmap.height()));
- ResourceUpdate upload = ResourceUpdate::Create(m_resource->texture(), &m_bitmap, contentRect, contentRect, gfx::Vector2d());
- queue.appendFullUpload(upload);
- m_bitmapDirty = false;
- }
+void NinePatchLayer::update(ResourceUpdateQueue& queue,
+ const OcclusionTracker* occlusion,
+ RenderingStats* stats) {
+ CreateUpdaterIfNeeded();
+
+ if (resource_ && (bitmap_dirty_ || resource_->texture()->resourceId() == 0)) {
+ gfx::Rect contentRect(gfx::Point(),
+ gfx::Size(bitmap_.width(), bitmap_.height()));
+ ResourceUpdate upload = ResourceUpdate::Create(resource_->texture(),
+ &bitmap_,
+ contentRect,
+ contentRect,
+ gfx::Vector2d());
+ queue.appendFullUpload(upload);
+ bitmap_dirty_ = false;
+ }
}
-void NinePatchLayer::createUpdaterIfNeeded()
-{
- if (m_updater)
- return;
+void NinePatchLayer::CreateUpdaterIfNeeded() {
+ if (updater_)
+ return;
- m_updater = ImageLayerUpdater::create();
+ updater_ = ImageLayerUpdater::create();
}
-void NinePatchLayer::createResource()
-{
- DCHECK(!m_bitmap.isNull());
- createUpdaterIfNeeded();
- m_updater->setBitmap(m_bitmap);
- m_needsDisplay = false;
+void NinePatchLayer::CreateResource() {
+ DCHECK(!bitmap_.isNull());
+ CreateUpdaterIfNeeded();
+ updater_->setBitmap(bitmap_);
+ m_needsDisplay = false;
- if (!m_resource)
- m_resource = m_updater->createResource(layerTreeHost()->contentsTextureManager());
+ if (!resource_) {
+ resource_ = updater_->createResource(
+ layerTreeHost()->contentsTextureManager());
+ }
}
-bool NinePatchLayer::drawsContent() const
-{
- bool draws = !m_bitmap.isNull() && Layer::drawsContent() && m_bitmap.width() && m_bitmap.height();
- return draws;
+bool NinePatchLayer::drawsContent() const {
+ bool draws = !bitmap_.isNull() &&
+ Layer::drawsContent() &&
+ bitmap_.width() &&
+ bitmap_.height();
+ return draws;
}
-void NinePatchLayer::pushPropertiesTo(LayerImpl* layer)
-{
- Layer::pushPropertiesTo(layer);
- NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer);
+void NinePatchLayer::pushPropertiesTo(LayerImpl* layer) {
+ Layer::pushPropertiesTo(layer);
+ NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
- if (m_resource) {
- DCHECK(!m_bitmap.isNull());
- layerImpl->setResourceId(m_resource->texture()->resourceId());
- layerImpl->setLayout(gfx::Size(m_bitmap.width(), m_bitmap.height()), m_imageAperture);
- }
+ if (resource_) {
+ DCHECK(!bitmap_.isNull());
+ layer_impl->SetResourceId(resource_->texture()->resourceId());
+ layer_impl->SetLayout(
+ gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_);
+ }
}
}
diff --git a/cc/nine_patch_layer.h b/cc/nine_patch_layer.h
index 65b9082..1a7a97e 100644
--- a/cc/nine_patch_layer.h
+++ b/cc/nine_patch_layer.h
@@ -17,38 +17,43 @@ namespace cc {
class ResourceUpdateQueue;
class CC_EXPORT NinePatchLayer : public Layer {
-public:
- static scoped_refptr<NinePatchLayer> create();
-
- virtual bool drawsContent() const OVERRIDE;
- virtual void setTexturePriorities(const PriorityCalculator&) OVERRIDE;
- virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats*) OVERRIDE;
- virtual void pushPropertiesTo(LayerImpl*) OVERRIDE;
-
- // aperture is in the pixel space of the bitmap resource and refers to
- // the center patch of the ninepatch (which is unused in this
- // implementation). We split off eight rects surrounding it and stick them
- // on the edges of the layer. The corners are unscaled, the top and bottom
- // rects are x-stretched to fit, and the left and right rects are
- // y-stretched to fit.
- void setBitmap(const SkBitmap& bitmap, const gfx::Rect& aperture);
-
-private:
- NinePatchLayer();
- virtual ~NinePatchLayer();
- virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* treeImpl) OVERRIDE;
-
- void createUpdaterIfNeeded();
- void createResource();
-
- scoped_refptr<ImageLayerUpdater> m_updater;
- scoped_ptr<LayerUpdater::Resource> m_resource;
-
- SkBitmap m_bitmap;
- bool m_bitmapDirty;
-
- // The transparent center region that shows the parent layer's contents in image space.
- gfx::Rect m_imageAperture;
+ public:
+ static scoped_refptr<NinePatchLayer> Create();
+
+ virtual bool drawsContent() const OVERRIDE;
+ virtual void setTexturePriorities(const PriorityCalculator& priority_calc)
+ OVERRIDE;
+ virtual void update(ResourceUpdateQueue& queue,
+ const OcclusionTracker* occlusion,
+ RenderingStats* stats) OVERRIDE;
+ virtual void pushPropertiesTo(LayerImpl* layer) OVERRIDE;
+
+ // aperture is in the pixel space of the bitmap resource and refers to
+ // the center patch of the ninepatch (which is unused in this
+ // implementation). We split off eight rects surrounding it and stick them
+ // on the edges of the layer. The corners are unscaled, the top and bottom
+ // rects are x-stretched to fit, and the left and right rects are
+ // y-stretched to fit.
+ void SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture);
+
+ private:
+ NinePatchLayer();
+ virtual ~NinePatchLayer();
+ virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* tree_impl)
+ OVERRIDE;
+
+ void CreateUpdaterIfNeeded();
+ void CreateResource();
+
+ scoped_refptr<ImageLayerUpdater> updater_;
+ scoped_ptr<LayerUpdater::Resource> resource_;
+
+ SkBitmap bitmap_;
+ bool bitmap_dirty_;
+
+ // The transparent center region that shows the parent layer's contents in
+ // image space.
+ gfx::Rect image_aperture_;
};
} // namespace cc
diff --git a/cc/nine_patch_layer_impl.cc b/cc/nine_patch_layer_impl.cc
index 0fa0317..72cc20e 100644
--- a/cc/nine_patch_layer_impl.cc
+++ b/cc/nine_patch_layer_impl.cc
@@ -12,194 +12,289 @@
namespace cc {
-NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* treeImpl, int id)
- : LayerImpl(treeImpl, id)
- , m_resourceId(0)
-{
-}
+NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id)
+ : LayerImpl(tree_impl, id),
+ resource_id_(0) {}
-NinePatchLayerImpl::~NinePatchLayerImpl()
-{
-}
+NinePatchLayerImpl::~NinePatchLayerImpl() {}
-ResourceProvider::ResourceId NinePatchLayerImpl::contentsResourceId() const
-{
- return 0;
+ResourceProvider::ResourceId NinePatchLayerImpl::contentsResourceId() const {
+ return 0;
}
-scoped_ptr<LayerImpl> NinePatchLayerImpl::createLayerImpl(LayerTreeImpl* treeImpl)
-{
- return NinePatchLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>();
+scoped_ptr<LayerImpl> NinePatchLayerImpl::createLayerImpl(
+ LayerTreeImpl* tree_impl) {
+ return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-void NinePatchLayerImpl::pushPropertiesTo(LayerImpl* layer)
-{
- LayerImpl::pushPropertiesTo(layer);
- NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer);
-
- if (!m_resourceId)
- return;
+void NinePatchLayerImpl::pushPropertiesTo(LayerImpl* layer) {
+ LayerImpl::pushPropertiesTo(layer);
+ NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
- layerImpl->setResourceId(m_resourceId);
- layerImpl->setLayout(m_imageBounds, m_imageAperture);
-}
+ if (!resource_id_)
+ return;
-void NinePatchLayerImpl::willDraw(ResourceProvider* resourceProvider)
-{
+ layer_impl->SetResourceId(resource_id_);
+ layer_impl->SetLayout(image_bounds_, image_aperture_);
}
-static gfx::RectF normalizedRect(float x, float y, float width, float height, float totalWidth, float totalHeight)
-{
- return gfx::RectF(x / totalWidth, y / totalHeight, width / totalWidth, height / totalHeight);
+void NinePatchLayerImpl::willDraw(ResourceProvider* resource_provider) {}
+
+static gfx::RectF NormalizedRect(float x,
+ float y,
+ float width,
+ float height,
+ float total_width,
+ float total_height) {
+ return gfx::RectF(x / total_width,
+ y / total_height,
+ width / total_width,
+ height / total_height);
}
-void NinePatchLayerImpl::setLayout(const gfx::Size& imageBounds, const gfx::Rect& aperture)
-{
- m_imageBounds = imageBounds;
- m_imageAperture = aperture;
+void NinePatchLayerImpl::SetLayout(gfx::Size image_bounds, gfx::Rect aperture) {
+ image_bounds_ = image_bounds;
+ image_aperture_ = aperture;
}
-void NinePatchLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData)
-{
- if (!m_resourceId)
- return;
-
- SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState());
- appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
-
- static const bool flipped = false;
- static const bool premultipliedAlpha = true;
-
- DCHECK(!bounds().IsEmpty());
-
- // NinePatch border widths in bitmap pixel space
- int leftWidth = m_imageAperture.x();
- int topHeight = m_imageAperture.y();
- int rightWidth = m_imageBounds.width() - m_imageAperture.right();
- int bottomHeight = m_imageBounds.height() - m_imageAperture.bottom();
-
- // If layer can't fit the corners, clip to show the outer edges of the
- // image.
- int cornerTotalWidth = leftWidth + rightWidth;
- int middleWidth = bounds().width() - cornerTotalWidth;
- if (middleWidth < 0) {
- float leftWidthProportion = static_cast<float>(leftWidth) / cornerTotalWidth;
- int leftWidthCrop = middleWidth * leftWidthProportion;
- leftWidth += leftWidthCrop;
- rightWidth = bounds().width() - leftWidth;
- middleWidth = 0;
- }
- int cornerTotalHeight = topHeight + bottomHeight;
- int middleHeight = bounds().height() - cornerTotalHeight;
- if (middleHeight < 0) {
- float topHeightProportion = static_cast<float>(topHeight) / cornerTotalHeight;
- int topHeightCrop = middleHeight * topHeightProportion;
- topHeight += topHeightCrop;
- bottomHeight = bounds().height() - topHeight;
- middleHeight = 0;
- }
-
- // Patch positions in layer space
- gfx::Rect topLeft(0, 0, leftWidth, topHeight);
- gfx::Rect topRight(bounds().width() - rightWidth, 0, rightWidth, topHeight);
- gfx::Rect bottomLeft(0, bounds().height() - bottomHeight, leftWidth, bottomHeight);
- gfx::Rect bottomRight(topRight.x(), bottomLeft.y(), rightWidth, bottomHeight);
- gfx::Rect top(topLeft.right(), 0, middleWidth, topHeight);
- gfx::Rect left(0, topLeft.bottom(), leftWidth, middleHeight);
- gfx::Rect right(topRight.x(), topRight.bottom(), rightWidth, left.height());
- gfx::Rect bottom(top.x(), bottomLeft.y(), top.width(), bottomHeight);
-
- float imgWidth = m_imageBounds.width();
- float imgHeight = m_imageBounds.height();
-
- // Patch positions in bitmap UV space (from zero to one)
- gfx::RectF uvTopLeft = normalizedRect(0, 0, leftWidth, topHeight, imgWidth, imgHeight);
- gfx::RectF uvTopRight = normalizedRect(imgWidth - rightWidth, 0, rightWidth, topHeight, imgWidth, imgHeight);
- gfx::RectF uvBottomLeft = normalizedRect(0, imgHeight - bottomHeight, leftWidth, bottomHeight, imgWidth, imgHeight);
- gfx::RectF uvBottomRight = normalizedRect(imgWidth - rightWidth, imgHeight - bottomHeight, rightWidth, bottomHeight, imgWidth, imgHeight);
- gfx::RectF uvTop(uvTopLeft.right(), 0, (imgWidth - leftWidth - rightWidth) / imgWidth, (topHeight) / imgHeight);
- gfx::RectF uvLeft(0, uvTopLeft.bottom(), leftWidth / imgWidth, (imgHeight - topHeight - bottomHeight) / imgHeight);
- gfx::RectF uvRight(uvTopRight.x(), uvTopRight.bottom(), rightWidth / imgWidth, uvLeft.height());
- gfx::RectF uvBottom(uvTop.x(), uvBottomLeft.y(), uvTop.width(), bottomHeight / imgHeight);
-
- // Nothing is opaque here.
- // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness?
- gfx::Rect opaqueRect;
- const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
- scoped_ptr<TextureDrawQuad> quad;
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, topLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvTopLeft.origin(), uvTopLeft.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, topRight, opaqueRect, m_resourceId, premultipliedAlpha, uvTopRight.origin(), uvTopRight.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, bottomLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomLeft.origin(), uvBottomLeft.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, bottomRight, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomRight.origin(), uvBottomRight.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, top, opaqueRect, m_resourceId, premultipliedAlpha, uvTop.origin(), uvTop.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, left, opaqueRect, m_resourceId, premultipliedAlpha, uvLeft.origin(), uvLeft.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, right, opaqueRect, m_resourceId, premultipliedAlpha, uvRight.origin(), uvRight.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
-
- quad = TextureDrawQuad::Create();
- quad->SetNew(sharedQuadState, bottom, opaqueRect, m_resourceId, premultipliedAlpha, uvBottom.origin(), uvBottom.bottom_right(), vertex_opacity, flipped);
- quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
+void NinePatchLayerImpl::appendQuads(QuadSink& quad_sink,
+ AppendQuadsData& append_quads_data) {
+ if (!resource_id_)
+ return;
+
+ SharedQuadState* shared_quad_state =
+ quad_sink.useSharedQuadState(createSharedQuadState());
+ appendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
+
+ static const bool flipped = false;
+ static const bool premultiplied_alpha = true;
+
+ DCHECK(!bounds().IsEmpty());
+
+ // NinePatch border widths in bitmap pixel space
+ int left_width = image_aperture_.x();
+ int top_height = image_aperture_.y();
+ int right_width = image_bounds_.width() - image_aperture_.right();
+ int bottom_height = image_bounds_.height() - image_aperture_.bottom();
+
+ // If layer can't fit the corners, clip to show the outer edges of the
+ // image.
+ int corner_total_width = left_width + right_width;
+ int middle_width = bounds().width() - corner_total_width;
+ if (middle_width < 0) {
+ float left_width_proportion =
+ static_cast<float>(left_width) / corner_total_width;
+ int left_width_crop = middle_width * left_width_proportion;
+ left_width += left_width_crop;
+ right_width = bounds().width() - left_width;
+ middle_width = 0;
+ }
+ int corner_total_height = top_height + bottom_height;
+ int middle_height = bounds().height() - corner_total_height;
+ if (middle_height < 0) {
+ float top_height_proportion =
+ static_cast<float>(top_height) / corner_total_height;
+ int top_height_crop = middle_height * top_height_proportion;
+ top_height += top_height_crop;
+ bottom_height = bounds().height() - top_height;
+ middle_height = 0;
+ }
+
+ // Patch positions in layer space
+ gfx::Rect top_left(0, 0, left_width, top_height);
+ gfx::Rect topRight(
+ bounds().width() - right_width, 0, right_width, top_height);
+ gfx::Rect bottomLeft(
+ 0, bounds().height() - bottom_height, left_width, bottom_height);
+ gfx::Rect bottomRight(
+ topRight.x(), bottomLeft.y(), right_width, bottom_height);
+ gfx::Rect top(top_left.right(), 0, middle_width, top_height);
+ gfx::Rect left(0, top_left.bottom(), left_width, middle_height);
+ gfx::Rect right(topRight.x(), topRight.bottom(), right_width, left.height());
+ gfx::Rect bottom(top.x(), bottomLeft.y(), top.width(), bottom_height);
+
+ float img_width = image_bounds_.width();
+ float img_height = image_bounds_.height();
+
+ // Patch positions in bitmap UV space (from zero to one)
+ gfx::RectF uv_top_left = NormalizedRect(0,
+ 0,
+ left_width,
+ top_height,
+ img_width,
+ img_height);
+ gfx::RectF uv_top_right = NormalizedRect(img_width - right_width,
+ 0,
+ right_width,
+ top_height,
+ img_width,
+ img_height);
+ gfx::RectF uv_bottom_left = NormalizedRect(0,
+ img_height - bottom_height,
+ left_width,
+ bottom_height,
+ img_width,
+ img_height);
+ gfx::RectF uv_bottom_right = NormalizedRect(img_width - right_width,
+ img_height - bottom_height,
+ right_width,
+ bottom_height,
+ img_width,
+ img_height);
+ gfx::RectF uvTop(uv_top_left.right(),
+ 0,
+ (img_width - left_width - right_width) / img_width,
+ (top_height) / img_height);
+ gfx::RectF uvLeft(0,
+ uv_top_left.bottom(),
+ left_width / img_width,
+ (img_height - top_height - bottom_height) / img_height);
+ gfx::RectF uvRight(uv_top_right.x(),
+ uv_top_right.bottom(),
+ right_width / img_width,
+ uvLeft.height());
+ gfx::RectF uvBottom(uvTop.x(),
+ uv_bottom_left.y(),
+ uvTop.width(),
+ bottom_height / img_height);
+
+ // Nothing is opaque here.
+ // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness?
+ gfx::Rect opaque_rect;
+ const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
+ scoped_ptr<TextureDrawQuad> quad;
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ top_left,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uv_top_left.origin(),
+ uv_top_left.bottom_right(),
+ vertex_opacity, flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ topRight,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uv_top_right.origin(),
+ uv_top_right.bottom_right(),
+ vertex_opacity, flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ bottomLeft,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uv_bottom_left.origin(),
+ uv_bottom_left.bottom_right(),
+ vertex_opacity,
+ flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ bottomRight,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uv_bottom_right.origin(),
+ uv_bottom_right.bottom_right(),
+ vertex_opacity,
+ flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ top,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uvTop.origin(),
+ uvTop.bottom_right(),
+ vertex_opacity,
+ flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ left,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uvLeft.origin(),
+ uvLeft.bottom_right(),
+ vertex_opacity,
+ flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ right,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uvRight.origin(),
+ uvRight.bottom_right(),
+ vertex_opacity,
+ flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
+
+ quad = TextureDrawQuad::Create();
+ quad->SetNew(shared_quad_state,
+ bottom,
+ opaque_rect,
+ resource_id_,
+ premultiplied_alpha,
+ uvBottom.origin(),
+ uvBottom.bottom_right(),
+ vertex_opacity,
+ flipped);
+ quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data);
}
-void NinePatchLayerImpl::didDraw(ResourceProvider* resourceProvider)
-{
-}
+void NinePatchLayerImpl::didDraw(ResourceProvider* resource_provider) {}
-void NinePatchLayerImpl::didLoseOutputSurface()
-{
- m_resourceId = 0;
+void NinePatchLayerImpl::didLoseOutputSurface() {
+ resource_id_ = 0;
}
-const char* NinePatchLayerImpl::layerTypeAsString() const
-{
- return "NinePatchLayer";
+const char* NinePatchLayerImpl::layerTypeAsString() const {
+ return "NinePatchLayer";
}
-void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent) const
-{
- str->append(indentString(indent));
- base::StringAppendF(str, "imageAperture: %s\n", m_imageAperture.ToString().c_str());
- base::StringAppendF(str, "imageBounds: %s\n", m_imageBounds.ToString().c_str());
- LayerImpl::dumpLayerProperties(str, indent);
+void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent)
+ const {
+ str->append(indentString(indent));
+ base::StringAppendF(
+ str, "imageAperture: %s\n", image_aperture_.ToString().c_str());
+ base::StringAppendF(
+ str, "image_bounds: %s\n", image_bounds_.ToString().c_str());
+ LayerImpl::dumpLayerProperties(str, indent);
}
-base::DictionaryValue* NinePatchLayerImpl::layerTreeAsJson() const
-{
- base::DictionaryValue* result = LayerImpl::layerTreeAsJson();
+base::DictionaryValue* NinePatchLayerImpl::layerTreeAsJson() const {
+ base::DictionaryValue* result = LayerImpl::layerTreeAsJson();
- base::ListValue* list = new base::ListValue;
- list->AppendInteger(m_imageAperture.origin().x());
- list->AppendInteger(m_imageAperture.origin().y());
- list->AppendInteger(m_imageAperture.size().width());
- list->AppendInteger(m_imageAperture.size().height());
- result->Set("ImageAperture", list);
+ base::ListValue* list = new base::ListValue;
+ list->AppendInteger(image_aperture_.origin().x());
+ list->AppendInteger(image_aperture_.origin().y());
+ list->AppendInteger(image_aperture_.size().width());
+ list->AppendInteger(image_aperture_.size().height());
+ result->Set("ImageAperture", list);
- list = new base::ListValue;
- list->AppendInteger(m_imageBounds.width());
- list->AppendInteger(m_imageBounds.height());
- result->Set("ImageBounds", list);
+ list = new base::ListValue;
+ list->AppendInteger(image_bounds_.width());
+ list->AppendInteger(image_bounds_.height());
+ result->Set("ImageBounds", list);
- return result;
+ return result;
}
-}
+} // namespace cc
diff --git a/cc/nine_patch_layer_impl.h b/cc/nine_patch_layer_impl.h
index 8b693ac..d8f0978 100644
--- a/cc/nine_patch_layer_impl.h
+++ b/cc/nine_patch_layer_impl.h
@@ -18,41 +18,44 @@ class DictionaryValue;
namespace cc {
class CC_EXPORT NinePatchLayerImpl : public LayerImpl {
-public:
- static scoped_ptr<NinePatchLayerImpl> create(LayerTreeImpl* treeImpl, int id)
- {
- return make_scoped_ptr(new NinePatchLayerImpl(treeImpl, id));
- }
- virtual ~NinePatchLayerImpl();
+ public:
+ static scoped_ptr<NinePatchLayerImpl> Create(LayerTreeImpl* tree_impl,
+ int id) {
+ return make_scoped_ptr(new NinePatchLayerImpl(tree_impl, id));
+ }
+ virtual ~NinePatchLayerImpl();
- void setResourceId(unsigned id) { m_resourceId = id; }
- void setLayout(const gfx::Size& imageBounds, const gfx::Rect& aperture);
+ void SetResourceId(unsigned id) { resource_id_ = id; }
+ void SetLayout(gfx::Size image_bounds, gfx::Rect aperture);
- virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* treeImpl) OVERRIDE;
- virtual void pushPropertiesTo(LayerImpl*) OVERRIDE;
+ virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* tree_impl)
+ OVERRIDE;
+ virtual void pushPropertiesTo(LayerImpl* layer) OVERRIDE;
- virtual void willDraw(ResourceProvider*) OVERRIDE;
- virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE;
- virtual void didDraw(ResourceProvider*) OVERRIDE;
- virtual ResourceProvider::ResourceId contentsResourceId() const OVERRIDE;
- virtual void dumpLayerProperties(std::string*, int indent) const OVERRIDE;
- virtual void didLoseOutputSurface() OVERRIDE;
+ virtual void willDraw(ResourceProvider* resource_provider) OVERRIDE;
+ virtual void appendQuads(QuadSink& quad_sink,
+ AppendQuadsData& append_quads_data) OVERRIDE;
+ virtual void didDraw(ResourceProvider* FIXMENAME) OVERRIDE;
+ virtual ResourceProvider::ResourceId contentsResourceId() const OVERRIDE;
+ virtual void dumpLayerProperties(std::string* str, int indent) const OVERRIDE;
+ virtual void didLoseOutputSurface() OVERRIDE;
- virtual base::DictionaryValue* layerTreeAsJson() const OVERRIDE;
+ virtual base::DictionaryValue* layerTreeAsJson() const OVERRIDE;
-protected:
- NinePatchLayerImpl(LayerTreeImpl* treeImpl, int id);
+ protected:
+ NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id);
-private:
- virtual const char* layerTypeAsString() const OVERRIDE;
+ private:
+ virtual const char* layerTypeAsString() const OVERRIDE;
- // The size of the NinePatch bitmap in pixels.
- gfx::Size m_imageBounds;
+ // The size of the NinePatch bitmap in pixels.
+ gfx::Size image_bounds_;
- // The transparent center region that shows the parent layer's contents in image space.
- gfx::Rect m_imageAperture;
+ // The transparent center region that shows the parent layer's contents in
+ // image space.
+ gfx::Rect image_aperture_;
- ResourceProvider::ResourceId m_resourceId;
+ ResourceProvider::ResourceId resource_id_;
};
} // namespace cc
diff --git a/cc/nine_patch_layer_impl_unittest.cc b/cc/nine_patch_layer_impl_unittest.cc
index fbf765b..dba3cdf 100644
--- a/cc/nine_patch_layer_impl_unittest.cc
+++ b/cc/nine_patch_layer_impl_unittest.cc
@@ -41,14 +41,14 @@ TEST(NinePatchLayerImplTest, verifyDrawQuads)
FakeImplProxy proxy;
FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(hostImpl.activeTree(), 1);
+ scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::Create(hostImpl.activeTree(), 1);
layer->drawProperties().visible_content_rect = visibleContentRect;
layer->setBounds(layerSize);
layer->setContentBounds(layerSize);
layer->createRenderSurface();
layer->drawProperties().render_target = layer.get();
- layer->setLayout(bitmapSize, apertureRect);
- layer->setResourceId(1);
+ layer->SetLayout(bitmapSize, apertureRect);
+ layer->SetResourceId(1);
// This scale should not affect the generated quad geometry, but only
// the shared draw transform.
@@ -102,14 +102,14 @@ TEST(NinePatchLayerImplTest, verifyDrawQuadsForSqueezedLayer)
FakeImplProxy proxy;
FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(hostImpl.activeTree(), 1);
+ scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::Create(hostImpl.activeTree(), 1);
layer->drawProperties().visible_content_rect = visibleContentRect;
layer->setBounds(layerSize);
layer->setContentBounds(layerSize);
layer->createRenderSurface();
layer->drawProperties().render_target = layer.get();
- layer->setLayout(bitmapSize, apertureRect);
- layer->setResourceId(1);
+ layer->SetLayout(bitmapSize, apertureRect);
+ layer->SetResourceId(1);
AppendQuadsData data;
layer->appendQuads(quadCuller, data);
diff --git a/cc/nine_patch_layer_unittest.cc b/cc/nine_patch_layer_unittest.cc
index 8c04ea2..e63263f 100644
--- a/cc/nine_patch_layer_unittest.cc
+++ b/cc/nine_patch_layer_unittest.cc
@@ -65,7 +65,7 @@ protected:
TEST_F(NinePatchLayerTest, triggerFullUploadOnceWhenChangingBitmap)
{
- scoped_refptr<NinePatchLayer> testLayer = NinePatchLayer::create();
+ scoped_refptr<NinePatchLayer> testLayer = NinePatchLayer::Create();
ASSERT_TRUE(testLayer);
testLayer->setIsDrawable(true);
testLayer->setBounds(gfx::Size(100, 100));
@@ -90,7 +90,7 @@ TEST_F(NinePatchLayerTest, triggerFullUploadOnceWhenChangingBitmap)
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
bitmap.allocPixels();
- testLayer->setBitmap(bitmap, gfx::Rect(5, 5, 1, 1));
+ testLayer->SetBitmap(bitmap, gfx::Rect(5, 5, 1, 1));
testLayer->setTexturePriorities(calculator);
testLayer->update(queue, &occlusionTracker, NULL);
EXPECT_EQ(queue.fullUploadSize(), 1);
diff --git a/cc/test/layer_tree_json_parser.cc b/cc/test/layer_tree_json_parser.cc
index e4983b0..d4eec93 100644
--- a/cc/test/layer_tree_json_parser.cc
+++ b/cc/test/layer_tree_json_parser.cc
@@ -53,12 +53,12 @@ scoped_refptr<Layer> ParseTreeFromValue(base::Value* val,
success &= list->GetInteger(0, &image_width);
success &= list->GetInteger(1, &image_height);
- scoped_refptr<NinePatchLayer> nine_patch_layer = NinePatchLayer::create();
+ scoped_refptr<NinePatchLayer> nine_patch_layer = NinePatchLayer::Create();
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, image_width, image_height);
bitmap.allocPixels(NULL, NULL);
- nine_patch_layer->setBitmap(bitmap,
+ nine_patch_layer->SetBitmap(bitmap,
gfx::Rect(aperture_x, aperture_y, aperture_width, aperture_height));
new_layer = nine_patch_layer;