Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1563770. Always include a visible rect with blob images. r=nical
Browse files Browse the repository at this point in the history
I suspect we may change things more in the future as we blob's size
just be the visible rect but this is an incremental step in the right
direction.

It also includes some changes to make sure that we always update our
tiles appropriately.

Differential Revision: https://phabricator.services.mozilla.com/D37079
  • Loading branch information
jrmuizel committed Jul 11, 2019
1 parent 06c654a commit 22e87aa
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 62 deletions.
6 changes: 4 additions & 2 deletions gfx/layers/ipc/WebRenderMessages.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct OpAddImage {
struct OpAddBlobImage {
ImageDescriptor descriptor;
OffsetRange bytes;
ImageIntRect visibleRect;
uint16_t tiling;
BlobImageKey key;
};
Expand All @@ -121,10 +122,11 @@ struct OpUpdateBlobImage {
ImageDescriptor descriptor;
OffsetRange bytes;
BlobImageKey key;
ImageIntRect visibleRect;
ImageIntRect dirtyRect;
};

struct OpSetImageVisibleArea {
struct OpSetBlobImageVisibleArea {
ImageIntRect area;
BlobImageKey key;
};
Expand Down Expand Up @@ -177,7 +179,7 @@ union OpUpdateResource {
OpAddBlobImage;
OpUpdateImage;
OpUpdateBlobImage;
OpSetImageVisibleArea;
OpSetBlobImageVisibleArea;
OpDeleteImage;
OpDeleteBlobImage;
OpAddRawFont;
Expand Down
13 changes: 8 additions & 5 deletions gfx/layers/wr/IpcResourceUpdateQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,15 @@ bool IpcResourceUpdateQueue::AddImage(ImageKey key,

bool IpcResourceUpdateQueue::AddBlobImage(BlobImageKey key,
const ImageDescriptor& aDescriptor,
Range<uint8_t> aBytes) {
Range<uint8_t> aBytes,
ImageIntRect aVisibleRect) {
MOZ_RELEASE_ASSERT(aDescriptor.width > 0 && aDescriptor.height > 0);
auto bytes = mWriter.Write(aBytes);
if (!bytes.length()) {
return false;
}
mUpdates.AppendElement(layers::OpAddBlobImage(aDescriptor, bytes, 0, key));
mUpdates.AppendElement(
layers::OpAddBlobImage(aDescriptor, bytes, aVisibleRect, 0, key));
return true;
}

Expand Down Expand Up @@ -336,13 +338,14 @@ bool IpcResourceUpdateQueue::UpdateImageBuffer(
bool IpcResourceUpdateQueue::UpdateBlobImage(BlobImageKey aKey,
const ImageDescriptor& aDescriptor,
Range<uint8_t> aBytes,
ImageIntRect aVisibleRect,
ImageIntRect aDirtyRect) {
auto bytes = mWriter.Write(aBytes);
if (!bytes.length()) {
return false;
}
mUpdates.AppendElement(
layers::OpUpdateBlobImage(aDescriptor, bytes, aKey, aDirtyRect));
mUpdates.AppendElement(layers::OpUpdateBlobImage(aDescriptor, bytes, aKey,
aVisibleRect, aDirtyRect));
return true;
}

Expand All @@ -355,7 +358,7 @@ void IpcResourceUpdateQueue::UpdateExternalImage(wr::ExternalImageId aExtId,

void IpcResourceUpdateQueue::SetBlobImageVisibleArea(
wr::BlobImageKey aKey, const ImageIntRect& aArea) {
mUpdates.AppendElement(layers::OpSetImageVisibleArea(aArea, aKey));
mUpdates.AppendElement(layers::OpSetBlobImageVisibleArea(aArea, aKey));
}

void IpcResourceUpdateQueue::DeleteImage(ImageKey aKey) {
Expand Down
5 changes: 3 additions & 2 deletions gfx/layers/wr/IpcResourceUpdateQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class IpcResourceUpdateQueue {
Range<uint8_t> aBytes);

bool AddBlobImage(wr::BlobImageKey aKey, const ImageDescriptor& aDescriptor,
Range<uint8_t> aBytes);
Range<uint8_t> aBytes, ImageIntRect aVisibleRect);

void AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey);

Expand All @@ -151,7 +151,8 @@ class IpcResourceUpdateQueue {

bool UpdateBlobImage(wr::BlobImageKey aKey,
const ImageDescriptor& aDescriptor,
Range<uint8_t> aBytes, ImageIntRect aDirtyRect);
Range<uint8_t> aBytes, ImageIntRect aVisibleRect,
ImageIntRect aDirtyRect);

void UpdateExternalImage(ExternalImageId aExtID, ImageKey aKey,
ImageIntRect aDirtyRect);
Expand Down
16 changes: 7 additions & 9 deletions gfx/layers/wr/WebRenderBridgeParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ bool WebRenderBridgeParent::UpdateResources(
if (!reader.Read(op.bytes(), bytes)) {
return false;
}
aUpdates.AddBlobImage(op.key(), op.descriptor(), bytes);
aUpdates.AddBlobImage(op.key(), op.descriptor(), bytes,
wr::ToDeviceIntRect(op.visibleRect()));
break;
}
case OpUpdateResource::TOpUpdateBlobImage: {
Expand All @@ -438,17 +439,14 @@ bool WebRenderBridgeParent::UpdateResources(
return false;
}
aUpdates.UpdateBlobImage(op.key(), op.descriptor(), bytes,
wr::ToDeviceIntRect(op.visibleRect()),
wr::ToLayoutIntRect(op.dirtyRect()));
break;
}
case OpUpdateResource::TOpSetImageVisibleArea: {
const auto& op = cmd.get_OpSetImageVisibleArea();
wr::DeviceIntRect area;
area.origin.x = op.area().x;
area.origin.y = op.area().y;
area.size.width = op.area().width;
area.size.height = op.area().height;
aUpdates.SetImageVisibleArea(op.key(), area);
case OpUpdateResource::TOpSetBlobImageVisibleArea: {
const auto& op = cmd.get_OpSetBlobImageVisibleArea();
aUpdates.SetBlobImageVisibleArea(op.key(),
wr::ToDeviceIntRect(op.area()));
break;
}
case OpUpdateResource::TOpAddExternalImage: {
Expand Down
30 changes: 19 additions & 11 deletions gfx/layers/wr/WebRenderCommandBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ struct DIGroup {
GP("No previous key making new one %d\n", key._0.mHandle);
wr::ImageDescriptor descriptor(dtSize, 0, dt->GetFormat(), opacity);
MOZ_RELEASE_ASSERT(bytes.length() > sizeof(size_t));
if (!aResources.AddBlobImage(key, descriptor, bytes)) {
if (!aResources.AddBlobImage(
key, descriptor, bytes,
ViewAs<ImagePixel>(mPaintRect,
PixelCastJustification::LayerIsImage))) {
return;
}
mKey = Some(MakePair(aBuilder.GetRenderRoot(), key));
Expand All @@ -734,8 +737,11 @@ struct DIGroup {
bottomRight.y <= dtSize.height);
GP("Update Blob %d %d %d %d\n", mInvalidRect.x, mInvalidRect.y,
mInvalidRect.width, mInvalidRect.height);
if (!aResources.UpdateBlobImage(mKey.value().second(), descriptor, bytes,
ViewAs<ImagePixel>(mInvalidRect))) {
if (!aResources.UpdateBlobImage(
mKey.value().second(), descriptor, bytes,
ViewAs<ImagePixel>(mPaintRect,
PixelCastJustification::LayerIsImage),
ViewAs<ImagePixel>(mInvalidRect))) {
return;
}
}
Expand Down Expand Up @@ -2306,7 +2312,10 @@ WebRenderCommandBuilder::GenerateFallbackData(
wr::BlobImageKey{mManager->WrBridge()->GetNextImageKey()};
wr::ImageDescriptor descriptor(dtSize.ToUnknownSize(), 0,
dt->GetFormat(), opacity);
if (!aResources.AddBlobImage(key, descriptor, bytes)) {
if (!aResources.AddBlobImage(
key, descriptor, bytes,
ViewAs<ImagePixel>(visibleRect,
PixelCastJustification::LayerIsImage))) {
return nullptr;
}
TakeExternalSurfaces(
Expand All @@ -2321,11 +2330,11 @@ WebRenderCommandBuilder::GenerateFallbackData(
if (!fallbackData->GetBlobImageKey().isSome()) {
return nullptr;
}
aResources.SetBlobImageVisibleArea(
fallbackData->GetBlobImageKey().value(),
ViewAs<ImagePixel>(visibleRect,
PixelCastJustification::LayerIsImage));
}
aResources.SetBlobImageVisibleArea(
fallbackData->GetBlobImageKey().value(),
ViewAs<ImagePixel>(visibleRect,
PixelCastJustification::LayerIsImage));
} else {
WebRenderImageData* imageData = fallbackData->PaintIntoImage();

Expand Down Expand Up @@ -2526,9 +2535,8 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
wr::BlobImageKey{mManager->WrBridge()->GetNextImageKey()};
wr::ImageDescriptor descriptor(size, 0, dt->GetFormat(),
wr::OpacityType::HasAlphaChannel);
if (!aResources.AddBlobImage(key, descriptor,
bytes)) { // visible area: ImageIntRect(0, 0,
// size.width, size.height)
if (!aResources.AddBlobImage(key, descriptor, bytes,
ImageIntRect(0, 0, size.width, size.height))) {
return Nothing();
}
maskData->ClearImageKey();
Expand Down
6 changes: 4 additions & 2 deletions gfx/webrender_bindings/Moz2DImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ static RefPtr<ScaledFont> GetScaledFont(Translator* aTranslator,

static bool Moz2DRenderCallback(const Range<const uint8_t> aBlob,
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
const mozilla::wr::DeviceIntRect* aVisibleRect,
const uint16_t* aTileSize,
const mozilla::wr::TileOffset* aTileOffset,
const mozilla::wr::LayoutIntRect* aDirtyRect,
Expand Down Expand Up @@ -473,14 +474,15 @@ extern "C" {

bool wr_moz2d_render_cb(const mozilla::wr::ByteSlice blob, int32_t width,
int32_t height, mozilla::wr::ImageFormat aFormat,
const mozilla::wr::DeviceIntRect* aVisibleRect,
const uint16_t* aTileSize,
const mozilla::wr::TileOffset* aTileOffset,
const mozilla::wr::LayoutIntRect* aDirtyRect,
mozilla::wr::MutByteSlice output) {
return mozilla::wr::Moz2DRenderCallback(
mozilla::wr::ByteSliceToRange(blob), mozilla::gfx::IntSize(width, height),
mozilla::wr::ImageFormatToSurfaceFormat(aFormat), aTileSize, aTileOffset,
aDirtyRect, mozilla::wr::MutByteSliceToRange(output));
mozilla::wr::ImageFormatToSurfaceFormat(aFormat), aVisibleRect, aTileSize,
aTileOffset, aDirtyRect, mozilla::wr::MutByteSliceToRange(output));
}

} // extern
13 changes: 8 additions & 5 deletions gfx/webrender_bindings/WebRenderAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,10 @@ void TransactionBuilder::AddImage(ImageKey key,

void TransactionBuilder::AddBlobImage(BlobImageKey key,
const ImageDescriptor& aDescriptor,
wr::Vec<uint8_t>& aBytes) {
wr_resource_updates_add_blob_image(mTxn, key, &aDescriptor, &aBytes.inner);
wr::Vec<uint8_t>& aBytes,
const wr::DeviceIntRect& aVisibleRect) {
wr_resource_updates_add_blob_image(mTxn, key, &aDescriptor, &aBytes.inner,
aVisibleRect);
}

void TransactionBuilder::AddExternalImage(ImageKey key,
Expand Down Expand Up @@ -652,9 +654,10 @@ void TransactionBuilder::UpdateImageBuffer(ImageKey aKey,
void TransactionBuilder::UpdateBlobImage(BlobImageKey aKey,
const ImageDescriptor& aDescriptor,
wr::Vec<uint8_t>& aBytes,
const wr::DeviceIntRect& aVisibleRect,
const wr::LayoutIntRect& aDirtyRect) {
wr_resource_updates_update_blob_image(mTxn, aKey, &aDescriptor, &aBytes.inner,
aDirtyRect);
aVisibleRect, aDirtyRect);
}

void TransactionBuilder::UpdateExternalImage(ImageKey aKey,
Expand All @@ -674,8 +677,8 @@ void TransactionBuilder::UpdateExternalImageWithDirtyRect(
mTxn, aKey, &aDescriptor, aExtID, &aImageType, aChannelIndex, aDirtyRect);
}

void TransactionBuilder::SetImageVisibleArea(BlobImageKey aKey,
const wr::DeviceIntRect& aArea) {
void TransactionBuilder::SetBlobImageVisibleArea(
BlobImageKey aKey, const wr::DeviceIntRect& aArea) {
wr_resource_updates_set_blob_image_visible_area(mTxn, aKey, &aArea);
}

Expand Down
7 changes: 5 additions & 2 deletions gfx/webrender_bindings/WebRenderAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class TransactionBuilder final {
wr::Vec<uint8_t>& aBytes);

void AddBlobImage(wr::BlobImageKey aKey, const ImageDescriptor& aDescriptor,
wr::Vec<uint8_t>& aBytes);
wr::Vec<uint8_t>& aBytes,
const wr::DeviceIntRect& aVisibleRect);

void AddExternalImageBuffer(ImageKey key, const ImageDescriptor& aDescriptor,
ExternalImageId aHandle);
Expand All @@ -141,6 +142,7 @@ class TransactionBuilder final {
void UpdateBlobImage(wr::BlobImageKey aKey,
const ImageDescriptor& aDescriptor,
wr::Vec<uint8_t>& aBytes,
const wr::DeviceIntRect& aVisibleRect,
const wr::LayoutIntRect& aDirtyRect);

void UpdateExternalImage(ImageKey aKey, const ImageDescriptor& aDescriptor,
Expand All @@ -155,7 +157,8 @@ class TransactionBuilder final {
const wr::DeviceIntRect& aDirtyRect,
uint8_t aChannelIndex = 0);

void SetImageVisibleArea(BlobImageKey aKey, const wr::DeviceIntRect& aArea);
void SetBlobImageVisibleArea(BlobImageKey aKey,
const wr::DeviceIntRect& aArea);

void DeleteImage(wr::ImageKey aKey);

Expand Down
5 changes: 5 additions & 0 deletions gfx/webrender_bindings/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,11 +1602,13 @@ pub extern "C" fn wr_resource_updates_add_blob_image(
image_key: BlobImageKey,
descriptor: &WrImageDescriptor,
bytes: &mut WrVecU8,
visible_rect: DeviceIntRect,
) {
txn.add_blob_image(
image_key,
descriptor.into(),
Arc::new(bytes.flush_into_vec()),
visible_rect,
if descriptor.format == ImageFormat::BGRA8 { Some(256) } else { None }
);
}
Expand Down Expand Up @@ -1711,12 +1713,14 @@ pub extern "C" fn wr_resource_updates_update_blob_image(
image_key: BlobImageKey,
descriptor: &WrImageDescriptor,
bytes: &mut WrVecU8,
visible_rect: DeviceIntRect,
dirty_rect: LayoutIntRect,
) {
txn.update_blob_image(
image_key,
descriptor.into(),
Arc::new(bytes.flush_into_vec()),
visible_rect,
&DirtyRect::Partial(dirty_rect)
);
}
Expand Down Expand Up @@ -3160,6 +3164,7 @@ extern "C" {
width: i32,
height: i32,
format: ImageFormat,
visible_rect: &DeviceIntRect,
tile_size: Option<&u16>,
tile_offset: Option<&TileOffset>,
dirty_rect: Option<&LayoutIntRect>,
Expand Down
17 changes: 13 additions & 4 deletions gfx/webrender_bindings/src/moz2d_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! registering fonts found in the blob (see `prepare_request`).
use webrender::api::*;
use webrender::api::units::{BlobDirtyRect, BlobToDeviceTranslation};
use webrender::api::units::{BlobDirtyRect, BlobToDeviceTranslation, DeviceIntRect};
use bindings::{ByteSlice, MutByteSlice, wr_moz2d_render_cb, ArcVecU8, gecko_profiler_start_marker, gecko_profiler_end_marker};
use rayon::ThreadPool;
use rayon::prelude::*;
Expand Down Expand Up @@ -445,6 +445,9 @@ struct BlobFont {
struct BlobCommand {
/// The blob.
data: Arc<BlobImageData>,
/// What part of the blob should be rasterized (visible_rect's top-left corresponds to
/// (0,0) in the blob's rasterization)
visible_rect: DeviceIntRect,
/// The size of the tiles to use in rasterization, if tiling should be used.
tile_size: Option<TileSize>,
}
Expand All @@ -454,6 +457,7 @@ struct BlobCommand {
descriptor: BlobImageDescriptor,
commands: Arc<BlobImageData>,
dirty_rect: BlobDirtyRect,
visible_rect: DeviceIntRect,
tile_size: Option<TileSize>,
}

Expand Down Expand Up @@ -492,10 +496,12 @@ impl AsyncBlobImageRasterizer for Moz2dBlobRasterizer {
let command = &self.blob_commands[&params.request.key];
let blob = Arc::clone(&command.data);
assert!(params.descriptor.rect.size.width > 0 && params.descriptor.rect.size.height > 0);

Job {
request: params.request,
descriptor: params.descriptor,
commands: blob,
visible_rect: command.visible_rect,
dirty_rect: params.dirty_rect,
tile_size: command.tile_size,
}
Expand Down Expand Up @@ -545,6 +551,7 @@ fn rasterize_blob(job: Job) -> (BlobImageRequest, BlobImageResult) {
descriptor.rect.size.width,
descriptor.rect.size.height,
descriptor.format,
&job.visible_rect,
job.tile_size.as_ref(),
job.request.tile.as_ref(),
dirty_rect.as_ref(),
Expand All @@ -569,15 +576,15 @@ fn rasterize_blob(job: Job) -> (BlobImageRequest, BlobImageResult) {
}

impl BlobImageHandler for Moz2dBlobImageHandler {
fn add(&mut self, key: BlobImageKey, data: Arc<BlobImageData>, tile_size: Option<TileSize>) {
fn add(&mut self, key: BlobImageKey, data: Arc<BlobImageData>, visible_rect: &DeviceIntRect, tile_size: Option<TileSize>) {
{
let index = BlobReader::new(&data);
assert!(index.reader.has_more());
}
self.blob_commands.insert(key, BlobCommand { data: Arc::clone(&data), tile_size });
self.blob_commands.insert(key, BlobCommand { data: Arc::clone(&data), visible_rect: *visible_rect, tile_size });
}

fn update(&mut self, key: BlobImageKey, data: Arc<BlobImageData>, dirty_rect: &BlobDirtyRect) {
fn update(&mut self, key: BlobImageKey, data: Arc<BlobImageData>, visible_rect: &DeviceIntRect, dirty_rect: &BlobDirtyRect) {
match self.blob_commands.entry(key) {
hash_map::Entry::Occupied(mut e) => {
let command = e.get_mut();
Expand All @@ -597,6 +604,8 @@ impl BlobImageHandler for Moz2dBlobImageHandler {
}
};
command.data = Arc::new(merge_blob_images(&command.data, &data, dirty_rect));
assert_eq!(command.visible_rect, *visible_rect);
command.visible_rect = *visible_rect;
}
_ => { panic!("missing image key"); }
}
Expand Down
Loading

0 comments on commit 22e87aa

Please sign in to comment.