cc: Handle directly composited images in impl-side painting
Directly composited images are recorded into an SkPicture just like normal content. This also means that (at the moment) they will be treated like normal content, such as getting low-res versions. There will need to be some future follow-up to make sure that tiny images that end up large on page don't take up unnecessary GPU memory. The only bad part about this path is that changing a layer's bounds forces the content to need to be re-recorded and re-rasterized, as there's an assumption that the composited image fills its entire bounds. This could be fixed in the future by adding another layer (haha) of indirection. R=nduca@chromium.org BUG=163998 Review URL: https://chromiumcodereview.appspot.com/11516005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172241 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
cc
webkit/compositor_bindings
@ -126,6 +126,8 @@
|
||||
'page_scale_animation.h',
|
||||
'picture.cc',
|
||||
'picture.h',
|
||||
'picture_image_layer.cc',
|
||||
'picture_image_layer.h',
|
||||
'picture_layer.cc',
|
||||
'picture_layer.h',
|
||||
'picture_layer_impl.cc',
|
||||
|
@ -5,6 +5,8 @@
|
||||
#ifndef CC_CONTENT_LAYER_CLIENT_H_
|
||||
#define CC_CONTENT_LAYER_CLIENT_H_
|
||||
|
||||
#include "cc/cc_export.h"
|
||||
|
||||
class SkCanvas;
|
||||
|
||||
namespace gfx {
|
||||
@ -14,7 +16,7 @@ class RectF;
|
||||
|
||||
namespace cc {
|
||||
|
||||
class ContentLayerClient {
|
||||
class CC_EXPORT ContentLayerClient {
|
||||
public:
|
||||
virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opaque) = 0;
|
||||
|
||||
|
70
cc/picture_image_layer.cc
Normal file
70
cc/picture_image_layer.cc
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2010 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cc/picture_image_layer.h"
|
||||
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
scoped_refptr<PictureImageLayer> PictureImageLayer::create()
|
||||
{
|
||||
return make_scoped_refptr(new PictureImageLayer());
|
||||
}
|
||||
|
||||
PictureImageLayer::PictureImageLayer()
|
||||
: PictureLayer(this)
|
||||
{
|
||||
}
|
||||
|
||||
PictureImageLayer::~PictureImageLayer()
|
||||
{
|
||||
clearClient();
|
||||
}
|
||||
|
||||
void PictureImageLayer::setBitmap(const SkBitmap& bitmap)
|
||||
{
|
||||
// setBitmap() currently gets called whenever there is any
|
||||
// style change that affects the layer even if that change doesn't
|
||||
// affect the actual contents of the image (e.g. a CSS animation).
|
||||
// With this check in place we avoid unecessary texture uploads.
|
||||
if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
|
||||
return;
|
||||
|
||||
bitmap_ = bitmap;
|
||||
setNeedsDisplay();
|
||||
}
|
||||
|
||||
void PictureImageLayer::update(
|
||||
ResourceUpdateQueue& queue,
|
||||
const OcclusionTracker* tracker,
|
||||
RenderingStats& stats) {
|
||||
if (bounds() != bounds_) {
|
||||
// Pictures are recorded in layer space, so if the layer size changes,
|
||||
// then the picture needs to be re-scaled, as a directly composited image
|
||||
// always fills its entire layer bounds. This could be improved by
|
||||
// recording pictures of images at their actual resolution somehow.
|
||||
bounds_ = bounds();
|
||||
setNeedsDisplay();
|
||||
}
|
||||
PictureLayer::update(queue, tracker, stats);
|
||||
}
|
||||
|
||||
void PictureImageLayer::paintContents(
|
||||
SkCanvas* canvas,
|
||||
const gfx::Rect& clip,
|
||||
gfx::RectF& opaque) {
|
||||
if (!bitmap_.width() || !bitmap_.height())
|
||||
return;
|
||||
|
||||
SkScalar content_to_layer_scale_x = SkFloatToScalar(
|
||||
static_cast<float>(bounds().width()) / bitmap_.width());
|
||||
SkScalar content_to_layer_scale_y = SkFloatToScalar(
|
||||
static_cast<float>(bounds().height()) / bitmap_.height());
|
||||
canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
|
||||
|
||||
canvas->drawBitmap(bitmap_, 0, 0);
|
||||
}
|
||||
|
||||
} // namespace cc
|
44
cc/picture_image_layer.h
Normal file
44
cc/picture_image_layer.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2010 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CC_PICTURE_IMAGE_LAYER_H_
|
||||
#define CC_PICTURE_IMAGE_LAYER_H_
|
||||
|
||||
#include "cc/cc_export.h"
|
||||
#include "cc/content_layer_client.h"
|
||||
#include "cc/picture_layer.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/size.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_EXPORT PictureImageLayer : public PictureLayer, ContentLayerClient {
|
||||
public:
|
||||
static scoped_refptr<PictureImageLayer> create();
|
||||
|
||||
void setBitmap(const SkBitmap& image);
|
||||
|
||||
// Layer implementation.
|
||||
virtual void update(
|
||||
ResourceUpdateQueue& queue,
|
||||
const OcclusionTracker* tracker,
|
||||
RenderingStats& stats) OVERRIDE;
|
||||
|
||||
// ContentLayerClient implementation.
|
||||
virtual void paintContents(
|
||||
SkCanvas* canvas,
|
||||
const gfx::Rect& clip,
|
||||
gfx::RectF& opaque) OVERRIDE;
|
||||
|
||||
private:
|
||||
PictureImageLayer();
|
||||
virtual ~PictureImageLayer();
|
||||
|
||||
SkBitmap bitmap_;
|
||||
gfx::Size bounds_;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#endif // CC_PICTURE_IMAGE_LAYER_H_
|
@ -4,10 +4,16 @@
|
||||
|
||||
#include "web_image_layer_impl.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "cc/image_layer.h"
|
||||
#include "cc/picture_image_layer.h"
|
||||
#include "cc/switches.h"
|
||||
#include "web_layer_impl.h"
|
||||
|
||||
using cc::ImageLayer;
|
||||
static bool usingPictureLayer()
|
||||
{
|
||||
return CommandLine::ForCurrentProcess()->HasSwitch(cc::switches::kEnableImplSidePainting);
|
||||
}
|
||||
|
||||
namespace WebKit {
|
||||
|
||||
@ -17,8 +23,11 @@ WebImageLayer* WebImageLayer::create()
|
||||
}
|
||||
|
||||
WebImageLayerImpl::WebImageLayerImpl()
|
||||
: m_layer(new WebLayerImpl(ImageLayer::create()))
|
||||
{
|
||||
if (usingPictureLayer())
|
||||
m_layer.reset(new WebLayerImpl(cc::PictureImageLayer::create()));
|
||||
else
|
||||
m_layer.reset(new WebLayerImpl(cc::ImageLayer::create()));
|
||||
}
|
||||
|
||||
WebImageLayerImpl::~WebImageLayerImpl()
|
||||
@ -32,7 +41,10 @@ WebLayer* WebImageLayerImpl::layer()
|
||||
|
||||
void WebImageLayerImpl::setBitmap(SkBitmap bitmap)
|
||||
{
|
||||
static_cast<ImageLayer*>(m_layer->layer())->setBitmap(bitmap);
|
||||
if (usingPictureLayer())
|
||||
static_cast<cc::PictureImageLayer*>(m_layer->layer())->setBitmap(bitmap);
|
||||
else
|
||||
static_cast<cc::ImageLayer*>(m_layer->layer())->setBitmap(bitmap);
|
||||
}
|
||||
|
||||
} // namespace WebKit
|
||||
|
Reference in New Issue
Block a user